Author: bentmann Date: Wed Sep 3 06:52:16 2008 New Revision: 691615 URL: http://svn.apache.org/viewvc?rev=691615&view=rev Log: [MANT-45] basedir attribute of <war> task of package target in generated Ant build causes files to be archived twice
Added: maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/src/main/java/ maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/src/main/java/org/ maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/src/main/java/org/MyClass.java (with props) maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/src/main/resources/test.properties (with props) maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/src/main/webapp/WEB-INF/test.txt (with props) Modified: maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/pom.xml maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/verify.bsh maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntBuildWriterUtil.java Modified: maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/pom.xml?rev=691615&r1=691614&r2=691615&view=diff ============================================================================== --- maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/pom.xml (original) +++ maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/pom.xml Wed Sep 3 06:52:16 2008 @@ -38,6 +38,10 @@ </dependency> </dependencies> + <properties> + <build.compiler>extJavac</build.compiler> + </properties> + <build> <finalName>ant-webapp-test</finalName> <plugins> Added: maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/src/main/java/org/MyClass.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/src/main/java/org/MyClass.java?rev=691615&view=auto ============================================================================== --- maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/src/main/java/org/MyClass.java (added) +++ maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/src/main/java/org/MyClass.java Wed Sep 3 06:52:16 2008 @@ -0,0 +1,5 @@ +package org; + +public class MyClass +{ +} Propchange: maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/src/main/java/org/MyClass.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/src/main/java/org/MyClass.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/src/main/resources/test.properties URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/src/main/resources/test.properties?rev=691615&view=auto ============================================================================== --- maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/src/main/resources/test.properties (added) +++ maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/src/main/resources/test.properties Wed Sep 3 06:52:16 2008 @@ -0,0 +1 @@ +key=value \ No newline at end of file Propchange: maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/src/main/resources/test.properties ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/src/main/resources/test.properties ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/src/main/webapp/WEB-INF/test.txt URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/src/main/webapp/WEB-INF/test.txt?rev=691615&view=auto ============================================================================== --- maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/src/main/webapp/WEB-INF/test.txt (added) +++ maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/src/main/webapp/WEB-INF/test.txt Wed Sep 3 06:52:16 2008 @@ -0,0 +1 @@ +Test \ No newline at end of file Propchange: maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/src/main/webapp/WEB-INF/test.txt ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/src/main/webapp/WEB-INF/test.txt ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/verify.bsh URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/verify.bsh?rev=691615&r1=691614&r2=691615&view=diff ============================================================================== --- maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/verify.bsh (original) +++ maven/plugins/trunk/maven-ant-plugin/src/it/webapp-it/verify.bsh Wed Sep 3 06:52:16 2008 @@ -1,32 +1,99 @@ import java.io.BufferedReader; import java.io.File; import java.io.IOException; +import java.util.jar.*; import org.codehaus.plexus.util.IOUtil; -File build; -File mavenBuild; -File mavenBuildProperties; +try +{ + File build; + File mavenBuild; + File mavenBuildProperties; + + // Webapp project + + build = new File( basedir, "build.xml" ); + if ( build.isDirectory() || !build.exists() ) + { + System.err.println( "The file '" + build.getAbsolutePath() + "' is a directory or doesn't exist." ); + return false; + } + mavenBuild = new File( basedir, "maven-build.xml" ); + if ( mavenBuild.isDirectory() || !mavenBuild.exists() ) + { + System.err.println( "The file '" + mavenBuild.getAbsolutePath() + "' is a directory or doesn't exist." ); + return false; + } + mavenBuildProperties = new File( basedir, "maven-build.properties" ); + if ( mavenBuildProperties.isDirectory() || !mavenBuildProperties.exists() ) + { + System.err.println( "The file '" + mavenBuildProperties.getAbsolutePath() + "' is a directory or doesn't exist." ); + return false; + } + + warFile = new File( basedir, "target/ant-webapp-test.war" ); + System.out.println( "Checking for existence of WAR file: " + warFile ); + if ( !warFile.isFile() ) + { + System.err.println( "FAILED!" ); + return false; + } + + JarFile war = new JarFile( warFile ); -// Webapp project + String[] expected = { + "index.jsp", + "WEB-INF/web.xml", + "WEB-INF/test.txt", + "WEB-INF/classes/test.properties", + "WEB-INF/classes/org/MyClass.class", + }; + for ( String entry : expected ) + { + System.out.println( "Checking for existence of WAR file entry: " + entry ); + if ( war.getEntry( entry ) == null ) + { + System.err.println( "FAILED!" ); + return false; + } -build = new File( basedir, "build.xml" ); -if ( build.isDirectory() || !build.exists() ) -{ - System.err.println( "The file '" + build.getAbsolutePath() + "' is a directory or doesn't exist." ); - return false; -} -mavenBuild = new File( basedir, "maven-build.xml" ); -if ( mavenBuild.isDirectory() || !mavenBuild.exists() ) -{ - System.err.println( "The file '" + mavenBuild.getAbsolutePath() + "' is a directory or doesn't exist." ); - return false; + System.out.println( "Checking for uniqueness of WAR file entry: " + entry ); + int count = 0; + for ( Enumeration en = war.entries(); en.hasMoreElements(); ) + { + JarEntry je = (JarEntry) en.nextElement(); + if ( entry.equals( je.getName() ) ) + { + count++; + } + } + if ( count != 1 ) + { + System.err.println( "FAILED! " + count ); + return false; + } + } + + String[] unexpected = { + "org/MyClass.class", + }; + for ( String entry : unexpected ) + { + System.out.println( "Checking for absence of WAR file entry: " + entry ); + if ( war.getEntry( entry ) != null ) + { + System.err.println( "FAILED!" ); + return false; + } + } + + war.close(); } -mavenBuildProperties = new File( basedir, "maven-build.properties" ); -if ( mavenBuildProperties.isDirectory() || !mavenBuildProperties.exists() ) +catch( Throwable t ) { - System.err.println( "The file '" + mavenBuildProperties.getAbsolutePath() + "' is a directory or doesn't exist." ); - return false; + t.printStackTrace(); + return false; } return true; Modified: maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntBuildWriterUtil.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntBuildWriterUtil.java?rev=691615&r1=691614&r2=691615&view=diff ============================================================================== --- maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntBuildWriterUtil.java (original) +++ maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntBuildWriterUtil.java Wed Sep 3 06:52:16 2008 @@ -495,22 +495,20 @@ public static void writeWarTask( XMLWriter writer, MavenProject project, File localRepository ) throws IOException { + String webXml = + getMavenWarPluginBasicOption( project, "webXml", "${basedir}/src/main/webapp/WEB-INF/web.xml" ); + if ( webXml.startsWith( "${basedir}/" ) ) + { + webXml = webXml.substring( "${basedir}/".length() ); + } + writeCopyLib( writer, project, "${maven.build.dir}/${maven.build.finalName}/WEB-INF/lib" ); writer.startElement( "war" ); writer.addAttribute( "destfile", "${maven.build.dir}/${maven.build.finalName}.war" ); - addWrapAttribute( writer, "war", "basedir", "${maven.build.outputDir}", 3 ); addWrapAttribute( writer, "war", "compress", getMavenWarPluginBasicOption( project, "archive//compress", "true" ), 3 ); - if ( getMavenWarPluginBasicOption( project, "webXml", null ) != null ) - { - addWrapAttribute( writer, "war", "webxml", getMavenWarPluginBasicOption( project, "webXml", null ), 3 ); - } - else - { - // Default - addWrapAttribute( writer, "war", "webxml", "${basedir}/src/main/webapp/WEB-INF/web.xml", 3 ); - } + addWrapAttribute( writer, "war", "webxml", webXml, 3 ); if ( getMavenWarPluginBasicOption( project, "manifestFile", null ) != null ) { addWrapAttribute( writer, "war", "manifest", getMavenWarPluginBasicOption( project, "manifestFile", null ), @@ -522,12 +520,9 @@ writer.startElement( "classes" ); writer.addAttribute( "dir", "${maven.build.outputDir}" ); writer.endElement(); // classes - writer.startElement( "webinf" ); - writer.addAttribute( "dir", "${basedir}/src/main/webapp/WEB-INF" ); - addWrapAttribute( writer, "webinf", "excludes", "web.xml", 4 ); - writer.endElement(); // webinf writer.startElement( "fileset" ); - writer.addAttribute( "dir", "${basedir}/src/main/webapp" ); + writer.addAttribute( "dir", "src/main/webapp" ); + addWrapAttribute( writer, "fileset", "excludes", "WEB-INF/web.xml", 4 ); writer.endElement(); // fileset writer.endElement(); // war }