You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sn...@apache.org on 2006/11/01 19:37:02 UTC

svn commit: r470026 - in /maven/plugins/trunk/maven-ear-plugin/src: main/java/org/apache/maven/plugin/ear/EarMojo.java test/java/org/apache/maven/plugin/ear/EarMojoTest.java test/resources/projects/project-022/ test/resources/projects/project-022/pom.xml

Author: snicoll
Date: Wed Nov  1 10:37:02 2006
New Revision: 470026

URL: http://svn.apache.org/viewvc?view=rev&rev=470026
Log:
MEAR-36: Added classifier functionnality to EAR plugin
Submitted by: Eric Bernstein
Reviewed by: Stephane Nicoll

Added:
    maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-022/
    maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-022/pom.xml   (with props)
Modified:
    maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java
    maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/EarMojoTest.java

Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java?view=diff&rev=470026&r1=470025&r2=470026
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java (original)
+++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java Wed Nov  1 10:37:02 2006
@@ -20,6 +20,7 @@
 import org.apache.maven.archiver.MavenArchiver;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
+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;
@@ -113,6 +114,14 @@
     private String unpackTypes;
 
     /**
+     * Classifier to add to the artifact generated. If given, the artifact will
+     * be an attachment instead.
+     *
+     * @parameter
+     */
+    private String classifier;
+
+    /**
      * The directory to get the resources from.
      *
      * @parameter expression="${project.build.outputDirectory}"
@@ -137,6 +146,11 @@
     private MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
 
     /**
+     * @component
+     */
+    private MavenProjectHelper projectHelper;
+
+    /**
      * The archive manager.
      *
      * @component
@@ -270,7 +284,7 @@
 
         try
         {
-            File earFile = new File( outputDirectory, finalName + ".ear" );
+            File earFile = getEarFile( outputDirectory, finalName, classifier );
             MavenArchiver archiver = new MavenArchiver();
             archiver.setArchiver( jarArchiver );
             archiver.setOutputFile( earFile );
@@ -281,7 +295,14 @@
             archiver.getArchiver().addDirectory( getWorkDirectory() );
             archiver.createArchive( getProject(), archive );
 
-            project.getArtifact().setFile( earFile );
+            if ( classifier != null )
+            {
+                projectHelper.attachArtifact( getProject(), "ear", classifier, earFile );
+            }
+            else
+            {
+                getProject().getArtifact().setFile( earFile );
+            }
         }
         catch ( Exception e )
         {
@@ -351,6 +372,28 @@
             getLog().info( "Including custom manifest file[" + customManifestFile + "]" );
             archive.setManifestFile( customManifestFile );
         }
+    }
+
+    /**
+     * Returns the EAR file to generate, based on an optional classifier.
+     *
+     * @param basedir    the output directory
+     * @param finalName  the name of the ear file
+     * @param classifier an optional classifier
+     * @return the EAR file to generate
+     */
+    private static File getEarFile( String basedir, String finalName, String classifier )
+    {
+        if ( classifier == null )
+        {
+            classifier = "";
+        }
+        else if ( classifier.trim().length() > 0 && !classifier.startsWith( "-" ) )
+        {
+            classifier = "-" + classifier;
+        }
+
+        return new File( basedir, finalName + classifier + ".ear" );
     }
 
     /**

Modified: maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/EarMojoTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/EarMojoTest.java?view=diff&rev=470026&r1=470025&r2=470026
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/EarMojoTest.java (original)
+++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/EarMojoTest.java Wed Nov  1 10:37:02 2006
@@ -236,4 +236,15 @@
                        new boolean[]{false, true, false, false, true} );
     }
 
+    /**
+     * Builds an EAR with a classifier.
+     */
+    public void testProject022()
+        throws Exception
+    {
+        final File baseDir = executeMojo( "project-022", new Properties() );
+        final File expectedFile = new File( baseDir, "target/maven-ear-plugin-test-project-022-99.0-myclassifier.ear" );
+        assertTrue( "EAR archive not found", expectedFile.exists() );
+    }
+
 }

Added: maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-022/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-022/pom.xml?view=auto&rev=470026
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-022/pom.xml (added)
+++ maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-022/pom.xml Wed Nov  1 10:37:02 2006
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>ear</groupId>
+  <artifactId>maven-ear-plugin-test-project-022</artifactId>
+  <version>99.0</version>
+  <name>Maven</name>
+  <packaging>ear</packaging>
+  <dependencies>
+    <dependency>
+      <groupId>eartest</groupId>
+      <artifactId>ejb-sample-one</artifactId>
+      <version>1.0</version>
+      <type>ejb</type>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-ear-plugin</artifactId>
+        <configuration>
+          <classifier>myclassifier</classifier>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-022/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-022/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision