Author: aadamchik
Date: Sun Dec 24 13:33:02 2006
New Revision: 490073

URL: http://svn.apache.org/viewvc?view=rev&rev=490073
Log:
CAY-719:Finalize Maven assembly scripts for the upcoming 3.0 milestone releases
(implemented main artifact file packaging)

Modified:
    
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/AbstractAggregatorMojo.java
    
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/BinAggregatorMojo.java
    
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/JavadocsAggregatorMojo.java
    
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/SourcesAggregatorMojo.java

Modified: 
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/AbstractAggregatorMojo.java
URL: 
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/AbstractAggregatorMojo.java?view=diff&rev=490073&r1=490072&r2=490073
==============================================================================
--- 
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/AbstractAggregatorMojo.java
 (original)
+++ 
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/AbstractAggregatorMojo.java
 Sun Dec 24 13:33:02 2006
@@ -107,7 +107,7 @@
      */
     protected MavenProject project;
 
-    protected abstract File getOutputDirectory();
+    protected abstract File getUnpackDirectory();
     
     /**
      * Preprocesses the list of ArtifactItems. This method defaults the 
outputDirectory if
@@ -125,7 +125,7 @@
             this.getLog().info("Configured Artifact: " + 
artifactItem.toString());
 
             if (artifactItem.getOutputDirectory() == null) {
-                artifactItem.setOutputDirectory(getOutputDirectory());
+                artifactItem.setOutputDirectory(getUnpackDirectory());
             }
             
             artifactItem.getOutputDirectory().mkdirs();

Modified: 
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/BinAggregatorMojo.java
URL: 
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/BinAggregatorMojo.java?view=diff&rev=490073&r1=490072&r2=490073
==============================================================================
--- 
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/BinAggregatorMojo.java
 (original)
+++ 
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/BinAggregatorMojo.java
 Sun Dec 24 13:33:02 2006
@@ -1,10 +1,14 @@
 package org.apache.cayenne.maven.plugin.aggregator;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Iterator;
 
 import org.apache.maven.plugin.MojoExecutionException;
+import org.codehaus.plexus.archiver.Archiver;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
 
 /**
  * A goal to build aggregated jar artifacts from multiple "standard" artifacts.
@@ -14,17 +18,33 @@
  */
 public class BinAggregatorMojo extends AbstractAggregatorMojo {
 
+    static final String[] DEFAULT_EXCLUDES = new String[] {
+        "META-INF/maven/**"
+    };
+
+    static final String[] DEFAULT_INCLUDES = new String[] {
+        "**/**"
+    };
+
     /**
      * Default location used for mojo unless overridden in ArtifactItem
      * 
-     * @parameter expression="${outputDirectory}"
+     * @parameter expression="${unpackDirectory}"
      *            
default-value="${project.build.directory}/aggregate/unpack-bin"
      * @required
      */
-    private File outputDirectory;
+    private File unpackDirectory;
 
-    protected File getOutputDirectory() {
-        return outputDirectory;
+    /**
+     * Name of the generated JAR.
+     * 
+     * @parameter expression="${project.build.finalName}"
+     * @required
+     */
+    private String finalName;
+
+    protected File getUnpackDirectory() {
+        return unpackDirectory;
     }
 
     public void execute() throws MojoExecutionException {
@@ -34,5 +54,39 @@
             ArtifactItem artifactItem = (ArtifactItem) iter.next();
             unpackArtifact(artifactItem);
         }
+
+        packArtifact();
+    }
+
+    private void packArtifact() throws MojoExecutionException {
+        // pack...
+        File outputDirectory = new File(project.getBuild().getDirectory());
+        File destinationFile = new File(outputDirectory, finalName + ".jar");
+
+        Archiver archiver;
+        try {
+            archiver = archiverManager.getArchiver("jar");
+        }
+        catch (NoSuchArchiverException e) {
+            throw new MojoExecutionException("Unknown archiver type", e);
+        }
+
+        try {
+            archiver.setDestFile(destinationFile);
+            archiver.addDirectory(
+                    getUnpackDirectory(),
+                    DEFAULT_INCLUDES,
+                    DEFAULT_EXCLUDES);
+            archiver.createArchive();
+        }
+        catch (ArchiverException e) {
+            throw new MojoExecutionException("Error creating archive", e);
+        }
+        catch (IOException e) {
+            throw new MojoExecutionException("IO Error creating archive", e);
+        }
+
+        // make it a project artifact
+        project.getArtifact().setFile(destinationFile);
     }
-}
+}
\ No newline at end of file

Modified: 
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/JavadocsAggregatorMojo.java
URL: 
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/JavadocsAggregatorMojo.java?view=diff&rev=490073&r1=490072&r2=490073
==============================================================================
--- 
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/JavadocsAggregatorMojo.java
 (original)
+++ 
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/JavadocsAggregatorMojo.java
 Sun Dec 24 13:33:02 2006
@@ -34,14 +34,14 @@
     /**
      * Default location used for mojo unless overridden in ArtifactItem
      * 
-     * @parameter expression="${outputDirectory}"
+     * @parameter expression="${unpackDirectory}"
      *            
default-value="${project.build.directory}/aggregate/unpack-sources"
      * @required
      */
-    private File outputDirectory;
+    private File unpackDirectory;
 
-    protected File getOutputDirectory() {
-        return outputDirectory;
+    protected File getUnpackDirectory() {
+        return unpackDirectory;
     }
 
     public void execute() throws MojoExecutionException, MojoFailureException {

Modified: 
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/SourcesAggregatorMojo.java
URL: 
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/SourcesAggregatorMojo.java?view=diff&rev=490073&r1=490072&r2=490073
==============================================================================
--- 
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/SourcesAggregatorMojo.java
 (original)
+++ 
incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/SourcesAggregatorMojo.java
 Sun Dec 24 13:33:02 2006
@@ -34,14 +34,14 @@
     /**
      * Default location used for mojo unless overridden in ArtifactItem
      * 
-     * @parameter expression="${outputDirectory}"
+     * @parameter expression="${unpackDirectory}"
      *            
default-value="${project.build.directory}/aggregate/unpack-sources"
      * @required
      */
-    private File outputDirectory;
+    private File unpackDirectory;
 
-    protected File getOutputDirectory() {
-        return outputDirectory;
+    protected File getUnpackDirectory() {
+        return unpackDirectory;
     }
 
     public void execute() throws MojoExecutionException, MojoFailureException {


Reply via email to