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:28:30 UTC
[maven-ant-plugin] 32/42: [MANT-45] basedir attribute of task
of package target in generated Ant build causes files to be archived twice
This is an automated email from the ASF dual-hosted git repository.
hboutemy pushed a commit to annotated tag maven-ant-plugin-2.1.1
in repository https://gitbox.apache.org/repos/asf/maven-ant-plugin.git
commit bff95319f7b9e628dcab1297b578223b9364f94a
Author: Benjamin Bentmann <be...@apache.org>
AuthorDate: Wed Sep 3 13:52:16 2008 +0000
[MANT-45] basedir attribute of <war> task of package target in generated Ant build causes files to be archived twice
git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-ant-plugin@691615 13f79535-47bb-0310-9956-ffa450edef68
---
src/it/webapp-it/pom.xml | 4 +
src/it/webapp-it/src/main/java/org/MyClass.java | 5 +
.../webapp-it/src/main/resources/test.properties | 1 +
src/it/webapp-it/src/main/webapp/WEB-INF/test.txt | 1 +
src/it/webapp-it/verify.bsh | 105 +++++++++++++++++----
.../maven/plugin/ant/AntBuildWriterUtil.java | 25 ++---
6 files changed, 107 insertions(+), 34 deletions(-)
diff --git a/src/it/webapp-it/pom.xml b/src/it/webapp-it/pom.xml
index 1fd5fb5..2d432c0 100644
--- a/src/it/webapp-it/pom.xml
+++ b/src/it/webapp-it/pom.xml
@@ -38,6 +38,10 @@ under the License.
</dependency>
</dependencies>
+ <properties>
+ <build.compiler>extJavac</build.compiler>
+ </properties>
+
<build>
<finalName>ant-webapp-test</finalName>
<plugins>
diff --git a/src/it/webapp-it/src/main/java/org/MyClass.java b/src/it/webapp-it/src/main/java/org/MyClass.java
new file mode 100644
index 0000000..47c7d4b
--- /dev/null
+++ b/src/it/webapp-it/src/main/java/org/MyClass.java
@@ -0,0 +1,5 @@
+package org;
+
+public class MyClass
+{
+}
diff --git a/src/it/webapp-it/src/main/resources/test.properties b/src/it/webapp-it/src/main/resources/test.properties
new file mode 100644
index 0000000..4b10332
--- /dev/null
+++ b/src/it/webapp-it/src/main/resources/test.properties
@@ -0,0 +1 @@
+key=value
\ No newline at end of file
diff --git a/src/it/webapp-it/src/main/webapp/WEB-INF/test.txt b/src/it/webapp-it/src/main/webapp/WEB-INF/test.txt
new file mode 100644
index 0000000..8318c86
--- /dev/null
+++ b/src/it/webapp-it/src/main/webapp/WEB-INF/test.txt
@@ -0,0 +1 @@
+Test
\ No newline at end of file
diff --git a/src/it/webapp-it/verify.bsh b/src/it/webapp-it/verify.bsh
index f002a32..8f2ba8b 100644
--- a/src/it/webapp-it/verify.bsh
+++ b/src/it/webapp-it/verify.bsh
@@ -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;
diff --git a/src/main/java/org/apache/maven/plugin/ant/AntBuildWriterUtil.java b/src/main/java/org/apache/maven/plugin/ant/AntBuildWriterUtil.java
index 333f306..c5b052f 100644
--- a/src/main/java/org/apache/maven/plugin/ant/AntBuildWriterUtil.java
+++ b/src/main/java/org/apache/maven/plugin/ant/AntBuildWriterUtil.java
@@ -495,22 +495,20 @@ public class AntBuildWriterUtil
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 @@ public class AntBuildWriterUtil
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
}
--
To stop receiving notification emails like this one, please contact
"commits@maven.apache.org" <co...@maven.apache.org>.