diff --git a/pom.xml b/pom.xml index ee7c2672..b976e655 100644 --- a/pom.xml +++ b/pom.xml @@ -60,8 +60,7 @@ -SNAPSHOT 2.121.2 8 - 2.14 - UTF-8 + 2.16 @@ -94,7 +93,7 @@ org.jenkins-ci.plugins.workflow workflow-api - 2.30 + 2.31 diff --git a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/zip/UnZipStepExecution.java b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/zip/UnZipStepExecution.java index 1b318e4c..0db1a6bb 100644 --- a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/zip/UnZipStepExecution.java +++ b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/zip/UnZipStepExecution.java @@ -31,13 +31,10 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.apache.tools.ant.types.selectors.SelectorUtils; -import org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution; import org.jenkinsci.plugins.workflow.steps.StepContext; -import org.jenkinsci.plugins.workflow.steps.StepContextParameter; import org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution; import javax.annotation.Nonnull; -import javax.inject.Inject; import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -132,13 +129,10 @@ public Map invoke(File zipFile, VirtualChannel channel) throws I destination.mkdirs(); } PrintStream logger = listener.getLogger(); - ZipFile zip = null; boolean doGlob = !StringUtils.isBlank(glob); Map strMap = new TreeMap(); - try { + try (ZipFile zip = new ZipFile(zipFile, Charset.forName(charset))) { logger.println("Extracting from " + zipFile.getAbsolutePath()); - Charset charsetForZip = Charset.forName(charset); - zip = new ZipFile(zipFile, charsetForZip); Enumeration entries = zip.entries(); Integer fileCount = 0; while (entries.hasMoreElements()) { @@ -196,7 +190,7 @@ public Map invoke(File zipFile, VirtualChannel channel) throws I return null; } } finally { - IOUtils.closeQuietly(zip); + logger.flush(); } } @@ -220,9 +214,7 @@ public TestZipFileCallable(TaskListener listener) { @Override public Boolean invoke(File f, VirtualChannel channel) throws IOException, InterruptedException { PrintStream logger = listener.getLogger(); - ZipFile zip = null; - try { - zip = new ZipFile(f); + try (ZipFile zip = new ZipFile(f)) { logger.print("Checking "); logger.print(zip.size()); logger.print(" zipped entries in "); @@ -254,8 +246,7 @@ public Boolean invoke(File f, VirtualChannel channel) throws IOException, Interr listener.error("Error validating zip file: " + e.getMessage()); return false; } finally { - //according to docs this should also close all open streams. - IOUtils.closeQuietly(zip); + logger.flush(); } } }