You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by ke...@apache.org on 2005/08/02 23:48:03 UTC

svn commit: r227088 - in /maven/components/trunk: ./ maven-plugins/ maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ maven-plugins/maven-ear-plugin/src/site/ maven-plugins/maven-ear-plugin/src/site/apt/

Author: kenney
Date: Tue Aug  2 14:47:50 2005
New Revision: 227088

URL: http://svn.apache.org/viewcvs?rev=227088&view=rev
Log:
o Bumped version of plexus-container-default to 1.0-alpha-6-SNAPSHOT

o Committed changes to the EAR plugin on behalf of Stephane Nicoll,
  awaiting his commit privileges.
  Resolves MNG-621 and MNG-622.

Added:
    maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java   (with props)
    maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModule.java   (with props)
    maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModuleFactory.java   (with props)
    maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EjbClientModule.java   (with props)
    maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EjbModule.java   (with props)
    maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/JavaModule.java   (with props)
    maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/RarModule.java   (with props)
    maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/WebModule.java   (with props)
    maven/components/trunk/maven-plugins/maven-ear-plugin/src/site/
    maven/components/trunk/maven-plugins/maven-ear-plugin/src/site/apt/
    maven/components/trunk/maven-plugins/maven-ear-plugin/src/site/apt/configuration-examples.apt   (with props)
Modified:
    maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java
    maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java
    maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java
    maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarPluginException.java
    maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java
    maven/components/trunk/maven-plugins/pom.xml
    maven/components/trunk/pom.xml

Added: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java?rev=227088&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java (added)
+++ maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java Tue Aug  2 14:47:50 2005
@@ -0,0 +1,226 @@
+package org.apache.maven.plugin.ear;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * A base implementation of an {@link EarModule}.
+ *
+ * @author <a href="stephane.nicoll@gmail.com">Stephane Nicoll</a>
+ * @version $Id$
+ */
+public abstract class AbstractEarModule
+    implements EarModule
+{
+
+    protected static final String MODULE_ELEMENT = "module";
+
+    private String uri;
+
+    private Artifact artifact;
+
+    // Those are set by the configuration
+
+    private String groupId;
+
+    private String artifactId;
+
+    private String bundleDir;
+
+    private String bundleFileName;
+
+    /**
+     * Empty constructor to be used when the module
+     * is built based on the configuration.
+     */
+    public AbstractEarModule()
+    {
+    }
+
+    /**
+     * Creates an ear module from the artifact.
+     *
+     * @param a the artifact
+     */
+    public AbstractEarModule( Artifact a )
+    {
+        this.artifact = a;
+        this.groupId = a.getGroupId();
+        this.artifactId = a.getArtifactId();
+        this.bundleDir = null;
+    }
+
+    public void resolveArtifact( Set artifacts )
+        throws EarPluginException
+    {
+        if ( artifact != null )
+        {
+            return;
+        }
+        else
+        {
+            if ( groupId == null || artifactId == null )
+            {
+                throw new EarPluginException(
+                    "Could not resolve artifact[" + groupId + ":" + artifactId + ":" + getType() + "]" );
+            }
+
+            Iterator i = artifacts.iterator();
+            while ( i.hasNext() )
+            {
+                Artifact a = (Artifact) i.next();
+                if ( a.getGroupId().equals( groupId ) && a.getArtifactId().equals( artifactId ) &&
+                    a.getType().equals( getType() ) )
+                {
+                    artifact = a;
+                    return;
+                }
+            }
+
+            // Artifact has not been found
+            throw new EarPluginException( "Artifact[" + groupId + ":" + artifactId + ":" + getType() + "] " +
+                "is not a dependency of the project." );
+        }
+    }
+
+    /**
+     * Returns the type associated to the module.
+     *
+     * @return the artifact's type of the module
+     */
+    protected abstract String getType();
+
+    public Artifact getArtifact()
+    {
+        return artifact;
+    }
+
+    public String getUri()
+    {
+        if ( uri == null )
+        {
+            if ( getBundleDir() == null )
+            {
+                uri = getBundleFileName();
+            }
+            else
+            {
+                uri = getBundleDir() + getBundleFileName();
+            }
+        }
+        return uri;
+    }
+
+    /**
+     * Returns the artifact's groupId.
+     *
+     * @return the group Id
+     */
+    public String getGroupId()
+    {
+        return groupId;
+    }
+
+    /**
+     * Returns the artifact's Id.
+     *
+     * @return the artifact Id
+     */
+    public String getArtifactId()
+    {
+        return artifactId;
+    }
+
+    /**
+     * Returns the bundle directory. If null, the module
+     * is bundled in the root of the EAR.
+     *
+     * @return the custom bundle directory
+     */
+    public String getBundleDir()
+    {
+        if ( bundleDir != null )
+        {
+            bundleDir = cleanBundleDir( bundleDir );
+        }
+        return bundleDir;
+    }
+
+    /**
+     * Returns the bundle file name. If null, the artifact's
+     * file name is returned.
+     *
+     * @return the bundle file name
+     */
+    public String getBundleFileName()
+    {
+        if ( bundleFileName == null )
+        {
+            bundleFileName = artifact.getFile().getName();
+        }
+        return bundleFileName;
+    }
+
+    public String toString()
+    {
+        StringBuffer sb = new StringBuffer();
+        sb.append( getType() ).append( ":" ).append( groupId ).append( ":" ).append( artifactId );
+        if ( artifact != null )
+        {
+            sb.append( ":" ).append( artifact.getVersion() );
+        }
+        return sb.toString();
+    }
+
+    /**
+     * Cleans the bundle directory so that it might be used
+     * properly.
+     *
+     * @param bundleDir the bundle directory to clean
+     * @return the cleaned bundle directory
+     */
+    private static String cleanBundleDir( String bundleDir )
+    {
+        if ( bundleDir == null )
+        {
+            return bundleDir;
+        }
+
+        // Using slashes
+        bundleDir = bundleDir.replace( '\\', '/' );
+
+        // Remove '/' prefix if any so that directory is a relative path
+        if ( bundleDir.startsWith( " / " ) )
+        {
+            bundleDir = bundleDir.substring( 1, bundleDir.length() );
+        }
+
+        // Adding '/' suffix to specify a directory structure
+        if ( !bundleDir.endsWith( "/" ) )
+        {
+            bundleDir = bundleDir + "/";
+        }
+
+        System.out.println( "Bundle dir[" + bundleDir + "]" );
+
+        return bundleDir;
+    }
+}

