You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ke...@apache.org on 2006/02/02 17:50:28 UTC

svn commit: r374433 - /maven/sandbox/plugins/maven-ejb3-plugin/src/main/java/org/apache/maven/plugin/ejb3/Ejb3Mojo.java

Author: kenney
Date: Thu Feb  2 08:50:25 2006
New Revision: 374433

URL: http://svn.apache.org/viewcvs?rev=374433&view=rev
Log:
Added support for generating a -client jar, mostly copied from
the maven-ejb-plugin.

Modified:
    maven/sandbox/plugins/maven-ejb3-plugin/src/main/java/org/apache/maven/plugin/ejb3/Ejb3Mojo.java

Modified: maven/sandbox/plugins/maven-ejb3-plugin/src/main/java/org/apache/maven/plugin/ejb3/Ejb3Mojo.java
URL: http://svn.apache.org/viewcvs/maven/sandbox/plugins/maven-ejb3-plugin/src/main/java/org/apache/maven/plugin/ejb3/Ejb3Mojo.java?rev=374433&r1=374432&r2=374433&view=diff
==============================================================================
--- maven/sandbox/plugins/maven-ejb3-plugin/src/main/java/org/apache/maven/plugin/ejb3/Ejb3Mojo.java (original)
+++ maven/sandbox/plugins/maven-ejb3-plugin/src/main/java/org/apache/maven/plugin/ejb3/Ejb3Mojo.java Thu Feb  2 08:50:25 2006
@@ -18,14 +18,19 @@
 
 import org.apache.maven.archiver.MavenArchiveConfiguration;
 import org.apache.maven.archiver.MavenArchiver;
+import org.apache.maven.artifact.DependencyResolutionRequiredException;
 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.jar.ManifestException;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.archiver.jar.JarArchiver;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.List;
 
 /**
  * Builds J2EE EJB3 archive.
@@ -41,11 +46,14 @@
 public class Ejb3Mojo
     extends AbstractMojo
 {
-
     private static final String[] DEFAULT_EXCLUDES = new String[]{"**/package.html"};
 
     private static final String[] DEFAULT_INCLUDES = new String[]{"**/**"};
     
+    private static final String[] DEFAULT_CLIENT_INCLUDES = new String[]{"**/**"};
+
+    private static final String[] DEFAULT_CLIENT_EXCLUDES = new String[]{"**/*Bean.class",
+         "**/*CMP.class", "**/*Session.class", "**/package.html"};
 
     /**
      * Directory containing the generated EJB3.
@@ -62,7 +70,7 @@
      * @parameter alias="parName" expression="${project.build.finalName}"
      * @required
      */
