You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2018/05/29 21:49:51 UTC

commons-release-plugin git commit: Fix possible resource leak and/or file locking errors: The file output streams for the readme file and header file were not being closed.

Repository: commons-release-plugin
Updated Branches:
  refs/heads/master 0c29ac3a1 -> c6d7168bd


Fix possible resource leak and/or file locking errors: The file output
streams for the readme file and header file were not being closed.

Project: http://git-wip-us.apache.org/repos/asf/commons-release-plugin/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-release-plugin/commit/c6d7168b
Tree: http://git-wip-us.apache.org/repos/asf/commons-release-plugin/tree/c6d7168b
Diff: http://git-wip-us.apache.org/repos/asf/commons-release-plugin/diff/c6d7168b

Branch: refs/heads/master
Commit: c6d7168bd8d3d3232ffecf8bb064572dccd5657d
Parents: 0c29ac3
Author: Gary Gregory <ga...@gmail.com>
Authored: Tue May 29 15:49:48 2018 -0600
Committer: Gary Gregory <ga...@gmail.com>
Committed: Tue May 29 15:49:48 2018 -0600

----------------------------------------------------------------------
 .../commons/release/plugin/SharedFunctions.java |  2 +-
 .../mojos/CommonsDistributionStagingMojo.java   | 51 +++++++++++---------
 2 files changed, 29 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/c6d7168b/src/main/java/org/apache/commons/release/plugin/SharedFunctions.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/release/plugin/SharedFunctions.java b/src/main/java/org/apache/commons/release/plugin/SharedFunctions.java
index 71898b0..bb1954c 100755
--- a/src/main/java/org/apache/commons/release/plugin/SharedFunctions.java
+++ b/src/main/java/org/apache/commons/release/plugin/SharedFunctions.java
@@ -50,7 +50,7 @@ public final class SharedFunctions {
      *
      * @param log is the Maven log for output logging, particularly in regards to error management.
      * @param workingDirectory is a {@link File} that represents the directory to first attempt to delete then create.
-     * @throws MojoExecutionException when an {@link IOException} or {@link NullPointerException} is caught for the 
+     * @throws MojoExecutionException when an {@link IOException} or {@link NullPointerException} is caught for the
      *      purpose of bubbling the exception up to Maven properly.
      */
     public static void initDirectory(Log log, File workingDirectory) throws MojoExecutionException {

http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/c6d7168b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionStagingMojo.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionStagingMojo.java b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionStagingMojo.java
index dc80ae7..2420938 100755
--- a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionStagingMojo.java
+++ b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionStagingMojo.java
@@ -298,32 +298,37 @@ public class CommonsDistributionStagingMojo extends AbstractMojo {
     private List<File> buildReadmeAndHeaderHtmlFiles() throws MojoExecutionException {
         List<File> headerAndReadmeFiles = new ArrayList<>();
         File headerFile = new File(distCheckoutDirectory, "HEADER.html");
+        //
+        // HEADER file
+        //
+        try (Writer headerWriter = new OutputStreamWriter(new FileOutputStream(headerFile), "UTF-8")) {
+            HeaderHtmlVelocityDelegate.builder().build().render(headerWriter);
+        } catch (IOException e) {
+            final String message = "Could not build HEADER html file " + headerFile;
+            getLog().error(message, e);
+            throw new MojoExecutionException(message, e);
+        }
+        headerAndReadmeFiles.add(headerFile);
+        //
+        // README file
+        //
         File readmeFile = new File(distCheckoutDirectory, "README.html");
-        try {
-            FileOutputStream headerStream = new FileOutputStream(headerFile);
-            Writer headerWriter = new OutputStreamWriter(headerStream, "UTF-8");
-            FileOutputStream readmeStream = new FileOutputStream(readmeFile);
-            Writer readmeWriter = new OutputStreamWriter(readmeStream, "UTF-8");
-            HeaderHtmlVelocityDelegate headerHtmlVelocityDelegate = HeaderHtmlVelocityDelegate
-                .builder()
-                .build();
-            headerWriter = headerHtmlVelocityDelegate.render(headerWriter);
-            headerWriter.close();
-            headerAndReadmeFiles.add(headerFile);
-            ReadmeHtmlVelocityDelegate readmeHtmlVelocityDelegate = ReadmeHtmlVelocityDelegate
-                .builder()
-                .withArtifactId(project.getArtifactId())
-                .withVersion(project.getVersion())
-                .withSiteUrl(project.getUrl())
-                .build();
-            readmeWriter = readmeHtmlVelocityDelegate.render(readmeWriter);
-            readmeWriter.close();
-            headerAndReadmeFiles.add(readmeFile);
-            headerAndReadmeFiles.addAll(copyHeaderAndReadmeToSubdirectories(headerFile, readmeFile));
+        try (Writer readmeWriter = new OutputStreamWriter(new FileOutputStream(readmeFile), "UTF-8")) {
+            // @formatter:off
+            ReadmeHtmlVelocityDelegate readmeHtmlVelocityDelegate = ReadmeHtmlVelocityDelegate.builder()
+                    .withArtifactId(project.getArtifactId())
+                    .withVersion(project.getVersion())
+                    .withSiteUrl(project.getUrl())
+                    .build();
+            // @formatter:on
+            readmeHtmlVelocityDelegate.render(readmeWriter);
         } catch (IOException e) {
-            getLog().error("Could not build HEADER and README html files", e);
-            throw new MojoExecutionException("Could not build HEADER and README html files", e);
+            final String message = "Could not build README html file " + readmeFile;
+            getLog().error(message, e);
+            throw new MojoExecutionException(message, e);
         }
+        headerAndReadmeFiles.add(readmeFile);
+        headerAndReadmeFiles.addAll(copyHeaderAndReadmeToSubdirectories(headerFile, readmeFile));
         return headerAndReadmeFiles;
     }