Propchange: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java?rev=227088&r1=227087&r2=227088&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java (original)
+++ maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java Tue Aug  2 14:47:50 2005
@@ -18,12 +18,12 @@
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.ear.module.EarModule;
-import org.apache.maven.plugin.ear.module.EarModuleFactory;
+import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
 
 import java.io.File;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
@@ -46,48 +46,91 @@
      * @parameter expression="${project}"
      * @required
      * @readonly
-     * @description "the maven project to use"
      */
     private MavenProject project;
 
     /**
+     * The ear modules configuration.
+     *
+     * @parameter
+     */
+    private EarModule[] modules;
+
+    /**
      * Directory that resources are copied to during the build.
      *
      * @parameter expression="${project.build.directory}/${project.build.finalName}"
      * @required
      */
-    private String earDirectory;
+    private String workDirectory;
 
-    private List modules;
+    private List earModules;
 
     private File buildDir;
 
-    protected List getModules()
+    public void execute()
+        throws MojoExecutionException
     {
-        if ( modules == null )
+        getLog().debug( "Resolving ear modules ..." );
+
+        if ( modules != null && modules.length > 0 )
         {
-            // Gather modules and copy them
-            modules = new ArrayList();
-            Set artifacts = project.getArtifacts();
-            for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
+
+            // Let's validate user-defined modules
+            EarModule module = null;
+            try
             {
-                Artifact artifact = (Artifact) iter.next();
-                if ( !Artifact.SCOPE_TEST.equals( artifact.getScope())  ||
-                    !Artifact.SCOPE_PROVIDED.equals( artifact.getScope()) )
+                for ( int i = 0; i < modules.length; i++ )
                 {
-                    EarModule module = EarModuleFactory.newEarModule( artifact );
-                    modules.add( module );
+                    module = (EarModule) modules[i];
+                    getLog().debug( "Resolving ear module[" + module + "]" );
+                    module.resolveArtifact( project.getArtifacts() );
                 }
             }
+            catch ( EarPluginException e )
+            {
+                throw new MojoExecutionException( "Failed to initialize ear modules", e );
+            }
+            earModules = new ArrayList( Arrays.asList( modules ) );
+        }
+        else
+        {
+            earModules = new ArrayList();
         }
-        return modules;
+
+        // Let's add other modules
+        Set artifacts = project.getArtifacts();
+        for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
+        {
+            Artifact artifact = (Artifact) iter.next();
+
+            // Artifact is not yet registered and it has neither test, nor a
+            // provided scope
+            if ( !isArtifactRegistered( artifact, earModules ) && (
+                !Artifact.SCOPE_TEST.equals( artifact.getScope() ) ||
+                    !Artifact.SCOPE_PROVIDED.equals( artifact.getScope() ) ) )
+            {
+                EarModule module = EarModuleFactory.newEarModule( artifact );
+                earModules.add( module );
+            }
+        }
+
+    }
+
+    protected List getModules()
+    {
+        if ( earModules == null )
+        {
+            throw new IllegalStateException( "Ear modules have not been initialized" );
+        }
+        return earModules;
     }
 
     protected File getBuildDir()
     {
         if ( buildDir == null )
         {
-            buildDir = new File( earDirectory );
+            buildDir = new File( workDirectory );
         }
         return buildDir;
     }