-    private String finalName;
+    private String jarName;
 
     /**
      * Directory containing the classes.
@@ -82,6 +90,46 @@
     private File ejb3SourceDirectory;
 
     /**
+     * Whether the ejb client jar should be generated or not. Default
+     * is false.
+     *
+     * @parameter
+     * @todo boolean instead
+     */
+    private String generateClient = Boolean.FALSE.toString();
+
+    /**
+     * Excludes.
+     *
+     * <br/>Usage:
+     * <pre>
+     * &lt;clientIncludes&gt;
+     *   &lt;clientInclude&gt;**&#47;*Ejb.class&lt;&#47;clientInclude&gt;
+     *   &lt;clientInclude&gt;**&#47;*Bean.class&lt;&#47;clientInclude&gt;
+     * &lt;&#47;clientIncludes&gt;
+     * </pre>
+     * <br/>Attribute is used only if client jar is generated.
+     * <br/>Default exclusions: **&#47;*Bean.class, **&#47;*CMP.class, **&#47;*Session.class, **&#47;package.html
+     * @parameter
+     */
+    private List clientExcludes;
+
+    /**
+     * Includes.
+     *
+     * <br/>Usage:
+     * <pre>
+     * &lt;clientIncludes&gt;
+     *   &lt;clientInclude&gt;**&#47;*&lt;&#47;clientInclude&gt;
+     * &lt;&#47;clientIncludes&gt;
+     * </pre>
+     * <br/>Attribute is used only if client jar is generated.
+     * <br/>Default value: **&#47;**
+     * @parameter
+     */
+    private List clientIncludes;
+
+    /**
      * The maven project.
      *
      * @parameter expression="${project}"
@@ -106,6 +154,23 @@
      private JarArchiver jarArchiver;
 
     /**
+     * The client Jar archiver.
+     *
+     * @parameter expression="${component.org.codehaus.plexus.archiver.Archiver#jar}"
+     * @required
+     */
+    private JarArchiver clientJarArchiver;
+
+    /**
+     * The maven project's helper.
+     *
+     * @parameter expression="${component.org.apache.maven.project.MavenProjectHelper}"
+     * @required
+     * @readonly
+     */
+    private MavenProjectHelper projectHelper;
+
+    /**
      * Generates the EJB3.
      *
      * @todo Add license files in META-INF directory.
@@ -113,47 +178,106 @@
     public void execute()
         throws MojoExecutionException
     {
-        // Copy source files
         try
         {
-            if ( ejb3SourceDirectory != null
-                    && ejb3SourceDirectory.exists() )
-            {
-                getLog().info( "Copy ejb3 resources to " + outputDirectory.getAbsolutePath() );
-                FileUtils.copyDirectoryStructure( ejb3SourceDirectory, outputDirectory );
-            }
+            copyResources();
         }
         catch ( IOException e )
         {
             throw new MojoExecutionException( "Error copying EJB3 resources", e );
         }
 
-        File ejb3File = new File( basedir, finalName + ".ejb3" );
+        try
+        {
+            generateEJB3Archive();
+        }
+        catch ( Exception e )
+        {
+            throw new MojoExecutionException( "Error assembling EJB3", e );
+        }
+    
+        try
+        {
+            generateClient( jarName );
+        }
+        catch ( Exception e )
+        {
+            throw new MojoExecutionException( "Error creating client archive", e );
+        }
+    }
+
+    private void copyResources()
+        throws IOException
+    {
+        if ( ejb3SourceDirectory != null
+                && ejb3SourceDirectory.exists() )
+        {
+            getLog().info( "Copy ejb3 resources to " + outputDirectory.getAbsolutePath() );
+            FileUtils.copyDirectoryStructure( ejb3SourceDirectory, outputDirectory );
+        }
+    }
+
+
+    private void generateEJB3Archive()
+        throws ArchiverException, ManifestException, IOException, DependencyResolutionRequiredException
+    {
+        File ejb3File = new File( basedir, jarName + ".ejb3" );
 
         MavenArchiver archiver = new MavenArchiver();
         archiver.setArchiver( jarArchiver );
 
         archiver.setOutputFile( ejb3File );
 
-        try
+        if ( outputDirectory == null || !outputDirectory.exists() )
+        {
+            getLog().warn( "EJB3 will be empty - no content was marked for inclusion!" );
+        }
+        else
         {
-            if ( outputDirectory == null || !outputDirectory.exists() )
+            archiver.getArchiver().addDirectory( outputDirectory, DEFAULT_INCLUDES, DEFAULT_EXCLUDES );
+        }
+
+        archiver.createArchive( project, archive );
+
+        project.getArtifact().setFile( ejb3File );
+    }
+
+    private void generateClient( String jarName )
+        throws ArchiverException, ManifestException, IOException, DependencyResolutionRequiredException
+    {
+        if ( new Boolean( generateClient ).booleanValue() )
+        {
+            getLog().info( "Building ejb client " + jarName + "-client" );
+
+            String[] includes = DEFAULT_CLIENT_INCLUDES;
+            String[] excludes = DEFAULT_CLIENT_EXCLUDES;
+
+            if ( clientIncludes != null && !clientIncludes.isEmpty() )
             {
-                getLog().warn( "EJB3 will be empty - no content was marked for inclusion!" );
+                includes = (String[]) clientIncludes.toArray( new String[clientIncludes.size()] );
             }
-            else
+
+            if ( clientExcludes != null && !clientExcludes.isEmpty() )
             {
-                archiver.getArchiver().addDirectory( outputDirectory, DEFAULT_INCLUDES, DEFAULT_EXCLUDES );
+                excludes = (String[]) clientExcludes.toArray( new String[clientExcludes.size()] );
             }
 
-            archiver.createArchive( project, archive );
+            File clientJarFile = new File( basedir, jarName + "-client.jar" );
 
-            project.getArtifact().setFile( ejb3File );
-        }
-        catch ( Exception e )
-        {
-            // TODO: improve error handling
-            throw new MojoExecutionException( "Error assembling EJB3", e );
+            MavenArchiver clientArchiver = new MavenArchiver();
+
+            clientArchiver.setArchiver( clientJarArchiver );
+
+            clientArchiver.setOutputFile( clientJarFile );
+
+            clientArchiver.getArchiver().addDirectory( outputDirectory, includes, excludes );
+
+            // create archive
+            clientArchiver.createArchive( project, archive );
+
+            projectHelper.attachArtifact( project, "jar", "client", clientJarFile );
         }
+
     }
+
 }