Preparing to add and commit dists to svn

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

Branch: refs/heads/master
Commit: d1d0cb407eea63d73a22c21b5add9eee34602539
Parents: d365f0b
Author: Rob Tompkins <chtom...@apache.org>
Authored: Tue Jan 2 15:12:15 2018 -0500
Committer: Rob Tompkins <chtom...@apache.org>
Committed: Tue Jan 2 15:12:15 2018 -0500

----------------------------------------------------------------------
 .../commons/release/plugin/SharedFunctions.java | 29 ++++++++
 .../CommonsDistributionDetatchmentMojo.java     | 17 +----
 .../mojos/CommonsDistributionStagingMojo.java   | 77 +++++++++++++++++++-
 3 files changed, 103 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/d1d0cb40/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 60f2db9..9051629 100644
--- a/src/main/java/org/apache/commons/release/plugin/SharedFunctions.java
+++ b/src/main/java/org/apache/commons/release/plugin/SharedFunctions.java
@@ -21,6 +21,8 @@ import org.apache.maven.plugin.logging.Log;
 import org.codehaus.plexus.util.FileUtils;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 
 /**
@@ -55,4 +57,31 @@ public class SharedFunctions {
             workingDirectory.mkdirs();
         }
     }
+
+    /**
+     * Copies a file from the from file to the to file and logs the failure 
using the maven logger.
+     *
+     * @param log the {@link Log}, the maven logger.
+     * @param fromFile the {@link File} from which to copy.
+     * @param toFile the {@link File} to which to copy into.
+     * @throws MojoExecutionException if an {@link IOException} occurs.
+     */
+    public static void copyFile(Log log, File fromFile,  File toFile) throws 
MojoExecutionException{
+        FileInputStream in;
+        FileOutputStream out;
+        try {
+            in = new FileInputStream(fromFile);
+            out = new FileOutputStream(toFile);
+            byte[] buf = new byte[1024];
+            int len;
+            while ((len = in.read(buf)) > 0) {
+                out.write(buf, 0, len);
+            }
+            in.close();
+            out.close();
+        } catch (IOException e) {
+            log.error(e.getMessage());
+            throw new MojoExecutionException("Unable to copy file: " + 
e.getMessage(), e);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/d1d0cb40/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetatchmentMojo.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetatchmentMojo.java
 
b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetatchmentMojo.java
index c8ed139..5cf361a 100644
--- 
a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetatchmentMojo.java
+++ 
b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetatchmentMojo.java
@@ -108,22 +108,7 @@ public class CommonsDistributionDetatchmentMojo extends 
AbstractMojo {
             copiedArtifactAbsolutePath.append(artifactFile.getName());
             File copiedArtifact = new 
File(copiedArtifactAbsolutePath.toString());
             getLog().info("Copying: " + artifactFile.getName());
-            FileInputStream in;
-            FileOutputStream out;
-            try {
-                in = new FileInputStream(artifactFile);
-                out = new FileOutputStream(copiedArtifact);
-                byte[] buf = new byte[1024];
-                int len;
-                while ((len = in.read(buf)) > 0) {
-                    out.write(buf, 0, len);
-                }
-                in.close();
-                out.close();
-            } catch (IOException e) {
-                getLog().error(e.getMessage());
-                throw new MojoExecutionException("Unable to copy file: " + 
e.getMessage(), e);
-            }
+            SharedFunctions.copyFile(getLog(), artifactFile, copiedArtifact);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/d1d0cb40/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 6fa1a52..68d37ab 100644
--- 
a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionStagingMojo.java
+++ 
b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionStagingMojo.java
@@ -23,6 +23,7 @@ import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.project.artifact.AttachedArtifact;
 import org.apache.maven.scm.ScmException;
 import org.apache.maven.scm.ScmFileSet;
 import org.apache.maven.scm.manager.BasicScmManager;
@@ -36,23 +37,44 @@ import 
org.apache.maven.scm.repository.ScmRepositoryException;
 import org.apache.maven.settings.Settings;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
 
-@Mojo( name = "stage-distributions", defaultPhase = LifecyclePhase.DEPLOY, 
threadSafe = true)
+/**
+ * This class checks out the dev distribution location, copies the 
distributions into that directory
+ * structure under the <code>target</code> directory. Then commits the 
distributions back up to SVN.
+ * Also, we include the built and zipped site as well as the RELEASE-NOTES.txt.
+ *
+ * @author chtompki
+ * @since 1.0
+ */
+@Mojo(name = "stage-distributions", defaultPhase = LifecyclePhase.DEPLOY, 
threadSafe = true)
 public class CommonsDistributionStagingMojo extends AbstractMojo {
 
     /**
      */
-    @Parameter( defaultValue = 
"${project.build.directory}/commons-release-plugin", alias = "outputDirectory" )
+    @Parameter(defaultValue = "${basedir}")
+    private File basedir;
+
+    /**
+     */
+    @Parameter(defaultValue = 
"${project.build.directory}/commons-release-plugin", alias = "outputDirectory")
     private File workingDirectory;
 
     /**
      */
-    @Parameter( defaultValue = 
"${project.build.directory}/commons-release-plugin/scm", alias = 
"outputDirectory" )
+    @Parameter(defaultValue = 
"${project.build.directory}/commons-release-plugin/scm", alias = 
"outputDirectory")
     private File distCheckoutDirectory;
 
+    @Parameter(defaultValue = "false")
+    private Boolean dryRun;
+
     /**
      */
-    @Parameter ( required = true )
+    @Parameter(required = true)
     private String distSvnStagingUrl;
 
     @Override
@@ -72,9 +94,56 @@ public class CommonsDistributionStagingMojo extends 
AbstractMojo {
             ScmFileSet scmFileSet = new ScmFileSet(distCheckoutDirectory);
             getLog().info("Checking out dist from: " + distSvnStagingUrl);
             provider.checkOut(repository, scmFileSet);
+            copyReleaseNotesToWorkingDirectory();
+            copyDistributionsIntoScmDirectoryStructure();
         } catch (ScmException e) {
             getLog().error("Could not commit files to dist: " + 
distSvnStagingUrl, e);
             throw new MojoExecutionException("Could not commit files to dist: 
" + distSvnStagingUrl, e);
         }
     }
+
+    private void copyReleaseNotesToWorkingDirectory() throws 
MojoExecutionException {
+        StringBuffer copiedReleaseNotesAbsolutePath;
+        getLog().info("Copying RELEASE-NOTES.txt to working directory.");
+        File releaseNotes = new File(basedir + "/RELEASE-NOTES.txt");
+        copiedReleaseNotesAbsolutePath = new 
StringBuffer(workingDirectory.getAbsolutePath());
+        copiedReleaseNotesAbsolutePath.append("/scm/");
+        copiedReleaseNotesAbsolutePath.append(releaseNotes.getName());
+        File copiedReleaseNotes = new 
File(copiedReleaseNotesAbsolutePath.toString());
+        getLog().info("Copying: " + releaseNotes.getName());
+        SharedFunctions.copyFile(getLog(), releaseNotes, copiedReleaseNotes);
+    }
+
+    private void copyDistributionsIntoScmDirectoryStructure() throws 
MojoExecutionException {
+        List<File> workingDirectoryFiles = 
Arrays.asList(workingDirectory.listFiles());
+        String scmBinariesRoot = buildDistBinariesRoot();
+        String scmSourceRoot = buildDistSourceRoot();
+        File copy;
+        for (File file : workingDirectoryFiles) {
+            if (file.getName().contains("src")) {
+                copy = new File(scmSourceRoot + "/" + file.getName());
+                SharedFunctions.copyFile(getLog(), file, copy);
+            } else if (file.getName().contains("bin")) {
+                copy = new File(scmBinariesRoot + "/" + file.getName());
+                SharedFunctions.copyFile(getLog(), file, copy);
+            } else if (file.getName().contains("scm")){
+                //do nothing because we are copying into scm
+            } else {
+                copy = new File(distCheckoutDirectory.getAbsolutePath() + "/" 
+ file.getName());
+                SharedFunctions.copyFile(getLog(), file, copy);
+            }
+        }
+    }
+
+    private String buildDistBinariesRoot() {
+        StringBuffer buffer = new 
StringBuffer(distCheckoutDirectory.getAbsolutePath());
+        buffer.append("/binaries");
+        return buffer.toString();
+    }
+
+    private String buildDistSourceRoot() {
+        StringBuffer buffer = new 
StringBuffer(distCheckoutDirectory.getAbsolutePath());
+        buffer.append("/source");
+        return buffer.toString();
+    }
 }

Reply via email to