cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r490118 - in /incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin: aggregator/ util/
Date Mon, 25 Dec 2006 09:07:19 GMT
Author: aadamchik
Date: Mon Dec 25 01:07:18 2006
New Revision: 490118

URL: http://svn.apache.org/viewvc?view=rev&rev=490118
Log:
CAY-719:Finalize Maven assembly scripts for the upcoming 3.0 milestone releases
(refactoring; added support for aggregate-sources goal)

Added:
    incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/util/
    incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/util/PatternGroup.java
      - copied, changed from r490115, incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/PatternGroup.java
Removed:
    incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/PatternGroup.java
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/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=490118&r1=490117&r2=490118
==============================================================================
--- 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
Mon Dec 25 01:07:18 2006
@@ -24,6 +24,9 @@
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.cayenne.maven.plugin.util.PatternGroup;
+import org.apache.maven.archiver.MavenArchiveConfiguration;
+import org.apache.maven.archiver.MavenArchiver;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -34,15 +37,26 @@
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectHelper;
 import org.codehaus.plexus.archiver.ArchiverException;
 import org.codehaus.plexus.archiver.UnArchiver;
+import org.codehaus.plexus.archiver.jar.JarArchiver;
 import org.codehaus.plexus.archiver.manager.ArchiverManager;
 import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
 import org.codehaus.plexus.util.FileUtils;
 