@@ -97,8 +140,22 @@
         return project;
     }
 
-    protected String getEarDirectory()
+    protected String getWorkDirectory()
     {
-        return earDirectory;
+        return workDirectory;
+    }
+
+    private static boolean isArtifactRegistered( Artifact a, List currentList )
+    {
+        Iterator i = currentList.iterator();
+        while ( i.hasNext() )
+        {
+            EarModule em = (EarModule) i.next();
+            if ( em.getArtifact().equals( a ) )
+            {
+                return true;
+            }
+        }
+        return false;
     }
 }

Modified: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java?rev=227088&r1=227087&r2=227088&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java (original)
+++ maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java Tue Aug  2 14:47:50 2005
@@ -1,6 +1,5 @@
 package org.apache.maven.plugin.ear;
 
-import org.apache.maven.plugin.ear.module.EarModule;
 import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
 import org.codehaus.plexus.util.xml.XMLWriter;
 

Added: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModule.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModule.java?rev=227088&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModule.java (added)
+++ maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModule.java Tue Aug  2 14:47:50 2005
@@ -0,0 +1,68 @@
+package org.apache.maven.plugin.ear;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+import java.util.Set;
+
+/**
+ * The ear module interface.
+ *
+ * @author <a href="stephane.nicoll@gmail.com">Stephane Nicoll</a>
+ * @version $Id$
+ */
+public interface EarModule
+{
+
+    /**
+     * Returns the {@link Artifact} representing this module.
+     * <p/>
+     * Note that this might return <tt>null</tt> till the
+     * module has been resolved.
+     *
+     * @return the artifact
+     * @see #resolveArtifact(java.util.Set)
+     */
+    public Artifact getArtifact();
+
+    /**
+     * Returns the <tt>URI</tt> for this module.
+     *
+     * @return the <tt>URI</tt>
+     */
+    public String getUri();
+
+    /**
+     * Appends the <tt>XML</tt> representation of this module.
+     *
+     * @param writer  the writer to use
+     * @param version the version of the <tt>application.xml</tt> file
+     */
+    public void appendModule( XMLWriter writer, String version );
+
+    /**
+     * Resolves the {@link Artifact} represented by the module.
+     *
+     * @param artifacts the project's artifacts
+     * @throws EarPluginException if the artifact could not be resolved
+     */
+    public void resolveArtifact( Set artifacts )
+        throws EarPluginException;
+
+}

