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/18 17:02:08 UTC

[1/2] commons-release-plugin git commit: Add SHA-256.

Repository: commons-release-plugin
Updated Branches:
  refs/heads/master bef9b22e1 -> 2c2402c3a


Add SHA-256.

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/9ce2be1f
Tree: http://git-wip-us.apache.org/repos/asf/commons-release-plugin/tree/9ce2be1f
Diff: http://git-wip-us.apache.org/repos/asf/commons-release-plugin/diff/9ce2be1f

Branch: refs/heads/master
Commit: 9ce2be1fc28de3708fc84858dd51d56e022e1c30
Parents: 0c9d294
Author: Gary Gregory <ga...@gmail.com>
Authored: Fri May 18 10:49:37 2018 -0600
Committer: Gary Gregory <ga...@gmail.com>
Committed: Fri May 18 10:49:37 2018 -0600

----------------------------------------------------------------------
 .../CommonsDistributionDetachmentMojo.java      | 139 ++++++++++++++++---
 1 file changed, 116 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/9ce2be1f/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetachmentMojo.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetachmentMojo.java b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetachmentMojo.java
index c6d8fef..a3aee29 100644
--- a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetachmentMojo.java
+++ b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetachmentMojo.java
@@ -17,6 +17,7 @@
 package org.apache.commons.release.plugin.mojos;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.PrintWriter;
@@ -27,6 +28,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Properties;
 import java.util.Set;
