You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by tr...@apache.org on 2005/08/16 21:54:32 UTC
svn commit: r233048 -
/maven/components/trunk/maven-plugins/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java
Author: trygvis
Date: Tue Aug 16 12:54:30 2005
New Revision: 233048
URL: http://svn.apache.org/viewcvs?rev=233048&view=rev
Log:
Fixing MNG-478: "war:war warSourceExcludes parameter not used when set in the
POM".
Patch created by Greg Case, thanks for your work!
Modified:
maven/components/trunk/maven-plugins/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java
Modified: maven/components/trunk/maven-plugins/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java?rev=233048&r1=233047&r2=233048&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java (original)
+++ maven/components/trunk/maven-plugins/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java Tue Aug 16 12:54:30 2005
@@ -26,6 +26,7 @@
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.jar.ManifestException;
import org.codehaus.plexus.archiver.war.WarArchiver;
+import org.codehaus.plexus.util.DirectoryScanner;
import org.codehaus.plexus.util.FileUtils;
import java.io.File;
@@ -62,12 +63,11 @@
private MavenProject project;
/**
- * @todo Convert to File
* @parameter expression="${project.build.outputDirectory}"
* @required
* @readonly
*/
- private String classesDirectory;
+ private File classesDirectory;
/**
* @parameter expression="${project.build.directory}"
@@ -76,18 +76,16 @@
private String outputDirectory;
/**
- * @todo Convert to File
* @parameter expression="${project.build.directory}/${project.build.finalName}"
* @required
*/
- private String webappDirectory;
+ private File webappDirectory;
/**
- * @todo Convert to File
* @parameter expression="${basedir}/src/main/webapp"
* @required
*/
- private String warSourceDirectory;
+ private File warSourceDirectory;
/**
* @parameter alias="includes"
@@ -118,23 +116,27 @@
private static final String[] EMPTY_STRING_ARRAY = {};
- public void copyResources( File sourceDirectory, File webappDirectory, String includes, String excludes,
- String webXml )
+ public void copyResources( File sourceDirectory, File webappDirectory, String webXml )
throws IOException
{
if ( !sourceDirectory.equals( webappDirectory ) )
{
getLog().info( "Copy webapp resources to " + webappDirectory.getAbsolutePath() );
- if ( new File( warSourceDirectory ).exists() )
+ if ( warSourceDirectory.exists() )
{
- //TODO : Use includes and excludes
- FileUtils.copyDirectoryStructure( sourceDirectory, webappDirectory );
+ String[] fileNames = getWarFiles( sourceDirectory );
+ for (int i = 0; i < fileNames.length; i++)
+ {
+ FileUtils.copyFile(new File( sourceDirectory, fileNames[i] ), new File( webappDirectory, fileNames[i] ) );
+ }
}
if ( webXml != null && !"".equals( webXml ) )
{
- FileUtils.copyFileToDirectory( new File( webXml ), new File( webappDirectory, WEB_INF ) );
+ //rename to web.xml
+ File webinfDir = new File( webappDirectory, WEB_INF );
+ FileUtils.copyFile( new File( webXml ), new File( webinfDir, "/web.xml" ) );
}
}
}
@@ -150,7 +152,6 @@
File webappClassesDirectory = new File( webappDirectory, WEB_INF + "/classes" );
- File classesDirectory = new File( this.classesDirectory );
if ( classesDirectory.exists() )
{
FileUtils.copyDirectoryStructure( classesDirectory, webappClassesDirectory );
@@ -189,14 +190,13 @@
public void generateExplodedWebapp()
throws IOException
{
- File webappDirectory = new File( this.webappDirectory );
webappDirectory.mkdirs();
File webinfDir = new File( webappDirectory, WEB_INF );
webinfDir.mkdirs();
- copyResources( new File( warSourceDirectory ), webappDirectory, warSourceIncludes, warSourceExcludes, webXml );
+ copyResources( warSourceDirectory, webappDirectory, webXml );
buildWebapp( project );
}
@@ -249,8 +249,7 @@
archiver.setOutputFile( warFile );
- String[] excludes = (String[]) getDefaultExcludes().toArray( EMPTY_STRING_ARRAY );
- warArchiver.addDirectory( new File( webappDirectory ), null, excludes );
+ warArchiver.addDirectory( webappDirectory, getIncludes(), getExcludes() );
warArchiver.setWebxml( new File( webappDirectory, "WEB-INF/web.xml" ) );
@@ -293,9 +292,59 @@
// Mac
defaultExcludes.add( "**/.DS_Store" );
- // Special one for WARs
- defaultExcludes.add( "**/" + WEB_INF + "/web.xml" );
+ // Windows Thumbs
+ defaultExcludes.add( "**/Thumbs.db" );
return defaultExcludes;
+ }
+
+ /**
+ * 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[] getWarFiles( File sourceDir )
+ {
+ DirectoryScanner scanner = new DirectoryScanner();
+ scanner.setBasedir( sourceDir );
+ scanner.setExcludes( getExcludes() );
+ scanner.addDefaultExcludes();
+
+ scanner.setIncludes( getIncludes() );
+
+ scanner.scan();
+
+ return scanner.getIncludedFiles();
+ }
+
+ /**
+ * Returns an a string array of the excludes to be used when assembling/copy the war
+ */
+ private String[] getExcludes()
+ {
+ List excludeList = getDefaultExcludes();
+ if ( warSourceExcludes != null && !"".equals( warSourceExcludes ) )
+ {
+ excludeList.add( warSourceExcludes );
+ }
+
+ // if webXML is specified, omit the one in the source directory
+ if ( webXml != null && !"".equals( webXml ) )
+ {
+ excludeList.add( "**/" + WEB_INF + "/web.xml" );
+ }
+
+ return (String[]) excludeList.toArray( EMPTY_STRING_ARRAY );
+ }
+
+ /**
+ * Returns an a string array of the includes to be used when assembling/copy the
+ * war
+ */
+ private String[] getIncludes()
+ {
+ return new String[] { warSourceIncludes };
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org