You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by br...@apache.org on 2005/05/21 17:09:24 UTC

svn commit: r171221 - in /maven/components/trunk/sandbox/maven-ear-plugin: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/maven/ src/main/java/org/apache/maven/plugin/ src/main/java/org/apache/maven/plugin/ear/ src/main/java/org/apache/maven/plugin/ear/module/ src/main/resources/ src/main/resources/org/ src/main/resources/org/apache/ src/main/resources/org/apache/maven/ src/main/resources/org/apache/maven/plugin/ src/main/resources/org/apache/maven/plugin/ear/ src/test/ src/test/java/ src/test/resources/

Author: brett
Date: Sat May 21 08:09:22 2005
New Revision: 171221

URL: http://svn.apache.org/viewcvs?rev=171221&view=rev
Log:
PR: MNG-148
Submitted by: Stephane Nicoll
Reviewed by:  Brett Porter, Emmanuel Venisse
Implementation of an EAR plugin

Added:
    maven/components/trunk/sandbox/maven-ear-plugin/
    maven/components/trunk/sandbox/maven-ear-plugin/pom.xml   (with props)
    maven/components/trunk/sandbox/maven-ear-plugin/src/
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java   (with props)
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java   (with props)
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java   (with props)
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarPluginException.java   (with props)
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java   (with props)
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/AbstractEarModule.java   (with props)
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/EarModule.java   (with props)
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/EarModuleFactory.java   (with props)
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/EjbModule.java   (with props)
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/JavaModule.java   (with props)
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/RarModule.java   (with props)
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/WebModule.java   (with props)
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/resources/
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/resources/org/
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/resources/org/apache/
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/resources/org/apache/maven/
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/resources/org/apache/maven/plugin/
    maven/components/trunk/sandbox/maven-ear-plugin/src/main/resources/org/apache/maven/plugin/ear/
    maven/components/trunk/sandbox/maven-ear-plugin/src/test/
    maven/components/trunk/sandbox/maven-ear-plugin/src/test/java/
    maven/components/trunk/sandbox/maven-ear-plugin/src/test/resources/

Added: maven/components/trunk/sandbox/maven-ear-plugin/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/maven-ear-plugin/pom.xml?rev=171221&view=auto
==============================================================================
--- maven/components/trunk/sandbox/maven-ear-plugin/pom.xml (added)
+++ maven/components/trunk/sandbox/maven-ear-plugin/pom.xml Sat May 21 08:09:22 2005
@@ -0,0 +1,29 @@
+<model>
+  <parent>
+    <artifactId>maven-plugin-parent</artifactId>
+    <groupId>org.apache.maven.plugins</groupId>
+    <version>2.0-alpha-2</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>maven-ear-plugin</artifactId>
+  <packaging>maven-plugin</packaging>
+  <name>Maven Ear plugin</name>
+  <version>2.0-alpha-1-SNAPSHOT</version>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-archiver</artifactId>
+      <version>2.0-alpha-2</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-project</artifactId>
+      <version>2.0-alpha-2</version>
+    </dependency>
+    <dependency>
+      <groupId>plexus</groupId>
+      <artifactId>plexus-utils</artifactId>
+      <version>1.0-alpha-3</version>
+    </dependency>
+  </dependencies>
+</model>

Propchange: maven/components/trunk/sandbox/maven-ear-plugin/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/sandbox/maven-ear-plugin/pom.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java?rev=171221&view=auto
==============================================================================
--- maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java (added)
+++ maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java Sat May 21 08:09:22 2005
@@ -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 <a href="stephane.nicoll@gmail.com">Stephane Nicoll</a>
+ * @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;
+    }
+}

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

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

Added: maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java?rev=171221&view=auto
==============================================================================
--- maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java (added)
+++ maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java Sat May 21 08:09:22 2005
@@ -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 <tt>XmlWriter</tt> based implementation used to generate an
+ * <tt>application.xml</tt> file
+ *
+ * @author Stephane Nicoll <st...@gmail.com>
+ * @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
+        }
+    }
+}

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

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

Added: maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java?rev=171221&view=auto
==============================================================================
--- maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java (added)
+++ maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java Sat May 21 08:09:22 2005
@@ -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 <a href="stephane.nicoll@gmail.com">Stephane Nicoll</a>
+ * @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

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

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

