Skip to content

Commit

Permalink
Upgrade Commons FileUpload from 1.5 to 2.0.0-M2
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed May 13, 2024
1 parent b235aba commit 9454dd8
Show file tree
Hide file tree
Showing 9 changed files with 274 additions and 76 deletions.
44 changes: 38 additions & 6 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ THE SOFTWARE.
<description>The module contains dependencies that are used by a specific Jenkins version</description>

<properties>
<commons-fileupload2.version>2.0.0-M2</commons-fileupload2.version>
<slf4jVersion>2.0.13</slf4jVersion>
<stapler.version>1860.vb_89682cf8d96</stapler.version>
<!-- TODO https://github.com/jenkinsci/stapler/pull/542 -->
<stapler.version>1861.v1e935e64198a_</stapler.version>
<groovy.version>2.4.21</groovy.version>
</properties>

Expand Down Expand Up @@ -119,11 +121,6 @@ THE SOFTWARE.
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand Down Expand Up @@ -189,6 +186,41 @@ THE SOFTWARE.
<artifactId>commons-compress</artifactId>
<version>1.26.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-fileupload2</artifactId>
<version>${commons-fileupload2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-fileupload2-core</artifactId>
<version>${commons-fileupload2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-fileupload2-distribution</artifactId>
<version>${commons-fileupload2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-fileupload2-jakarta-servlet5</artifactId>
<version>${commons-fileupload2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-fileupload2-jakarta-servlet6</artifactId>
<version>${commons-fileupload2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-fileupload2-javax</artifactId>
<version>${commons-fileupload2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-fileupload2-portlet</artifactId>
<version>${commons-fileupload2.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
Expand Down
12 changes: 8 additions & 4 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,6 @@ THE SOFTWARE.
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand Down Expand Up @@ -284,6 +280,14 @@ THE SOFTWARE.
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-fileupload2-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-fileupload2-javax</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
Expand Down
12 changes: 10 additions & 2 deletions core/src/main/java/hudson/FilePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
import jenkins.util.VirtualFile;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload2.core.FileItem;
import org.apache.commons.io.input.CountingInputStream;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
Expand Down Expand Up @@ -1166,7 +1166,7 @@ public void copyFrom(FilePath src) throws IOException, InterruptedException {
public void copyFrom(FileItem file) throws IOException, InterruptedException {
if (channel == null) {
try {
file.write(new File(remote));
file.write(Paths.get(remote));
} catch (IOException e) {
throw e;
} catch (Exception e) {
Expand All @@ -1180,6 +1180,14 @@ public void copyFrom(FileItem file) throws IOException, InterruptedException {
}
}

/**
* @deprecated use {@link #copyFrom(FileItem)}
*/
@Deprecated
public void copyFrom(org.apache.commons.fileupload.FileItem file) throws IOException, InterruptedException {
copyFrom(file.toFileUpload2FileItem());
}

/**
* Code that gets executed on the machine where the {@link FilePath} is local.
* Used to act on {@link FilePath}.
Expand Down
24 changes: 15 additions & 9 deletions core/src/main/java/hudson/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,12 @@
import jenkins.util.xml.RestrictiveEntityResolver;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload2.core.DiskFileItem;
import org.apache.commons.fileupload2.core.DiskFileItemFactory;
import org.apache.commons.fileupload2.core.FileItem;
import org.apache.commons.fileupload2.core.FileUploadException;
import org.apache.commons.fileupload2.javax.JavaxServletDiskFileUpload;
import org.apache.commons.fileupload2.javax.JavaxServletFileUpload;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -1832,13 +1834,17 @@ static class FileUploadPluginCopier implements PluginCopier {
}

@Override
public void copy(File target) throws Exception {
fileItem.write(target);
public void copy(File target) throws IOException {
fileItem.write(Util.fileToPath(target));
}

@Override
public void cleanup() {
fileItem.delete();
try {
fileItem.delete();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}

Expand Down Expand Up @@ -1873,8 +1879,8 @@ public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, Servl
String fileName = "";
PluginCopier copier;
File tmpDir = Files.createTempDirectory("uploadDir").toFile();
ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory(DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD, tmpDir));
List<FileItem> items = upload.parseRequest(req);
JavaxServletFileUpload<DiskFileItem, DiskFileItemFactory> upload = new JavaxServletDiskFileUpload(DiskFileItemFactory.builder().setFile(tmpDir).get());
List<DiskFileItem> items = upload.parseRequest(req);
String string = items.get(1).getString();
if (string != null && !string.isBlank()) {
// this is a URL deployment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import java.util.Objects;
import javax.servlet.ServletException;
import net.sf.json.JSONObject;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload2.core.FileItem;
import org.apache.commons.io.FileUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
Expand Down
Loading

0 comments on commit 9454dd8

Please sign in to comment.