+
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.release.plugin.SharedFunctions;
@@ -83,6 +85,13 @@ public class CommonsDistributionDetachmentMojo extends AbstractMojo {
     private Properties artifactSha1s = new Properties();
 
     /**
+     * A {@link Properties} of {@link Artifact} → {@link String} containing the sha256 signatures
+     * for the individual artifacts, where the {@link Artifact} is represented as:
+     * <code>groupId:artifactId:version:type=sha1</code>.
+     */
+    private Properties artifactSha256s = new Properties();
+
+    /**
      * The maven project context injection so that we can get a hold of the variables at hand.
      */
     @Parameter(defaultValue = "${project}", required = true)
@@ -121,6 +130,7 @@ public class CommonsDistributionDetachmentMojo extends AbstractMojo {
         getLog().info("Detaching Assemblies");
         for (Object attachedArtifact : project.getAttachedArtifacts()) {
             putAttachedArtifactInSha1Map((Artifact) attachedArtifact);
+            putAttachedArtifactInSha256Map((Artifact) attachedArtifact);
             if (ARTIFACT_TYPES_TO_DETACH.contains(((Artifact) attachedArtifact).getType())) {
                 detachedArtifacts.add((Artifact) attachedArtifact);
             }
@@ -135,10 +145,11 @@ public class CommonsDistributionDetachmentMojo extends AbstractMojo {
         if (!workingDirectory.exists()) {
             SharedFunctions.initDirectory(getLog(), workingDirectory);
         }
-        logAllArtifactsInPropertiesFile();
+        logAllArtifactsInSha1PropertiesFile();
+        logAllArtifactsInSha256PropertiesFile();
         copyRemovedArtifactsToWorkingDirectory();
         getLog().info("");
-        sha1AndMd5SignArtifacts();
+        hashArtifacts();
     }
 
     /**
@@ -154,10 +165,37 @@ public class CommonsDistributionDetachmentMojo extends AbstractMojo {
                 .append(artifact.getArtifactId()).append('-')
                 .append(artifact.getVersion()).append('-')
                 .append(artifact.getType());
-            artifactSha1s.put(
-                artifactKey.toString(),
-                DigestUtils.sha1Hex(Files.readAllBytes(artifact.getFile().toPath()))
-            );
+            try (FileInputStream fis = new FileInputStream(artifact.getFile())) {
+                artifactSha1s.put(artifactKey.toString(), DigestUtils.sha1Hex(fis));
+            }
+        } catch (IOException e) {
+            throw new MojoExecutionException(
+                "Could not find artifact signature for: "
+                    + artifact.getArtifactId()
+                    + "-"
+                    + artifact.getVersion()
+                    + " type: "
+                    + artifact.getType()
+                ,e);
+        }
+    }
+
+    /**
+     * Takes an attached artifact and puts the signature in the map.
+     * @param artifact is a maven {@link Artifact} taken from the project at start time of mojo.
+     * @throws MojoExecutionException if an {@link IOException} occurs when getting the sha1 of the
+     *                                artifact.
+     */
+    private void putAttachedArtifactInSha256Map(Artifact artifact) throws MojoExecutionException {
+        try {
+            StringBuffer artifactKey = new StringBuffer();
+            artifactKey
+                .append(artifact.getArtifactId()).append('-')
+                .append(artifact.getVersion()).append('-')
+                .append(artifact.getType());
+            try (FileInputStream fis = new FileInputStream(artifact.getFile())) {
+                artifactSha256s.put(artifactKey.toString(), DigestUtils.sha256Hex(fis));
+            }
         } catch (IOException e) {
             throw new MojoExecutionException(
                 "Could not find artifact signature for: "
@@ -175,12 +213,26 @@ public class CommonsDistributionDetachmentMojo extends AbstractMojo {
      *
      * @throws MojoExecutionException if we cant write the file due to an {@link IOException}.
      */
-    private void logAllArtifactsInPropertiesFile() throws MojoExecutionException {
-        File sha1PropertiesFile = new File(workingDirectory, "sha1.properties");
-        try (FileOutputStream fileWriter = new FileOutputStream(sha1PropertiesFile)) {
-            artifactSha1s.store(fileWriter, "Release SHA1s");
+    private void logAllArtifactsInSha1PropertiesFile() throws MojoExecutionException {
+        File propertiesFile = new File(workingDirectory, "sha1.properties");
+        try (FileOutputStream fileWriter = new FileOutputStream(propertiesFile)) {
+            artifactSha1s.store(fileWriter, "Release SHA-1s");
+        } catch (IOException e) {
+            throw new MojoExecutionException("Failure to write SHA-1's", e);
+        }
+    }
+
+    /**
+     * Writes to ./target/commons-release-plugin/sha256.properties the artifact sha256's.
+     *
+     * @throws MojoExecutionException if we cant write the file due to an {@link IOException}.
+     */
+    private void logAllArtifactsInSha256PropertiesFile() throws MojoExecutionException {
+        File propertiesFile = new File(workingDirectory, "sha256.properties");
+        try (FileOutputStream fileWriter = new FileOutputStream(propertiesFile)) {
+            artifactSha256s.store(fileWriter, "Release SHA-256s");
         } catch (IOException e) {
-            throw new MojoExecutionException("Failure to write SHA1's", e);
+            throw new MojoExecutionException("Failure to write SHA-256's", e);
         }
     }
 
@@ -206,26 +258,52 @@ public class CommonsDistributionDetachmentMojo extends AbstractMojo {
     }
 
     /**
-     *  A helper method that creates md5 and sha1 signature files for our detached artifacts in the
-     *  <code>target/commons-release-plugin</code> directory for the purpose of being uploade by
+     *  A helper method that creates md5, sha1, and sha256  signature files for our detached artifacts in the
+     *  <code>target/commons-release-plugin</code> directory for the purpose of being uploaded by
      *  the {@link CommonsDistributionStagingMojo}.
      *
      * @throws MojoExecutionException if some form of an {@link IOException} occurs, we want it
-     *                                properly wrapped so that maven can handle it.
+     *                                properly wrapped so that Maven can handle it.
      */
-    private void sha1AndMd5SignArtifacts() throws MojoExecutionException {
+    private void hashArtifacts() throws MojoExecutionException {
         for (Artifact artifact : detachedArtifacts) {
             if (!artifact.getFile().getName().contains("asc")) {
                 try {
-                    String md5 = DigestUtils.md5Hex(Files.readAllBytes(artifact.getFile().toPath()));
-                    getLog().info(artifact.getFile().getName() + " md5: " + md5);
-                    try (PrintWriter md5Writer = new PrintWriter(getMd5FilePath(workingDirectory, artifact.getFile()))){
-                        md5Writer.println(md5);
+                    {
+                        // MD5
+                        final String digest;
+                        try (FileInputStream fis = new FileInputStream(artifact.getFile())) {
+                            digest = DigestUtils.md5Hex(fis);
+                        }
+                        getLog().info(artifact.getFile().getName() + " md5: " + digest);
+                        try (PrintWriter printWriter = new PrintWriter(
+                                getMd5FilePath(workingDirectory, artifact.getFile()))) {
+                            printWriter.println(digest);
+                        }
+                    }
+                    {
+                        // SHA-1
+                        final String digest;
+                        try (FileInputStream fis = new FileInputStream(artifact.getFile())) {
+                            digest = DigestUtils.sha1Hex(fis);
+                        }
+                        getLog().info(artifact.getFile().getName() + " sha1: " + digest);
+                        try (PrintWriter printWriter = new PrintWriter(
+                                getSha1FilePath(workingDirectory, artifact.getFile()))) {
+                            printWriter.println(digest);
+                        }
                     }
-                    String sha1 = DigestUtils.sha1Hex(Files.readAllBytes(artifact.getFile().toPath()));
-                    getLog().info(artifact.getFile().getName() + " sha1: " + sha1);
-                    try (PrintWriter sha1Writer = new PrintWriter(getSha1FilePath(workingDirectory, artifact.getFile()))) {
-                        sha1Writer.println(sha1);
+                    {
+                        // SHA-256
+                        final String digest;
+                        try (FileInputStream fis = new FileInputStream(artifact.getFile())) {
+                            digest = DigestUtils.sha256Hex(fis);
+                        }
+                        getLog().info(artifact.getFile().getName() + " sha256: " + digest);
+                        try (PrintWriter printWriter = new PrintWriter(
+                                getSha256FilePath(workingDirectory, artifact.getFile()))) {
+                            printWriter.println(digest);
+                        }
                     }
                 } catch (IOException e) {
                     throw new MojoExecutionException("Could not sign file: " + artifact.getFile().getName(), e);
@@ -263,4 +341,19 @@ public class CommonsDistributionDetachmentMojo extends AbstractMojo {
         buffer.append(".sha1");
         return buffer.toString();
     }
+
+    /**
+     * A helper method to create a file path for the <code>sha1</code> signature file from a given file.
+     *
+     * @param workingDirectory is the {@link File} for the directory in which to make the <code>.sha1</code> file.
+     * @param file the {@link File} whose name we should use to create the <code>.sha1</code> file.
+     * @return a {@link String} that is the absolute path to the <code>.sha1</code> file.
+     */
+    private String getSha256FilePath(File workingDirectory, File file) {
+        StringBuffer buffer = new StringBuffer(workingDirectory.getAbsolutePath());
+        buffer.append("/");
+        buffer.append(file.getName());
+        buffer.append(".sha256");
+        return buffer.toString();
+    }
 }


[2/2] commons-release-plugin git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/commons-release-plugin.git

Posted by gg...@apache.org.
Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/commons-release-plugin.git

Conflicts:
	src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetachmentMojo.java


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/2c2402c3
Tree: http://git-wip-us.apache.org/repos/asf/commons-release-plugin/tree/2c2402c3
Diff: http://git-wip-us.apache.org/repos/asf/commons-release-plugin/diff/2c2402c3

Branch: refs/heads/master
Commit: 2c2402c3a205e6e5409dcd8611da0c3a6ad1eedb
Parents: 9ce2be1 bef9b22
Author: Gary Gregory <ga...@gmail.com>
Authored: Fri May 18 11:02:02 2018 -0600
Committer: Gary Gregory <ga...@gmail.com>
Committed: Fri May 18 11:02:02 2018 -0600

----------------------------------------------------------------------
 pom.xml                                         | 24 ++++---
 .../CommonsDistributionDetachmentMojo.java      | 69 +++++++++-----------
 .../vote-txt-template.txt                       |  1 +
 src/main/scripts/generate-xdocs.build.xml       |  6 +-
 4 files changed, 52 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/2c2402c3/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetachmentMojo.java
----------------------------------------------------------------------
diff --cc src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetachmentMojo.java
index a3aee29,40fd2fc..376fd78
--- a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetachmentMojo.java
+++ b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetachmentMojo.java
@@@ -21,7 -20,7 +21,6 @@@ import java.io.FileInputStream
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.PrintWriter;
--import java.nio.file.Files;
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.HashSet;
@@@ -165,37 -154,10 +164,37 @@@ public class CommonsDistributionDetachm
                  .append(artifact.getArtifactId()).append('-')
                  .append(artifact.getVersion()).append('-')
                  .append(artifact.getType());
 -            artifactSha1s.put(
 -                artifactKey.toString(),
 -                DigestUtils.sha1Hex(Files.readAllBytes(artifact.getFile().toPath()))
 -            );
 +            try (FileInputStream fis = new FileInputStream(artifact.getFile())) {
 +                artifactSha1s.put(artifactKey.toString(), DigestUtils.sha1Hex(fis));
 +            }
 +        } catch (IOException e) {
 +            throw new MojoExecutionException(
 +                "Could not find artifact signature for: "
 +                    + artifact.getArtifactId()
 +                    + "-"
 +                    + artifact.getVersion()
 +                    + " type: "
-                     + artifact.getType()
-                 ,e);
++                    + artifact.getType(),
++                e);
 +        }
 +    }
 +
 +    /**
 +     * Takes an attached artifact and puts the signature in the map.
 +     * @param artifact is a maven {@link Artifact} taken from the project at start time of mojo.
 +     * @throws MojoExecutionException if an {@link IOException} occurs when getting the sha1 of the
 +     *                                artifact.
 +     */
 +    private void putAttachedArtifactInSha256Map(Artifact artifact) throws MojoExecutionException {
 +        try {
 +            StringBuffer artifactKey = new StringBuffer();
 +            artifactKey
 +                .append(artifact.getArtifactId()).append('-')
 +                .append(artifact.getVersion()).append('-')
 +                .append(artifact.getType());
 +            try (FileInputStream fis = new FileInputStream(artifact.getFile())) {
 +                artifactSha256s.put(artifactKey.toString(), DigestUtils.sha256Hex(fis));
 +            }
          } catch (IOException e) {
              throw new MojoExecutionException(
                  "Could not find artifact signature for: "
@@@ -263,47 -211,23 +262,39 @@@
       *  the {@link CommonsDistributionStagingMojo}.
       *
       * @throws MojoExecutionException if some form of an {@link IOException} occurs, we want it
-      *                                properly wrapped so that Maven can handle it.
+      *                                properly wrapped so that maven can handle it.
       */
 -    private void sha1AndMd5SignArtifacts() throws MojoExecutionException {
 +    private void hashArtifacts() throws MojoExecutionException {
          for (Artifact artifact : detachedArtifacts) {
              if (!artifact.getFile().getName().contains("asc")) {
                  try {
-                     {
-                         // MD5
-                         final String digest;
-                         try (FileInputStream fis = new FileInputStream(artifact.getFile())) {
-                             digest = DigestUtils.md5Hex(fis);
-                         }
-                         getLog().info(artifact.getFile().getName() + " md5: " + digest);
-                         try (PrintWriter printWriter = new PrintWriter(
-                                 getMd5FilePath(workingDirectory, artifact.getFile()))) {
-                             printWriter.println(digest);
-                         }
 -                    String md5 = DigestUtils.md5Hex(Files.readAllBytes(artifact.getFile().toPath()));
 -                    getLog().info(artifact.getFile().getName() + " md5: " + md5);
 -                    try (PrintWriter md5Writer =
 -                        new PrintWriter(getMd5FilePath(workingDirectory, artifact.getFile()))) {
 -                        md5Writer.println(md5);
++                    // MD5
++                    String digest;
++                    try (FileInputStream fis = new FileInputStream(artifact.getFile())) {
++                        digest = DigestUtils.md5Hex(fis);
++                    }
++                    getLog().info(artifact.getFile().getName() + " md5: " + digest);
++                    try (PrintWriter printWriter = new PrintWriter(
++                            getMd5FilePath(workingDirectory, artifact.getFile()))) {
++                        printWriter.println(digest);
++                    }
++                    // SHA-1
++                    try (FileInputStream fis = new FileInputStream(artifact.getFile())) {
++                        digest = DigestUtils.sha1Hex(fis);
++                    }
++                    getLog().info(artifact.getFile().getName() + " sha1: " + digest);
++                    try (PrintWriter printWriter = new PrintWriter(
++                            getSha1FilePath(workingDirectory, artifact.getFile()))) {
++                        printWriter.println(digest);
                      }
-                     {
-                         // SHA-1
-                         final String digest;
-                         try (FileInputStream fis = new FileInputStream(artifact.getFile())) {
-                             digest = DigestUtils.sha1Hex(fis);
-                         }
-                         getLog().info(artifact.getFile().getName() + " sha1: " + digest);
-                         try (PrintWriter printWriter = new PrintWriter(
-                                 getSha1FilePath(workingDirectory, artifact.getFile()))) {
-                             printWriter.println(digest);
-                         }
 -                    String sha1 = DigestUtils.sha1Hex(Files.readAllBytes(artifact.getFile().toPath()));
 -                    getLog().info(artifact.getFile().getName() + " sha1: " + sha1);
 -                    try (PrintWriter sha1Writer =
 -                        new PrintWriter(getSha1FilePath(workingDirectory, artifact.getFile()))) {
 -                        sha1Writer.println(sha1);
++                    // SHA-256
++                    try (FileInputStream fis = new FileInputStream(artifact.getFile())) {
++                        digest = DigestUtils.sha256Hex(fis);
 +                    }
-                     {
-                         // SHA-256
-                         final String digest;
-                         try (FileInputStream fis = new FileInputStream(artifact.getFile())) {
-                             digest = DigestUtils.sha256Hex(fis);
-                         }
-                         getLog().info(artifact.getFile().getName() + " sha256: " + digest);
-                         try (PrintWriter printWriter = new PrintWriter(
-                                 getSha256FilePath(workingDirectory, artifact.getFile()))) {
-                             printWriter.println(digest);
-                         }
++                    getLog().info(artifact.getFile().getName() + " sha256: " + digest);
++                    try (PrintWriter printWriter = new PrintWriter(
++                            getSha256FilePath(workingDirectory, artifact.getFile()))) {
++                        printWriter.println(digest);
                      }
                  } catch (IOException e) {
                      throw new MojoExecutionException("Could not sign file: " + artifact.getFile().getName(), e);

http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/2c2402c3/src/main/resources/commons-xdoc-templates/vote-txt-template.txt
----------------------------------------------------------------------
diff --cc src/main/resources/commons-xdoc-templates/vote-txt-template.txt
index 65c722f,65c722f..668609a
--- a/src/main/resources/commons-xdoc-templates/vote-txt-template.txt
+++ b/src/main/resources/commons-xdoc-templates/vote-txt-template.txt
@@@ -36,6 -36,6 +36,7 @@@ Maven artifacts are here
  These are the Maven artifacts and their hashes in Nexus:
  
  @SHA1LIST@
++@SHA256LIST@
  
  (no need for .asc hashes!)
  

http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/2c2402c3/src/main/scripts/generate-xdocs.build.xml
----------------------------------------------------------------------
diff --cc src/main/scripts/generate-xdocs.build.xml
index be32372,be32372..0745599
--- a/src/main/scripts/generate-xdocs.build.xml
+++ b/src/main/scripts/generate-xdocs.build.xml
@@@ -56,9 -56,9 +56,12 @@@
          <!-- Create a temporary directory to load the template files into -->
          <mkdir dir="${commonsMojoTempDir}"/>
  
--    	<!-- Load SHA1 file created by the deploy goal -->
++    	<!-- Load SHA-1 file created by the deploy goal -->
      	<loadfile property="commons.sha1list" srcFile="target/commons-release-plugin/sha1.properties"/>
      	
++    	<!-- Load SHA-256 file created by the deploy goal -->
++    	<loadfile property="commons.sha256list" srcFile="target/commons-release-plugin/sha256.properties"/>
++    	
          <!-- Load the vote-txt template from mojo resources to temp directory -->
          <loadresource property="vote-txt">
              <javaresource name="${commonsMojoXdocDir}/vote-txt-template.txt"/>
@@@ -105,6 -105,6 +108,7 @@@
               <filter token="RMKEY"          value="${commons.releaseManagerKey}"/>            	
               <filter token="RCREV"          value="${svn.rc.revision}"/>            	
               <filter token="SHA1LIST"       value="${commons.sha1list}"/>            	
++             <filter token="SHA256LIST"     value="${commons.sha256list}"/>            	
               <filter token="DISTURL"        value="${svn.dist.url}"/>            	
               <filter token="TAGNAME"        value="${git.tag.name}"/>            	
               <filter token="TAGCOMMIT"      value="${git.tag.commit}"/>