You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sn...@apache.org on 2005/11/09 20:40:33 UTC

svn commit: r332123 - in /maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear: AbstractEarMojo.java EarMojo.java

Author: snicoll
Date: Wed Nov  9 11:40:29 2005
New Revision: 332123

URL: http://svn.apache.org/viewcvs?rev=332123&view=rev
Log:
- MNG-1461: custom application.xml can now be specified properly. Overrides any other file found in the source directories
- MNG-1444: added directory scanner to exclude common directories (subversion, CVS files, etc). Added earSourceIncludes and earSourceExcludes properties to specify the list of tokens to include and exclude respectively.

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/EarMojo.java

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=332123&r1=332122&r2=332123&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 Wed Nov  9 11:40:29 2005
@@ -17,6 +17,7 @@
  */
 
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
@@ -27,7 +28,6 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
-import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
 
 /**
  * A base class for EAR-processing related tasks.
@@ -40,6 +40,8 @@
 {
 
     public static final String APPLICATION_XML_URI = "META-INF/application.xml";
+
+    public static final String META_INF = "META-INF";
 
     /**
      * The maven project.

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=332123&r1=332122&r2=332123&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 Wed Nov  9 11:40:29 2005
@@ -21,11 +21,14 @@
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.codehaus.plexus.archiver.jar.JarArchiver;
+import org.codehaus.plexus.util.DirectoryScanner;
 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;
 
 /**
  * Builds J2EE Enteprise Archive (EAR) files.
@@ -49,6 +52,23 @@
     private File earSourceDirectory;
 
     /**
+     * The comma separated list of tokens to include in the EAR.
+     * Default is '**'.
+     *
+     * @parameter alias="includes"
+     */
+    private String earSourceIncludes = "**";
+
+    /**
+     * The comma separated list of tokens to exclude from the EAR.
+     *
+     * @parameter alias="excludes"
+     */
+    private String earSourceExcludes;
+
+    private static final String[] EMPTY_STRING_ARRAY = {};
+
+    /**
      * The location of the manifest file to be used within the ear file.
      *
      * @parameter expression="${basedir}/src/main/application/META-INF/MANIFEST.MF"
@@ -56,11 +76,12 @@
     private File manifestFile;
 
     /**
-     * The location of the application.xml file to be used within the ear file.
+     * The location of a custom application.xml file to be used
+     * within the ear file.
      *
-     * @parameter expression="${basedir}/src/main/application/META-INF/application.xml"
+     * @parameter
      */
-    private File applicationXmlFile;
+    private String applicationXml;
 
     /**
      * The directory for the generated EAR.
@@ -112,7 +133,7 @@
         getLog().debug( " ======= EarMojo settings =======" );
         getLog().debug( "earSourceDirectory[" + earSourceDirectory + "]" );
         getLog().debug( "manifestLocation[" + manifestFile + "]" );
-        getLog().debug( "applicationXmlLocation[" + applicationXmlFile + "]" );
+        getLog().debug( "applicationXml[" + getApplicationXml() + "]" );
         getLog().debug( "workDirectory[" + getWorkDirectory() + "]" );
         getLog().debug( "outputDirectory[" + outputDirectory + "]" );
         getLog().debug( "finalName[" + finalName + "]" );
@@ -149,8 +170,22 @@
             if ( earSourceDir.exists() )
             {
                 getLog().info( "Copy ear sources to " + getWorkDirectory().getAbsolutePath() );
-                FileUtils.copyDirectoryStructure( earSourceDir, getWorkDirectory() );
+                String[] fileNames = getEarFiles( earSourceDir );
+                for ( int i = 0; i < fileNames.length; i++ )
+                {
+                    FileUtils.copyFile( new File( earSourceDir, fileNames[i] ),
+                                        new File( getWorkDirectory(), fileNames[i] ) );
+                }
+            }
+
+            if ( applicationXml != null && !"".equals( applicationXml ) )
+            {
+                //rename to application.xml
+                getLog().info( "Including custom application.xml[" + applicationXml + "]" );
+                File metaInfDir = new File( getWorkDirectory(), META_INF );
+                FileUtils.copyFile( new File( applicationXml ), new File( metaInfDir, "/application.xml" ) );
             }
+
         }
         catch ( IOException e )
         {
@@ -163,7 +198,12 @@
             if ( resourcesDir.exists() )
             {
                 getLog().info( "Copy ear resources to " + getWorkDirectory().getAbsolutePath() );
-                FileUtils.copyDirectoryStructure( resourcesDir, getWorkDirectory() );
+                String[] fileNames = getEarFiles( resourcesDir );
+                for ( int i = 0; i < fileNames.length; i++ )
+                {
+                    FileUtils.copyFile( new File( resourcesDir, fileNames[i] ),
+                                        new File( getWorkDirectory(), fileNames[i] ) );
+                }
             }
         }
         catch ( IOException e )
@@ -200,6 +240,50 @@
         }
     }
 
+    public String getApplicationXml()
+    {
+        return applicationXml;
+    }
+
+    public void setApplicationXml( String applicationXml )
+    {
+        this.applicationXml = applicationXml;
+    }
+
+    /**
+     * Returns a string array of the excludes to be used
+     * when assembling/copying the ear.
+     *
+     * @return an array of tokens to exclude
+     */
+    protected String[] getExcludes()
+    {
+        List excludeList = new ArrayList( FileUtils.getDefaultExcludesAsList() );
+        if ( earSourceExcludes != null && !"".equals( earSourceExcludes ) )
+        {
+            excludeList.add( earSourceExcludes );
+        }
+
+        // if applicationXml is specified, omit the one in the source directory
+        if ( getApplicationXml() != null && !"".equals( getApplicationXml() ) )
+        {
+            excludeList.add( "**/" + META_INF + "/application.xml" );
+        }
+
+        return (String[]) excludeList.toArray( EMPTY_STRING_ARRAY );
+    }
+
+    /**
+     * Returns a string array of the includes to be used
+     * when assembling/copying the ear.
+     *
+     * @return an array of tokens to include
+     */
+    protected String[] getIncludes()
+    {
+        return new String[]{earSourceIncludes};
+    }
+
     private static File buildDestinationFile( File buildDir, String uri )
     {
         return new File( buildDir, uri );
@@ -218,5 +302,26 @@
             getLog().info( "Including custom manifest file[" + customManifestFile + "]" );
             archive.setManifestFile( customManifestFile );
         }
+    }
+
+    /**
+     * Returns a list of filenames that should be copied
+     * over to the destination directory.
+     *
+     * @param sourceDir the directory to be scanned
+     * @return the array of filenames, relative to the sourceDir
+     */
+    private String[] getEarFiles( File sourceDir )
+    {
+        DirectoryScanner scanner = new DirectoryScanner();
+        scanner.setBasedir( sourceDir );
+        scanner.setExcludes( getExcludes() );
+        scanner.addDefaultExcludes();
+
+        scanner.setIncludes( getIncludes() );
+
+        scanner.scan();
+
+        return scanner.getIncludedFiles();
     }
 }