You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2017/12/20 09:34:10 UTC

[maven-ear-plugin] 07/16: - 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.

This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a commit to annotated tag maven-ear-plugin-2.1
in repository https://gitbox.apache.org/repos/asf/maven-ear-plugin.git

commit 3e014d46f7b75b97008249d3bb10df00b69aa24c
Author: Stephane Nicoll <sn...@apache.org>
AuthorDate: Wed Nov 9 19:40:29 2005 +0000

    - 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.
    
    git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk/maven-plugins/maven-ear-plugin@332123 13f79535-47bb-0310-9956-ffa450edef68
---
 .../apache/maven/plugin/ear/AbstractEarMojo.java   |   4 +-
 .../java/org/apache/maven/plugin/ear/EarMojo.java  | 117 +++++++++++++++++++--
 2 files changed, 114 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java b/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java
index 167851c..4b6f8f1 100644
--- a/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java
+++ b/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java
@@ -17,6 +17,7 @@ package org.apache.maven.plugin.ear;
  */
 
 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.ArrayList;
 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.
@@ -41,6 +41,8 @@ public abstract class AbstractEarMojo
 
     public static final String APPLICATION_XML_URI = "META-INF/application.xml";
 
+    public static final String META_INF = "META-INF";
+
     /**
      * The maven project.
      *
diff --git a/src/main/java/org/apache/maven/plugin/ear/EarMojo.java b/src/main/java/org/apache/maven/plugin/ear/EarMojo.java
index e174288..d0db439 100644
--- a/src/main/java/org/apache/maven/plugin/ear/EarMojo.java
+++ b/src/main/java/org/apache/maven/plugin/ear/EarMojo.java
@@ -21,11 +21,14 @@ import org.apache.maven.archiver.MavenArchiver;
 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 @@ public class EarMojo
     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 @@ public class EarMojo
     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 @@ public class EarMojo
         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 @@ public class EarMojo
             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 @@ public class EarMojo
             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 class EarMojo
         }
     }
 
+    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 );
@@ -219,4 +303,25 @@ public class EarMojo
             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();
+    }
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@maven.apache.org" <co...@maven.apache.org>.