diff --git a/sandbox/maven-ear-plugin/pom.xml b/sandbox/maven-ear-plugin/pom.xml
new file mode 100644
index 0000000000..c73ccc938f
--- /dev/null
+++ b/sandbox/maven-ear-plugin/pom.xml
@@ -0,0 +1,29 @@
+
+
+ maven-plugin-parent
+ org.apache.maven.plugins
+ 2.0-alpha-2
+
+ 4.0.0
+ maven-ear-plugin
+ maven-plugin
+ Maven Ear plugin
+ 2.0-alpha-1-SNAPSHOT
+
+
+ org.apache.maven
+ maven-archiver
+ 2.0-alpha-2
+
+
+ org.apache.maven
+ maven-project
+ 2.0-alpha-2
+
+
+ plexus
+ plexus-utils
+ 1.0-alpha-3
+
+
+
diff --git a/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java
new file mode 100644
index 0000000000..7b36e06c27
--- /dev/null
+++ b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java
@@ -0,0 +1,103 @@
+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.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.ear.module.EarModule;
+import org.apache.maven.plugin.ear.module.EarModuleFactory;
+import org.apache.maven.project.MavenProject;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * A base class for EAR-processing related tasks.
+ *
+ * @author Stephane Nicoll
+ * @version $Id $
+ */
+public abstract class AbstractEarMojo
+ extends AbstractMojo
+{
+
+ public static final String APPLICATION_XML_URI = "META-INF/application.xml";
+
+ /**
+ * The maven project.
+ *
+ * @parameter expression="${project}"
+ * @required
+ * @readonly
+ * @description "the maven project to use"
+ */
+ private MavenProject project;
+
+ /**
+ * Directory that resources are copied to during the build.
+ *
+ * @parameter expression="${project.build.directory}/${project.build.finalName}"
+ * @required
+ */
+ private String earDirectory;
+
+ private List modules;
+
+ private File buildDir;
+
+ protected List getModules()
+ {
+ if ( modules == null )
+ {
+ // Gather modules and copy them
+ modules = new ArrayList();
+ Set artifacts = project.getArtifacts();
+ for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
+ {
+ Artifact artifact = (Artifact) iter.next();
+ if ( !Artifact.SCOPE_TEST.equals( artifact.getScope() ) )
+ {
+ EarModule module = EarModuleFactory.newEarModule( artifact );
+ modules.add( module );
+ }
+ }
+ }
+ return modules;
+ }
+
+ protected File getBuildDir()
+ {
+ if ( buildDir == null )
+ {
+ buildDir = new File( earDirectory );
+ }
+ return buildDir;
+ }
+
+ protected MavenProject getProject()
+ {
+ return project;
+ }
+
+ protected String getEarDirectory()
+ {
+ return earDirectory;
+ }
+}
diff --git a/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java
new file mode 100644
index 0000000000..8f1e05d3bb
--- /dev/null
+++ b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java
@@ -0,0 +1,108 @@
+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;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Iterator;
+import java.util.List;
+
+/*
+ * 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.
+ */
+
+/**
+ * An XmlWriter based implementation used to generate an
+ * application.xml file
+ *
+ * @author Stephane Nicoll
+ * @author $Author: sni $ (last edit)
+ * @version $Id$
+ */
+public final class ApplicationXmlWriter
+{
+
+ private final String version;
+
+ public ApplicationXmlWriter( String version )
+ {
+ this.version = version;
+ }
+
+ public void write( File destinationFile, List earModules, String displayName, String description )
+ throws EarPluginException
+ {
+ FileWriter w;
+ try
+ {
+ w = new FileWriter( destinationFile );
+ }
+ catch ( IOException ex )
+ {
+ throw new EarPluginException( "Exception while opening file[" + destinationFile.getAbsolutePath() + "]",
+ ex );
+ }
+
+ // @todo Add DTD or XSchema reference based on version attribute
+
+ XMLWriter writer = new PrettyPrintXMLWriter( w );
+ writer.startElement( "application" );
+
+ if ( displayName != null )
+ {
+ writer.startElement( "display-name" );
+ writer.writeText( displayName );
+ writer.endElement();
+ }
+
+ if ( description != null )
+ {
+ writer.startElement( "description" );
+ writer.writeText( description );
+ writer.endElement();
+ }
+
+ Iterator i = earModules.iterator();
+ while ( i.hasNext() )
+ {
+ EarModule module = (EarModule) i.next();
+ module.appendModule( writer, version );
+ }
+ writer.endElement();
+
+ close( w );
+ }
+
+ private void close( Writer closeable )
+ {
+ if ( closeable == null )
+ {
+ return;
+ }
+
+ try
+ {
+ closeable.close();
+ }
+ catch ( Exception e )
+ {
+ // TODO: warn
+ }
+ }
+}
diff --git a/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java
new file mode 100644
index 0000000000..85e74e09a5
--- /dev/null
+++ b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java
@@ -0,0 +1,164 @@
+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.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;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * The Ear Mojo.
+ *
+ * @author Stephane Nicoll
+ * @version $Id $
+ * @goal ear
+ * @phase package
+ * @requiresDependencyResolution test
+ * @description builds an ear
+ */
+public class EarMojo
+ extends AbstractEarMojo
+{
+ /**
+ * Single directory for extra files to include in the EAR.
+ *
+ * @parameter expression="${basedir}/src/application"
+ * @required
+ */
+ private String earSourceDirectory;
+
+ /**
+ * The location of the manifest file to be used within the ear file.
+ *
+ * @parameter expression="${basedir}/src/application/META-INF/MANIFEST.MF"
+ * @TODO handle this field
+ */
+ private String manifestLocation;
+
+ /**
+ * The location of the application.xml file to be used within the ear file.
+ *
+ * @parameter expression="${basedir}/src/application/META-INF/application.xml"
+ */
+ private String applicationXmlLocation;
+
+ /**
+ * The directory for the generated EAR.
+ *
+ * @parameter expression="${project.build.directory}"
+ * @required
+ */
+ private String outputDirectory;
+
+ /**
+ * The name of the EAR file to generate.
+ *
+ * @parameter alias="earName" expression="${project.build.finalName}"
+ * @required
+ * @readonly
+ */
+ private String finalName;
+
+ /**
+ * The list of excluded dependencies with format groupId:artifactId[:type].
+ *
+ * @parameter
+ * @TODO handle this field
+ */
+ private List excludedDependencies = new ArrayList();
+
+ /**
+ * The maven archiver to use.
+ *
+ * @parameter
+ */
+ private MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
+
+
+ public void execute()
+ throws MojoExecutionException
+ {
+ getLog().debug( " ======= EarMojo settings =======" );
+ getLog().debug( "earSourceDirectory[" + earSourceDirectory + "]" );
+ getLog().debug( "manifestLocation[" + manifestLocation + "]" );
+ getLog().debug( "applicationXmlLocation[" + applicationXmlLocation + "]" );
+ getLog().debug( "earDirectory[" + getEarDirectory() + "]" );
+ getLog().debug( "outputDirectory[" + outputDirectory + "]" );
+ getLog().debug( "finalName[" + finalName + "]" );
+ getLog().debug( "excludedDependencies[" + excludedDependencies + "]" );
+
+ // Copy modules
+ try
+ {
+ 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() );
+ }
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "Error copying EAR modules", e );
+ }
+
+ // Copy source files
+ try
+ {
+ File earSourceDir = new File( earSourceDirectory );
+ if ( earSourceDir.exists() )
+ {
+ getLog().info( "Copy ear resources to " + getBuildDir().getAbsolutePath() );
+ FileUtils.copyDirectoryStructure( earSourceDir, getBuildDir() );
+ }
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "Error copying EAR resources", e );
+ }
+
+ // Check if deployment descriptor is there
+ File ddFile = new File( getBuildDir(), APPLICATION_XML_URI );
+ if ( !ddFile.exists() )
+ {
+ throw new MojoExecutionException( "Deployment descriptor: " + ddFile.getAbsolutePath() + " does not exist." );
+ }
+
+ try
+ {
+ File earFile = new File( outputDirectory, finalName + ".ear" );
+ MavenArchiver archiver = new MavenArchiver();
+ archiver.setOutputFile( earFile );
+
+ archiver.getArchiver().addDirectory( getBuildDir() );
+ archiver.createArchive( getProject(), archive );
+ }
+ catch ( Exception e )
+ {
+ throw new MojoExecutionException( "Error assembling EAR", e );
+ }
+ }
+}
\ No newline at end of file
diff --git a/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarPluginException.java b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarPluginException.java
new file mode 100644
index 0000000000..a8e935fc9c
--- /dev/null
+++ b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarPluginException.java
@@ -0,0 +1,48 @@
+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.
+ */
+
+/**
+ * The base exception of the EAR plugin.
+ *
+ * @author Stephane Nicoll
+ * @author $Author: sni $ (last edit)
+ * @version $Revision: 1.2 $
+ */
+public class EarPluginException
+ extends Exception
+{
+
+ public EarPluginException()
+ {
+ }
+
+ public EarPluginException( String message )
+ {
+ super( message );
+ }
+
+ public EarPluginException( Throwable cause )
+ {
+ super( cause );
+ }
+
+ public EarPluginException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+}
diff --git a/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java
new file mode 100644
index 0000000000..7e701180f8
--- /dev/null
+++ b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java
@@ -0,0 +1,137 @@
+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.plugin.MojoExecutionException;
+import org.codehaus.plexus.util.FileUtils;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * A Mojo used to build the application.xml file
+ * if necessary.
+ *
+ * @author Stephane Nicoll
+ * @version $Id $
+ * @goal generate-application-xml
+ * @phase process-resources
+ * @requiresDependencyResolution test
+ * @description generates the application.xml deployment descriptor
+ */
+public class GenerateApplicationXmlMojo
+ extends AbstractEarMojo
+{
+
+ public static final String VERSION_1_3 = "1.3";
+
+ public static final String VERSION_1_4 = "1.4";
+
+ public static final String UTF_8 = "UTF-8";
+
+ /**
+ * Inserts the doctype header depending on the specified version.
+ *
+ * @parameter expression="${maven.ear.appxml.version}"
+ */
+ private String version = VERSION_1_3;
+
+ /**
+ * Display name of the application to be used when application.xml
+ * file is autogenerated.
+ *
+ * @parameter expression="${project.artifactId}"
+ */
+ private String displayName = null;
+
+ /**
+ * The description in generated application.xml.
+ *
+ * @parameter
+ */
+ private String description = null;
+
+ /**
+ * Character encoding for the auto-generated application.xml file.
+ *
+ * @parameter
+ * @TODO handle this field
+ */
+ private String encoding = UTF_8;
+
+ /**
+ * Directory where the application.xml file will be auto-generated.
+ *
+ * @parameter expression="${project.build.directory}"
+ */
+ private String generatedDescriptorLocation;
+
+ public void execute()
+ throws MojoExecutionException
+ {
+ getLog().debug( " ======= GenerateApplicationXmlMojo settings =======" );
+ getLog().debug( "version[" + version + "]" );
+ getLog().debug( "displayName[" + displayName + "]" );
+ getLog().debug( "description[" + description + "]" );
+ getLog().debug( "encoding[" + encoding + "]" );
+ getLog().debug( "generatedDescriptorLocation[" + generatedDescriptorLocation + "]" );
+
+ // Generate deployment descriptor
+ try
+ {
+ getLog().info( "Generating application.xml" );
+ generateDeploymentDescriptor();
+ FileUtils.copyFileToDirectory( new File( generatedDescriptorLocation, "application.xml" ),
+ new File( getBuildDir(), "META-INF" ) );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "Failed to generate application.xml", e );
+ }
+ }
+
+ /**
+ * Generates the deployment descriptor if necessary.
+ *
+ * @throws IOException
+ */
+ protected void generateDeploymentDescriptor()
+ throws IOException
+ {
+ File outputDir = new File( generatedDescriptorLocation );
+ if ( !outputDir.exists() )
+ {
+ outputDir.mkdir();
+ }
+
+ File descriptor = new File( outputDir, "application.xml" );
+ if ( !descriptor.exists() )
+ {
+ descriptor.createNewFile();
+ }
+
+ ApplicationXmlWriter writer = new ApplicationXmlWriter( version );
+ try
+ {
+ writer.write( descriptor, getModules(), displayName, description );
+ }
+ catch ( EarPluginException e )
+ {
+ throw new IOException( "Unable to generate application.xml[" + e.getMessage() + "]" );
+ }
+ }
+}
diff --git a/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/AbstractEarModule.java b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/AbstractEarModule.java
new file mode 100644
index 0000000000..1456ebf05a
--- /dev/null
+++ b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/AbstractEarModule.java
@@ -0,0 +1,53 @@
+package org.apache.maven.plugin.ear.module;
+
+/*
+ * 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;
+
+/**
+ * A base implementation of an {@link EarModule}.
+ *
+ * @author Stephane Nicoll
+ * @author $Author: sni $ (last edit)
+ * @version $Revision: 1.2 $
+ */
+public abstract class AbstractEarModule
+ implements EarModule
+{
+
+ protected static final String MODULE_ELEMENT = "module";
+
+ private final String uri;
+
+ private final Artifact artifact;
+
+ AbstractEarModule( String uri, Artifact a )
+ {
+ this.uri = uri;
+ this.artifact = a;
+ }
+
+ public Artifact getArtifact()
+ {
+ return artifact;
+ }
+
+ public String getUri()
+ {
+ return uri;
+ }
+}
diff --git a/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/EarModule.java b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/EarModule.java
new file mode 100644
index 0000000000..06ac2d4d3e
--- /dev/null
+++ b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/EarModule.java
@@ -0,0 +1,54 @@
+package org.apache.maven.plugin.ear.module;
+
+/*
+ * 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 ear module interface.
+ *
+ * @author Stephane Nicoll
+ * @author $Author: sni $ (last edit)
+ * @version $Revision: 1.2 $
+ */
+public interface EarModule
+{
+
+ /**
+ * Returns the Artifact representing this module.
+ *
+ * @return the Artifact
+ */
+ public Artifact getArtifact();
+
+ /**
+ * Returns the URI fo the Ear module.
+ *
+ * @return the URI
+ */
+ public String getUri();
+
+ /**
+ * Appends the XML representation of this module.
+ *
+ * @param writer the writer to use
+ * @param version the version of the application.xml file
+ */
+ public void appendModule( XMLWriter writer, String version );
+
+}
diff --git a/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/EarModuleFactory.java b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/EarModuleFactory.java
new file mode 100644
index 0000000000..bc65e632fa
--- /dev/null
+++ b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/EarModuleFactory.java
@@ -0,0 +1,92 @@
+package org.apache.maven.plugin.ear.module;
+
+/*
+ * 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 Artifact.
+ *
+ * @author Stephane Nicoll
+ * @author $Author: sni $ (last edit)
+ * @version $Revision: 1.2 $
+ */
+public final class EarModuleFactory
+{
+
+ /**
+ * Creates a new {@link EarModule} based on the specified 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( getUri( artifact ), artifact );
+ }
+ else if ( "ejb".equals( artifact.getType() ) )
+ {
+ return new EjbModule( getUri( artifact ), artifact );
+ }
+ else if ( "rar".equals( artifact.getType() ) )
+ {
+ return new RarModule( getUri( artifact ), artifact );
+ }
+ else if ( "war".equals( artifact.getType() ) )
+ {
+ return new WebModule( getUri( artifact ), artifact, getContextRoot( artifact ) );
+ }
+ else
+ {
+ throw new IllegalStateException( "Could not handle artifact type[" + artifact.getType() + "]" );
+ }
+ }
+
+ /**
+ * Returns the URI for the specifed Artifact.
+ *
+ * @param artifact the artifact
+ * @return the URI of this artifact in the EAR file
+ * @TODO handle custom URI - for now it returns the file name
+ */
+ private static String getUri( Artifact artifact )
+ {
+ return artifact.getFile().getName();
+ }
+
+ /**
+ * Returns the context root for the specifed war Artifact.
+ *
+ * @param artifact the artifact
+ * @return the context root of the artifact
+ * @TODO handle custom context root - for now it returns the artifact Id
+ */
+ private static String getContextRoot( Artifact artifact )
+ {
+ if ( artifact.getType().equals( "war" ) )
+ {
+ return "/" + artifact.getArtifactId();
+ }
+ else
+ {
+ throw new IllegalStateException(
+ "Could not get context-root for an artifact with type[" + artifact.getType() + "]" );
+ }
+ }
+}
diff --git a/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/EjbModule.java b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/EjbModule.java
new file mode 100644
index 0000000000..10e229e05c
--- /dev/null
+++ b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/EjbModule.java
@@ -0,0 +1,47 @@
+package org.apache.maven.plugin.ear.module;
+
+/*
+ * 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 Stephane Nicoll
+ * @author $Author: sni $ (last edit)
+ * @version $Revision: 1.2 $
+ */
+public class EjbModule
+ extends AbstractEarModule
+{
+ protected static final String EJB_MODULE = "ejb";
+
+ EjbModule( String uri, Artifact a )
+ {
+ super( uri, a );
+ }
+
+ public void appendModule( XMLWriter writer, String version )
+ {
+ writer.startElement( MODULE_ELEMENT );
+ writer.startElement( EJB_MODULE );
+ writer.writeText( getUri() );
+ writer.endElement();
+ writer.endElement();
+ }
+}
diff --git a/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/JavaModule.java b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/JavaModule.java
new file mode 100644
index 0000000000..5e7fc6a43d
--- /dev/null
+++ b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/JavaModule.java
@@ -0,0 +1,47 @@
+package org.apache.maven.plugin.ear.module;
+
+/*
+ * 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 Stephane Nicoll
+ * @author $Author: sni $ (last edit)
+ * @version $Revision: 1.2 $
+ */
+public class JavaModule
+ extends AbstractEarModule
+{
+ protected static final String JAVA_MODULE = "java";
+
+ JavaModule( String uri, Artifact a )
+ {
+ super( uri, a );
+ }
+
+ public void appendModule( XMLWriter writer, String version )
+ {
+ writer.startElement( MODULE_ELEMENT );
+ writer.startElement( JAVA_MODULE );
+ writer.writeText( getUri() );
+ writer.endElement();
+ writer.endElement();
+ }
+}
diff --git a/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/RarModule.java b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/RarModule.java
new file mode 100644
index 0000000000..7690b0d3d8
--- /dev/null
+++ b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/RarModule.java
@@ -0,0 +1,47 @@
+package org.apache.maven.plugin.ear.module;
+
+/*
+ * 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 Stephane Nicoll
+ * @author $Author: sni $ (last edit)
+ * @version $Revision: 1.2 $
+ */
+public class RarModule
+ extends AbstractEarModule
+{
+ protected static final String RAR_MODULE = "connector";
+
+ RarModule( String uri, Artifact a )
+ {
+ super( uri, a );
+ }
+
+ public void appendModule( XMLWriter writer, String version )
+ {
+ writer.startElement( MODULE_ELEMENT );
+ writer.startElement( RAR_MODULE );
+ writer.writeText( getUri() );
+ writer.endElement();
+ writer.endElement();
+ }
+}
diff --git a/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/WebModule.java b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/WebModule.java
new file mode 100644
index 0000000000..820324adf6
--- /dev/null
+++ b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/WebModule.java
@@ -0,0 +1,64 @@
+package org.apache.maven.plugin.ear.module;
+
+/*
+ * 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 Web application module.
+ *
+ * @author Stephane Nicoll
+ * @author $Author: sni $ (last edit)
+ * @version $Revision: 1.2 $
+ */
+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 final String contextRoot;
+
+ WebModule( String uri, Artifact a, String contextRoot )
+ {
+ super( uri, a );
+ this.contextRoot = contextRoot;
+ }
+
+ 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 String getContextRoot()
+ {
+ return contextRoot;
+ }
+}