Propchange: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModule.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModuleFactory.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModuleFactory.java?rev=227088&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModuleFactory.java (added)
+++ maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModuleFactory.java Tue Aug  2 14:47:50 2005
@@ -0,0 +1,65 @@
+package org.apache.maven.plugin.ear;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+
+/**
+ * Builds an {@link EarModule} based on an <tt>Artifact</tt>.
+ *
+ * @author <a href="stephane.nicoll@gmail.com">Stephane Nicoll</a>
+ * @version $Id$
+ */
+public final class EarModuleFactory
+{
+
+    /**
+     * Creates a new {@link EarModule} based on the
+     * specified {@link Artifact}.
+     *
+     * @param artifact the artifact
+     * @return an ear module for this artifact
+     */
+    public static final EarModule newEarModule( Artifact artifact )
+    {
+        if ( "jar".equals( artifact.getType() ) )
+        {
+            return new JavaModule( artifact );
+        }
+        else if ( "ejb".equals( artifact.getType() ) )
+        {
+            return new EjbModule( artifact );
+        }
+        else if ( "ejb-client".equals( artifact.getType() ) )
+        {
+            return new EjbClientModule( artifact );
+        }
+        else if ( "rar".equals( artifact.getType() ) )
+        {
+            return new RarModule( artifact );
+        }
+        else if ( "war".equals( artifact.getType() ) )
+        {
+            return new WebModule( artifact );
+        }
+        else
+        {
+            throw new IllegalStateException( "Could not handle artifact type[" + artifact.getType() + "]" );
+        }
+    }
+
+}

Propchange: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModuleFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModuleFactory.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java?rev=227088&r1=227087&r2=227088&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java (original)
+++ maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java Tue Aug  2 14:47:50 2005
@@ -19,7 +19,6 @@
 import org.apache.maven.archiver.MavenArchiveConfiguration;
 import org.apache.maven.archiver.MavenArchiver;
 import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.ear.module.EarModule;
 import org.codehaus.plexus.util.FileUtils;
 
 import java.io.File;
@@ -32,7 +31,7 @@
  * Builds J2EE Enteprise Archive (EAR) files.
  *
  * @author <a href="stephane.nicoll@gmail.com">Stephane Nicoll</a>
- * @version $Id $
+ * @version $Id$
  * @goal ear
  * @phase package
  * @requiresDependencyResolution test
@@ -77,7 +76,7 @@
      *
      * @parameter alias="earName" expression="${project.build.finalName}"
      * @required
-     * @readonly     
+     * @readonly
      */
     private String finalName;
 
@@ -100,11 +99,14 @@
     public void execute()
         throws MojoExecutionException
     {
+        // Initializes ear modules
+        super.execute();
+
         getLog().debug( " ======= EarMojo settings =======" );
         getLog().debug( "earSourceDirectory[" + earSourceDirectory + "]" );
         getLog().debug( "manifestLocation[" + manifestLocation + "]" );
         getLog().debug( "applicationXmlLocation[" + applicationXmlLocation + "]" );
-        getLog().debug( "earDirectory[" + getEarDirectory() + "]" );
+        getLog().debug( "workDirectory[" + getWorkDirectory() + "]" );
         getLog().debug( "outputDirectory[" + outputDirectory + "]" );
         getLog().debug( "finalName[" + finalName + "]" );
         getLog().debug( "excludedDependencies[" + excludedDependencies + "]" );
@@ -115,9 +117,9 @@
             for ( Iterator iter = getModules().iterator(); iter.hasNext(); )
             {
                 EarModule module = (EarModule) iter.next();
-                getLog().info( "Copying artifact[" + module.getArtifact().getGroupId() + ", " +
-                               module.getArtifact().getId() + ", " + module.getArtifact().getType() + "]" );
-                FileUtils.copyFileToDirectory( module.getArtifact().getFile(), getBuildDir() );
+                getLog().info( "Copying artifact[" + module + "] to[" + module.getUri() + "]" );
+                File destinationFile = buildDestinationFile( getBuildDir(), module.getUri() );
+                FileUtils.copyFile( module.getArtifact().getFile(), destinationFile );
             }
         }
         catch ( IOException e )
@@ -144,7 +146,8 @@
         File ddFile = new File( getBuildDir(), APPLICATION_XML_URI );
         if ( !ddFile.exists() )
         {
-            throw new MojoExecutionException( "Deployment descriptor: " + ddFile.getAbsolutePath() + " does not exist." );
+            throw new MojoExecutionException(
+                "Deployment descriptor: " + ddFile.getAbsolutePath() + " does not exist." );
         }
 
         try