-// copied from Maven Dependency plugin v. 1.0, AbstractFromConfigurationMojo.
+/**
+ * A superclass of aggregator mojos.
+ * 
+ * @author Andrus Adamchik
+ */
 public abstract class AbstractAggregatorMojo extends AbstractMojo {
 
+    // by default exclude maven entries from other jars and overlapping manifests
+    static final String[] DEFAULT_EXCLUDES = new String[] {
+            "META-INF/maven/**", "META-INF/MANIFEST.MF"
+    };
+
     /**
      * Used to look up Artifacts in the remote repository.
      * 
@@ -107,44 +121,105 @@
      */
     protected MavenProject project;
 
-    protected abstract File getUnpackDirectory();
+    /**
+     * @component
+     */
+    private MavenProjectHelper projectHelper;
 
     /**
-     * Preprocesses the list of ArtifactItems. This method defaults the outputDirectory if
-     * not set and creates the output Directory if it doesn't exist.
-     * 
-     * @return An ArrayList of preprocessed ArtifactItems
-     * @throws MojoExecutionException with a message if an error occurs.
-     * @see ArtifactItem
+     * Preprocesses the list of ArtifactItems and unpacks them to the provided directory.
      */
-    protected ArrayList getArtifactItems() throws MojoExecutionException {
+    protected void unpackArtifacts(File unpackDirectory, String classifier)
+            throws MojoExecutionException {
+
+        Iterator it = artifactItems.iterator();
+        while (it.hasNext()) {
+            ArtifactItem artifactItem = (ArtifactItem) it.next();
+            artifactItem.setClassifier(classifier);
 
-        Iterator iter = artifactItems.iterator();
-        while (iter.hasNext()) {
-            ArtifactItem artifactItem = (ArtifactItem) iter.next();
             getLog().debug("Configured artifact: " + artifactItem.toString());
 
             if (artifactItem.getOutputDirectory() == null) {
-                artifactItem.setOutputDirectory(getUnpackDirectory());
+                artifactItem.setOutputDirectory(unpackDirectory);
             }
 
             artifactItem.getOutputDirectory().mkdirs();
+            unpackArtifact(artifactItem);
+        }
+    }
+
+    /**
+     * Creates a filtered aggregated jar file from unpacked artifacts.
+     */
+    protected void packAggregatedArtifact(
+            File unpackDirectory,
+            String finalName,
+            String classifier,
+            File excludesFile,
+            File includesFile) throws MojoExecutionException {
+
+        if (classifier != null) {
+            finalName += "-" + classifier;
+        }
+
+        File outputDirectory = new File(project.getBuild().getDirectory());
+        File destinationFile = new File(outputDirectory, finalName + ".jar");
+
+        JarArchiver jarArchiver;
+        try {
+            jarArchiver = (JarArchiver) archiverManager.getArchiver("jar");
+        }
+        catch (NoSuchArchiverException e) {
+            throw new MojoExecutionException("Unknown archiver type", e);
+        }
+
+        PatternGroup excludes = new PatternGroup(excludesFile);
+        excludes.addPatterns(DEFAULT_EXCLUDES);
+
+        PatternGroup includes = new PatternGroup(includesFile);
+        if (includes.size() == 0) {
+            includes.addPatterns(new String[] {
+                "**/**"
+            });
+        }
+
+        // MavenArchiver adds Maven stuff into META-INF
+        MavenArchiver archiver = new MavenArchiver();
+        archiver.setArchiver(jarArchiver);
+        archiver.setOutputFile(destinationFile);
+
+        MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
+
+        try {
+            if (!unpackDirectory.exists()) {
+                getLog().warn("Jar will be empty, no unpack directory.");
+            }
+            else {
+                archiver.getArchiver().addDirectory(
+                        unpackDirectory,
+                        includes.getPatterns(),
+                        excludes.getPatterns());
+            }
+
+            archiver.createArchive(project, archive);
+        }
+        catch (Exception e) {
+            throw new MojoExecutionException("Error assembling JAR", e);
+        }
+
+        if (classifier == null) {
+            project.getArtifact().setFile(destinationFile);
+        }
+        else {
+            projectHelper.attachArtifact(project, "jar", classifier, destinationFile);
         }
-        return artifactItems;
     }
 
     /**
      * Resolves the Artifact from the remote repository if nessessary. If no version is
      * specified, it will be retrieved from the DependencyManagement section of the pom.
-     * 
-     * @param artifactItem containing information about artifact from plugin
-     *            configuration.
-     * @return Artifact object representing the specified file.
-     * @throws MojoExecutionException with a message if the version can't be found in
-     *             DependencyManagement.
      */
-    protected Artifact getArtifact(ArtifactItem artifactItem)
-            throws MojoExecutionException {
+    private Artifact getArtifact(ArtifactItem artifactItem) throws MojoExecutionException
{
         Artifact artifact;
 
         if (artifactItem.getVersion() == null) {
@@ -219,13 +294,9 @@
     }
 
     /**
-     * This method gets the Artifact object and calls DependencyUtil.unpackFile.
-     * 
-     * @param artifactItem containing the information about the Artifact to unpack.
-     * @throws MojoExecutionException with a message if an error occurs.
+     * Unpacks an artifact item.
      */
-    protected void unpackArtifact(ArtifactItem artifactItem)
-            throws MojoExecutionException {
+    private void unpackArtifact(ArtifactItem artifactItem) throws MojoExecutionException
{
         Artifact artifact = getArtifact(artifactItem);
 
         File location = artifactItem.getOutputDirectory();

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=490118&r1=490117&r2=490118
==============================================================================
--- 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
Mon Dec 25 01:07:18 2006
@@ -1,14 +1,8 @@
 package org.apache.cayenne.maven.plugin.aggregator;
 
 import java.io.File;
-import java.util.ArrayList;
-import java.util.Iterator;
 
-import org.apache.maven.archiver.MavenArchiveConfiguration;
-import org.apache.maven.archiver.MavenArchiver;
 import org.apache.maven.plugin.MojoExecutionException;
-import org.codehaus.plexus.archiver.jar.JarArchiver;
-import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
 
 /**
  * A goal to build aggregated jar artifacts from multiple other artifacts.
@@ -20,11 +14,6 @@
  */
 public class BinAggregatorMojo extends AbstractAggregatorMojo {
 
-    // by default exclude maven entries from otehr jars and overlapping manifests
-    static final String[] DEFAULT_EXCLUDES = new String[] {
-            "META-INF/maven/**", "META-INF/MANIFEST.MF"
-    };
-
     /**
      * Default location used for mojo unless overridden in ArtifactItem
      * 
@@ -56,71 +45,13 @@
      */
     private File includesFile;
 
-    protected File getUnpackDirectory() {
-        return unpackDirectory;
-    }
-
     public void execute() throws MojoExecutionException {
-        ArrayList artifactItems = getArtifactItems();
-        Iterator iter = artifactItems.iterator();
-        while (iter.hasNext()) {
-            ArtifactItem artifactItem = (ArtifactItem) iter.next();
-            unpackArtifact(artifactItem);
-        }
-
-        File file = packArtifact();
-        getLog().warn("created jar " + file.getAbsolutePath());
-        project.getArtifact().setFile(file);
-    }
-
-    private File packArtifact() throws MojoExecutionException {
-
-        File outputDirectory = new File(project.getBuild().getDirectory());
-        File destinationFile = new File(outputDirectory, finalName + ".jar");
-
-        JarArchiver jarArchiver;
-        try {
-            jarArchiver = (JarArchiver) archiverManager.getArchiver("jar");
-        }
-        catch (NoSuchArchiverException e) {
-            throw new MojoExecutionException("Unknown archiver type", e);
-        }
-
-        PatternGroup excludes = new PatternGroup(excludesFile);
-        excludes.addPatterns(DEFAULT_EXCLUDES);
-
-        PatternGroup includes = new PatternGroup(includesFile);
-        if (includes.size() == 0) {
-            includes.addPatterns(new String[] {
-                "**/**"
-            });
-        }
-
-        // MavenArchiver adds Maven stuff into META-INF
-        MavenArchiver archiver = new MavenArchiver();
-        archiver.setArchiver(jarArchiver);
-        archiver.setOutputFile(destinationFile);
-
-        MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
-
-        try {
-            File contentDirectory = getUnpackDirectory();
-            if (!contentDirectory.exists()) {
-                getLog().warn("JAR will be empty - no content was marked for inclusion!");
-            }
-            else {
-                archiver.getArchiver().addDirectory(
-                        contentDirectory,
-                        includes.getPatterns(),
-                        excludes.getPatterns());
-            }
-
-            archiver.createArchive(project, archive);
-        }
-        catch (Exception e) {
-            throw new MojoExecutionException("Error assembling JAR", e);
-        }
-
-        return destinationFile;
+        unpackArtifacts(unpackDirectory, null);
+        packAggregatedArtifact(
+                unpackDirectory,
+                finalName,
+                null,
+                excludesFile,
+                includesFile);
     }
 }

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=490118&r1=490117&r2=490118
==============================================================================
--- 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
Mon Dec 25 01:07:18 2006
@@ -40,11 +40,35 @@
      */
     private File unpackDirectory;
 
-    protected File getUnpackDirectory() {
-        return unpackDirectory;
-    }
+    /**
+     * Name of the generated JAR.
+     * 
+     * @parameter expression="${project.build.finalName}"
+     * @required
+     */
+    private String finalName;
+
+    /**
+     * A file that contains excludes patterns.
+     * 
+     * @parameter
+     */
+    private File excludesFile;
+
+    /**
+     * A file that contains includes patterns.
+     * 
+     * @parameter
+     */
+    private File includesFile;
 
     public void execute() throws MojoExecutionException, MojoFailureException {
-        // TODO
+        unpackArtifacts(unpackDirectory, "sources");
+        packAggregatedArtifact(
+                unpackDirectory,
+                finalName,
+                "sources",
+                excludesFile,
+                includesFile);
     }
 }

Copied: incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/util/PatternGroup.java
(from r490115, incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/PatternGroup.java)
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/util/PatternGroup.java?view=diff&rev=490118&p1=incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/PatternGroup.java&r1=490115&p2=incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/util/PatternGroup.java&r2=490118
==============================================================================
--- incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/aggregator/PatternGroup.java
(original)
+++ incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/util/PatternGroup.java
Mon Dec 25 01:07:18 2006
@@ -16,7 +16,7 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
-package org.apache.cayenne.maven.plugin.aggregator;
+package org.apache.cayenne.maven.plugin.util;
 
 import java.io.BufferedReader;
 import java.io.File;



Mime
View raw message