Added: maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarPluginException.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarPluginException.java?rev=171221&view=auto
==============================================================================
--- maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarPluginException.java (added)
+++ maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarPluginException.java Sat May 21 08:09:22 2005
@@ -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 <st...@gmail.com>
+ * @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 );
+    }
+}

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

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

Added: maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java?rev=171221&view=auto
==============================================================================
--- maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java (added)
+++ maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java Sat May 21 08:09:22 2005
@@ -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 <tt>Mojo</tt> used to build the <tt>application.xml</tt> file
+ * if necessary.
+ *
+ * @author <a href="stephane.nicoll@gmail.com">Stephane Nicoll</a>
+ * @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 <tt>application.xml</tt>
+     * file is autogenerated.
+     *
+     * @parameter expression="${project.artifactId}"
+     */
+    private String displayName = null;
+
+    /**
+     * The description in generated <tt>application.xml</tt>.
+     *
+     * @parameter
+     */
+    private String description = null;
+
+    /**
+     * Character encoding for the auto-generated <tt>application.xml</tt> file.
+     *
+     * @parameter
+     * @TODO handle this field
+     */
+    private String encoding = UTF_8;
+
+    /**
+     * Directory where the <tt>application.xml</tt> 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() + "]" );
+        }
+    }
+}

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

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

Added: maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/AbstractEarModule.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/AbstractEarModule.java?rev=171221&view=auto
==============================================================================
--- maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/AbstractEarModule.java (added)
+++ maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/AbstractEarModule.java Sat May 21 08:09:22 2005
@@ -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 <st...@gmail.com>
+ * @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;
+    }
+}

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

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

Added: maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/EarModule.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/EarModule.java?rev=171221&view=auto
==============================================================================
--- maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/EarModule.java (added)
+++ maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/EarModule.java Sat May 21 08:09:22 2005
@@ -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 <st...@gmail.com>
+ * @author $Author: sni $ (last edit)
+ * @version $Revision: 1.2 $
+ */
+public interface EarModule
+{
+
+    /**
+     * Returns the <tt>Artifact</tt> representing this module.
+     *
+     * @return the <tt>Artifact</tt>
+     */
+    public Artifact getArtifact();
+
+    /**
+     * Returns the <tt>URI</tt> fo the Ear 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 );
+
+}

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

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

Added: maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/EarModuleFactory.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/EarModuleFactory.java?rev=171221&view=auto
==============================================================================
--- maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/EarModuleFactory.java (added)
+++ maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/EarModuleFactory.java Sat May 21 08:09:22 2005
@@ -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 <tt>Artifact</tt>.
+ *
+ * @author Stephane Nicoll <st...@gmail.com>
+ * @author $Author: sni $ (last edit)
+ * @version $Revision: 1.2 $
+ */
+public final class EarModuleFactory
+{
+
+    /**
+     * Creates a new {@link EarModule} based on the specified <tt>Artifact</tt>.
+     *
+     * @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 <tt>Artifact</tt>.
+     *
+     * @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 <tt>Artifact</tt>.
+     *
+     * @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() + "]" );
+        }
+    }
+}

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

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

Added: maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/EjbModule.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/EjbModule.java?rev=171221&view=auto
==============================================================================
--- maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/EjbModule.java (added)
+++ maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/EjbModule.java Sat May 21 08:09:22 2005
@@ -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 <st...@gmail.com>
+ * @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();
+    }
+}

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

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

Added: maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/JavaModule.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/JavaModule.java?rev=171221&view=auto
==============================================================================
--- maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/JavaModule.java (added)
+++ maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/JavaModule.java Sat May 21 08:09:22 2005
@@ -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 <st...@gmail.com>
+ * @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();
+    }
+}

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

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

Added: maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/RarModule.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/RarModule.java?rev=171221&view=auto
==============================================================================
--- maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/RarModule.java (added)
+++ maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/RarModule.java Sat May 21 08:09:22 2005
@@ -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 <st...@gmail.com>
+ * @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();
+    }
+}

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

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

Added: maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/WebModule.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/WebModule.java?rev=171221&view=auto
==============================================================================
--- maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/WebModule.java (added)
+++ maven/components/trunk/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/module/WebModule.java Sat May 21 08:09:22 2005
@@ -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 <st...@gmail.com>
+ * @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;
+    }
+}

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

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



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