@@ -160,5 +163,10 @@
         {
             throw new MojoExecutionException( "Error assembling EAR", e );
         }
+    }
+
+    private static File buildDestinationFile( File buildDir, String uri )
+    {
+        return new File( buildDir, uri );
     }
 }

Modified: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarPluginException.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarPluginException.java?rev=227088&r1=227087&r2=227088&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarPluginException.java (original)
+++ maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarPluginException.java Tue Aug  2 14:47:50 2005
@@ -19,9 +19,8 @@
 /**
  * The base exception of the EAR plugin.
  *
- * @author Stephane Nicoll <st...@gmail.com>
- * @author $Author: sni $ (last edit)
- * @version $Revision: 1.2 $
+ * @author <a href="stephane.nicoll@gmail.com">Stephane Nicoll</a>
+ * @version $Id$
  */
 public class EarPluginException
     extends Exception

Added: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EjbClientModule.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EjbClientModule.java?rev=227088&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EjbClientModule.java (added)
+++ maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EjbClientModule.java Tue Aug  2 14:47:50 2005
@@ -0,0 +1,44 @@
+package org.apache.maven.plugin.ear;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+
+/**
+ * The {@link EarModule} implementation for an Ejb-client module.
+ *
+ * @author <a href="stephane.nicoll@gmail.com">Stephane Nicoll</a>
+ * @version $Id$
+ */
+public class EjbClientModule
+    extends JavaModule
+{
+
+    public EjbClientModule()
+    {
+    }
+
+    public EjbClientModule( Artifact a )
+    {
+        super( a );
+    }
+
+    protected String getType()
+    {
+        return "ejb-client";
+    }
+}

Propchange: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EjbClientModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EjbClientModule.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EjbModule.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EjbModule.java?rev=227088&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EjbModule.java (added)
+++ maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EjbModule.java Tue Aug  2 14:47:50 2005
@@ -0,0 +1,55 @@
+package org.apache.maven.plugin.ear;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+/**
+ * The {@link EarModule} implementation for an EJB module.
+ *
+ * @author <a href="stephane.nicoll@gmail.com">Stephane Nicoll</a>
+ * @version $Id$
+ */
+public class EjbModule
+    extends AbstractEarModule
+{
+    protected static final String EJB_MODULE = "ejb";
+
+    public EjbModule()
+    {
+    }
+
+    public EjbModule( Artifact a )
+    {
+        super( a );
+    }
+
+    public void appendModule( XMLWriter writer, String version )
+    {
+        writer.startElement( MODULE_ELEMENT );
+        writer.startElement( EJB_MODULE );
+        writer.writeText( getUri() );
+        writer.endElement();
+        writer.endElement();
+    }
+
+    protected String getType()
+    {
+        return "ejb";
+    }
+}

