diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-active-collection/src/main/java/org/apache/maven/plugin/coreit/CheckMojo.java b/its/core-it-support/core-it-plugins/maven-it-plugin-active-collection/src/main/java/org/apache/maven/plugin/coreit/CheckMojo.java index aa0e9325d7d2..c8a295d611f0 100644 --- a/its/core-it-support/core-it-plugins/maven-it-plugin-active-collection/src/main/java/org/apache/maven/plugin/coreit/CheckMojo.java +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-active-collection/src/main/java/org/apache/maven/plugin/coreit/CheckMojo.java @@ -117,21 +117,11 @@ public void execute() throws MojoExecutionException, MojoFailureException { getLog().info("[MAVEN-CORE-IT-LOG] Creating output file " + outputFile); - OutputStream out = null; - try { - outputFile.getParentFile().mkdirs(); - out = new FileOutputStream(outputFile); + outputFile.getParentFile().mkdirs(); + try (OutputStream out = new FileOutputStream(outputFile)) { componentProperties.store(out, "MAVEN-CORE-IT-LOG"); } catch (IOException e) { - throw new MojoExecutionException("Output file could not be created: " + outputFile, e); - } finally { - if (out != null) { - try { - out.close(); - } catch (IOException e) { - // just ignore - } - } + throw new MojoExecutionException(e); } getLog().info("[MAVEN-CORE-IT-LOG] Created output file " + outputFile); diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-active-collection/src/main/java/org/apache/maven/plugin/coreit/CheckThreadSafetyMojo.java b/its/core-it-support/core-it-plugins/maven-it-plugin-active-collection/src/main/java/org/apache/maven/plugin/coreit/CheckThreadSafetyMojo.java index ffe72d0ff0a7..3119dbae0f03 100644 --- a/its/core-it-support/core-it-plugins/maven-it-plugin-active-collection/src/main/java/org/apache/maven/plugin/coreit/CheckThreadSafetyMojo.java +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-active-collection/src/main/java/org/apache/maven/plugin/coreit/CheckThreadSafetyMojo.java @@ -134,21 +134,11 @@ public void run() { getLog().info("[MAVEN-CORE-IT-LOG] Creating output file " + outputFile); - OutputStream out = null; - try { - outputFile.getParentFile().mkdirs(); - out = new FileOutputStream(outputFile); + outputFile.getParentFile().mkdirs(); + try (OutputStream out = new FileOutputStream(outputFile)) { componentProperties.store(out, "MAVEN-CORE-IT-LOG"); } catch (IOException e) { - throw new MojoExecutionException("Output file could not be created: " + outputFile, e); - } finally { - if (out != null) { - try { - out.close(); - } catch (IOException e) { - // just ignore - } - } + throw new MojoExecutionException(e); } getLog().info("[MAVEN-CORE-IT-LOG] Created output file " + outputFile); diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-class-loader/maven-it-plugin-class-loader/src/main/java/org/apache/maven/plugin/coreit/PropertiesUtil.java b/its/core-it-support/core-it-plugins/maven-it-plugin-class-loader/maven-it-plugin-class-loader/src/main/java/org/apache/maven/plugin/coreit/PropertiesUtil.java index a4c04791352b..bb7a839aadfd 100644 --- a/its/core-it-support/core-it-plugins/maven-it-plugin-class-loader/maven-it-plugin-class-loader/src/main/java/org/apache/maven/plugin/coreit/PropertiesUtil.java +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-class-loader/maven-it-plugin-class-loader/src/main/java/org/apache/maven/plugin/coreit/PropertiesUtil.java @@ -19,9 +19,9 @@ package org.apache.maven.plugin.coreit; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.nio.file.Files; import java.util.Properties; import org.apache.maven.plugin.MojoExecutionException; @@ -35,21 +35,11 @@ class PropertiesUtil { public static void write(File outputFile, Properties props) throws MojoExecutionException { - OutputStream out = null; - try { - outputFile.getParentFile().mkdirs(); - out = new FileOutputStream(outputFile); + outputFile.getParentFile().mkdirs(); + try (OutputStream out = Files.newOutputStream(outputFile.toPath())) { props.store(out, "MAVEN-CORE-IT-LOG"); } catch (IOException e) { - throw new MojoExecutionException("Output file could not be created: " + outputFile, e); - } finally { - if (out != null) { - try { - out.close(); - } catch (IOException e) { - // just ignore - } - } + throw new MojoExecutionException(e); } } } diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/PropertiesUtil.java b/its/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/PropertiesUtil.java index 9d0a9a4414f5..9bb077502362 100644 --- a/its/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/PropertiesUtil.java +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/PropertiesUtil.java @@ -69,22 +69,11 @@ public static Properties read(File inputFile) throws MojoExecutionException { } public static void write(File outputFile, Properties props) throws MojoExecutionException { - OutputStream os = null; - try { - outputFile.getParentFile().mkdirs(); - os = new FileOutputStream(outputFile); + outputFile.getParentFile().mkdirs(); + try (OutputStream os = new FileOutputStream(outputFile)) { props.store(os, "MAVEN-CORE-IT-LOG"); } catch (IOException e) { - throw new MojoExecutionException( - "Output file " + outputFile + " could not be created: " + e.getMessage(), e); - } finally { - if (os != null) { - try { - os.close(); - } catch (IOException e) { - // just ignore - } - } + throw new MojoExecutionException(e); } } diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-site/src/main/java/org/apache/maven/plugin/coreit/InfoReport.java b/its/core-it-support/core-it-plugins/maven-it-plugin-site/src/main/java/org/apache/maven/plugin/coreit/InfoReport.java index 76912a72ce76..76368197f9eb 100644 --- a/its/core-it-support/core-it-plugins/maven-it-plugin-site/src/main/java/org/apache/maven/plugin/coreit/InfoReport.java +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-site/src/main/java/org/apache/maven/plugin/coreit/InfoReport.java @@ -96,21 +96,11 @@ public void execute() throws MojoExecutionException, MojoFailureException { getLog().info("[MAVEN-CORE-IT-LOG] Creating output file: " + outputFile); - OutputStream out = null; - try { - outputFile.getParentFile().mkdirs(); - out = new FileOutputStream(outputFile); + outputFile.getParentFile().mkdirs(); + try (OutputStream out = new FileOutputStream(outputFile)) { props.store(out, "MAVEN-CORE-IT-LOG"); } catch (IOException e) { - throw new MojoExecutionException("Output file could not be created: " + outputFile, e); - } finally { - if (out != null) { - try { - out.close(); - } catch (IOException e) { - // just ignore - } - } + throw new MojoExecutionException(e); } getLog().info("[MAVEN-CORE-IT-LOG] Created output file: " + outputFile); diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-toolchain/src/main/java/org/apache/maven/plugin/coreit/CoreItMojo.java b/its/core-it-support/core-it-plugins/maven-it-plugin-toolchain/src/main/java/org/apache/maven/plugin/coreit/CoreItMojo.java index e04db7350829..328fcd5c06ec 100644 --- a/its/core-it-support/core-it-plugins/maven-it-plugin-toolchain/src/main/java/org/apache/maven/plugin/coreit/CoreItMojo.java +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-toolchain/src/main/java/org/apache/maven/plugin/coreit/CoreItMojo.java @@ -105,21 +105,11 @@ public void execute() throws MojoExecutionException { } } - OutputStream out = null; - try { - outputFile.getParentFile().mkdirs(); - out = new FileOutputStream(outputFile); + outputFile.getParentFile().mkdirs(); + try (OutputStream out = new FileOutputStream(outputFile)) { properties.store(out, "MAVEN-CORE-IT-LOG"); } catch (IOException e) { - throw new MojoExecutionException(e.getMessage(), e); - } finally { - if (out != null) { - try { - out.close(); - } catch (IOException e) { - // ignore - } - } + throw new MojoExecutionException(e); } } diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-toolchain/src/main/java/org/apache/maven/plugin/coreit/FindToolMojo.java b/its/core-it-support/core-it-plugins/maven-it-plugin-toolchain/src/main/java/org/apache/maven/plugin/coreit/FindToolMojo.java index 11884b1a6b4e..eabfbbf47880 100644 --- a/its/core-it-support/core-it-plugins/maven-it-plugin-toolchain/src/main/java/org/apache/maven/plugin/coreit/FindToolMojo.java +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-toolchain/src/main/java/org/apache/maven/plugin/coreit/FindToolMojo.java @@ -87,21 +87,11 @@ public void execute() throws MojoExecutionException { } } - OutputStream out = null; - try { - outputFile.getParentFile().mkdirs(); - out = new FileOutputStream(outputFile); + outputFile.getParentFile().mkdirs(); + try (OutputStream out = new FileOutputStream(outputFile)) { properties.store(out, "MAVEN-CORE-IT-LOG"); } catch (IOException e) { - throw new MojoExecutionException(e.getMessage(), e); - } finally { - if (out != null) { - try { - out.close(); - } catch (IOException e) { - // ignore - } - } + throw new MojoExecutionException(e); } } }