Propchange: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EjbModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EjbModule.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java?rev=227088&r1=227087&r2=227088&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java (original)
+++ maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java Tue Aug  2 14:47:50 2005
@@ -91,6 +91,9 @@
     public void execute()
         throws MojoExecutionException
     {
+        // Initializes ear modules
+        super.execute();
+
         getLog().debug( " ======= GenerateApplicationXmlMojo settings =======" );
         getLog().debug( "generateApplicationXml[" + generateApplicationXml + "]" );
         getLog().debug( "version[" + version + "]" );

Added: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/JavaModule.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/JavaModule.java?rev=227088&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/JavaModule.java (added)
+++ maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/JavaModule.java Tue Aug  2 14:47:50 2005
@@ -0,0 +1,55 @@
+package org.apache.maven.plugin.ear;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+/**
+ * The {@link EarModule} implementation for a J2EE client module.
+ *
+ * @author <a href="stephane.nicoll@gmail.com">Stephane Nicoll</a>
+ * @version $Id$
+ */
+public class JavaModule
+    extends AbstractEarModule
+{
+    protected static final String JAVA_MODULE = "java";
+
+    public JavaModule()
+    {
+    }
+
+    public JavaModule( Artifact a )
+    {
+        super( a );
+    }
+
+    public void appendModule( XMLWriter writer, String version )
+    {
+        writer.startElement( MODULE_ELEMENT );
+        writer.startElement( JAVA_MODULE );
+        writer.writeText( getUri() );
+        writer.endElement();
+        writer.endElement();
+    }
+
+    protected String getType()
+    {
+        return "jar";
+    }
+}

Propchange: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/JavaModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/JavaModule.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/RarModule.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/RarModule.java?rev=227088&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/RarModule.java (added)
+++ maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/RarModule.java Tue Aug  2 14:47:50 2005
@@ -0,0 +1,55 @@
+package org.apache.maven.plugin.ear;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+/**
+ * The {@link EarModule} implementation for an J2EE connector module.
+ *
+ * @author <a href="stephane.nicoll@gmail.com">Stephane Nicoll</a>
+ * @version $Id$
+ */
+public class RarModule
+    extends AbstractEarModule
+{
+    protected static final String RAR_MODULE = "connector";
+
+    public RarModule()
+    {
+    }
+
+    public RarModule( Artifact a )
+    {
+        super( a );
+    }
+
+    public void appendModule( XMLWriter writer, String version )
+    {
+        writer.startElement( MODULE_ELEMENT );
+        writer.startElement( RAR_MODULE );
+        writer.writeText( getUri() );
+        writer.endElement();
+        writer.endElement();
+    }
+
+    protected String getType()
+    {
+        return "rar";
+    }
+}

Propchange: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/RarModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/RarModule.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/WebModule.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/WebModule.java?rev=227088&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/WebModule.java (added)
+++ maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/WebModule.java Tue Aug  2 14:47:50 2005
@@ -0,0 +1,111 @@
+package org.apache.maven.plugin.ear;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+import java.util.Set;
+
+/**
+ * The {@link EarModule} implementation for a Web application module.
+ *
+ * @author <a href="stephane.nicoll@gmail.com">Stephane Nicoll</a>
+ * @version $Id$
+ */
+public class WebModule
+    extends AbstractEarModule
+{
+    protected static final String WEB_MODULE = "web";
+
+    protected static final String WEB_URI_FIELD = "web-uri";
+
+    protected static final String CONTEXT_ROOT_FIELD = "context-root";
+
+    private String contextRoot;
+
+    public WebModule()
+    {
+    }
+
+    public WebModule( Artifact a )
+    {
+        super( a );
+        this.contextRoot = getDefaultContextRoot( a );
+    }
+
+    public void appendModule( XMLWriter writer, String version )
+    {
+        writer.startElement( MODULE_ELEMENT );
+        writer.startElement( WEB_MODULE );
+        writer.startElement( WEB_URI_FIELD );
+        writer.writeText( getUri() );
+        writer.endElement(); // web-uri
+        writer.startElement( CONTEXT_ROOT_FIELD );
+        writer.writeText( getContextRoot() );
+        writer.endElement(); // context-root
+        writer.endElement(); // web
+        writer.endElement(); // module
+    }
+
+    public void resolveArtifact( Set artifacts )
+        throws EarPluginException
+    {
+        // Let's resolve the artifact
+        super.resolveArtifact( artifacts );
+
+        // Context root has not been customized - using default
+        if ( contextRoot == null )
+        {
+            contextRoot = getDefaultContextRoot( getArtifact() );
+        }
+    }
+
+    /**
+     * Returns the context root to use for the web module.
+     * <p/>
+     * Note that this might return <tt>null</tt> till the
+     * artifact has been resolved.
+     *
+     * @return the context root
+     */
+    public String getContextRoot()
+    {
+        return contextRoot;
+    }
+
+    protected String getType()
+    {
+        return "war";
+    }
+
+    /**
+     * Generates a default context root for the given artifact, based
+     * on the <tt>artifactId</tt>.
+     *
+     * @param a the artifact
+     * @return a context root for the artifact
+     */
+    private static String getDefaultContextRoot( Artifact a )
+    {
+        if ( a == null )
+        {
+            throw new NullPointerException( "Artifact could not be null." );
+        }
+        return "/" + a.getArtifactId();
+    }
+}

Propchange: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/WebModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/WebModule.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/components/trunk/maven-plugins/maven-ear-plugin/src/site/apt/configuration-examples.apt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-ear-plugin/src/site/apt/configuration-examples.apt?rev=227088&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-ear-plugin/src/site/apt/configuration-examples.apt (added)
+++ maven/components/trunk/maven-plugins/maven-ear-plugin/src/site/apt/configuration-examples.apt Tue Aug  2 14:47:50 2005
@@ -0,0 +1,126 @@
+ ---
+ Ear Plugin: configuration examples
+ ---
+ Stéphane Nicoll
+ ---
+ 31-Jul-2005
+ ---
+
+Introduction
+
+  The Ear plugin allows to generate automatically the descriptor deployment, e.g.
+  application.xml. This generation is already customized by basic configuration
+  items, see <<TODO: ADD A LINK HERE>>.
+
+  Ear modules might be further customized as follows:
+
+   * contextRoot: the custom context root for a web application
+
+   * bundleDir: the directory in the EAR structure where the artifact will be stored
+
+   * bundleFileName: the name of the artifact in the EAR structure
+
+   * uri: the complete path in the EAR structure for the artifact
+
+Customizing the context root
+
+  The sample below shows how to customize the context root of an artifact to be placed
+  in the EAR file:
+
++--------
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-ear-plugin</artifactId>
+        <configuration>
+           [...]
+           <modules>
+             <webModule>
+               <groupId>artifactGroupId</groupId>
+               <artifactId>artifactId</artifactId>
+               <contextRoot>/custom-context-root</contextRoot>
+             </webModule>
+          </modules>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
++---------
+
+Customizing a module location
+
+  The sample below shows how to place a library in the APP-INF/lib directory of the EAR file:
+
++--------
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-ear-plugin</artifactId>
+        <configuration>
+           [...]
+           <modules>
+             <javaModule>
+               <groupId>artifactGroupId</groupId>
+               <artifactId>artifactId</artifactId>
+               <bundleDir>APP-INF/lib</bundleDir>
+             </javaModule>
+          </modules>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
++---------
+
+Customizing a module file name
+
+  The sample below shows how to rename a module being placed in the EAR file:
+
++--------
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-ear-plugin</artifactId>
+        <configuration>
+           [...]
+           <modules>
+             <javaModule>
+               <groupId>artifactGroupId</groupId>
+               <artifactId>artifactId</artifactId>
+               <bundleFileName>anotherName-1.2.3.jar</bundleFileName>
+             </javaModule>
+          </modules>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
++---------
+
+Customizing a module uri
+
+  This is actually a combination of customizing the module's location and file
+  name. The sample below shows how to specify the URI of a module being placed
+  in the EAR file:
+
++--------
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-ear-plugin</artifactId>
+        <configuration>
+           [...]
+           <modules>
+             <javaModule>
+               <groupId>artifactGroupId</groupId>
+               <artifactId>artifactId</artifactId>
+               <uri>APP-INF/lib/anotherName-1.2.3.jar</uri>
+             </javaModule>
+          </modules>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
++---------

Propchange: maven/components/trunk/maven-plugins/maven-ear-plugin/src/site/apt/configuration-examples.apt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-plugins/maven-ear-plugin/src/site/apt/configuration-examples.apt
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/components/trunk/maven-plugins/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/pom.xml?rev=227088&r1=227087&r2=227088&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/pom.xml (original)
+++ maven/components/trunk/maven-plugins/pom.xml Tue Aug  2 14:47:50 2005
@@ -111,7 +111,7 @@
       <dependency>
         <groupId>plexus</groupId>
         <artifactId>plexus-container-default</artifactId>
-        <version>1.0-alpha-4</version>
+        <version>1.0-alpha-6-SNAPSHOT</version>
       </dependency>
       <dependency>
         <groupId>plexus</groupId>

Modified: maven/components/trunk/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/pom.xml?rev=227088&r1=227087&r2=227088&view=diff
==============================================================================
--- maven/components/trunk/pom.xml (original)
+++ maven/components/trunk/pom.xml Tue Aug  2 14:47:50 2005
@@ -152,7 +152,7 @@
       <dependency>
         <groupId>plexus</groupId>
         <artifactId>plexus-container-default</artifactId>
-        <version>1.0-alpha-4</version>
+        <version>1.0-alpha-6-SNAPSHOT</version>
       </dependency>
       <dependency>
         <groupId>plexus</groupId>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org