diff --git a/src/it/skinny-wars-javaee5/ear-module/pom.xml b/src/it/skinny-wars-javaee5/ear-module/pom.xml
index 20bfc634..dc3371b7 100644
--- a/src/it/skinny-wars-javaee5/ear-module/pom.xml
+++ b/src/it/skinny-wars-javaee5/ear-module/pom.xml
@@ -31,11 +31,28 @@ under the License.
commons-lang
commons-lang
- 2.5
+ 2.6
+
+
+ org.apache.commons
+ commons-collections4
+ 4.2
+
+
+ org.apache.maven.its.ear.skinnywars
+ war-module1
+ 1.0
+ war
+
+
+ org.apache.maven.its.ear.skinnywars
+ war-module2
+ 1.0
+ war
org.apache.maven.its.ear.skinnywars
- war-module
+ war-module3
1.0
war
diff --git a/src/it/skinny-wars-javaee5/pom.xml b/src/it/skinny-wars-javaee5/pom.xml
index ce56bae3..0afee723 100644
--- a/src/it/skinny-wars-javaee5/pom.xml
+++ b/src/it/skinny-wars-javaee5/pom.xml
@@ -30,7 +30,26 @@ under the License.
Test Skinny WAR generation
- ear-module
- war-module
+ ear-module
+ war-module1
+ war-module2
+ war-module3
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-war-plugin
+ @mavenWarPluginVersion@
+
+
+ org.apache.maven.plugins
+ maven-ear-plugin
+ @project.version@
+
+
+
+
diff --git a/src/it/skinny-wars-javaee5/verify.bsh b/src/it/skinny-wars-javaee5/verify.bsh
index ad6abb97..45c2419b 100644
--- a/src/it/skinny-wars-javaee5/verify.bsh
+++ b/src/it/skinny-wars-javaee5/verify.bsh
@@ -22,73 +22,128 @@ import java.util.*;
import java.util.jar.*;
import java.util.regex.*;
-File jarFile = new File( basedir, "ear-module/target/ear-module-1.0/org.apache.maven.its.ear.skinnywars-war-module-1.0.war" );
-System.out.println( "Checking for existence of " + jarFile );
-if ( !jarFile.isFile() )
+assertJar( String fileName, String[] includedEntries, String[] excludedEntries, boolean assertManifest,
+ String[] expectedClassPathElements )
{
- throw new IllegalStateException( "Missing file: " + jarFile );
-}
+ File jarFile = new File( basedir, fileName );
+ System.out.println( "Checking for existence of " + jarFile );
+ if ( !jarFile.isFile() )
+ {
+ throw new IllegalStateException( "Missing file: " + jarFile );
+ }
-JarFile jar = new JarFile( jarFile );
+ JarFile jar = new JarFile( jarFile );
-String[] includedEntries = {
- "WEB-INF/web.xml",
- "META-INF/MANIFEST.MF"
-};
-for ( String included : includedEntries )
-{
- System.out.println( "Checking for included archive entry " + included );
- if ( jar.getEntry( included ) == null )
+ if ( includedEntries != null )
{
- throw new IllegalStateException( "Missing archive entry: " + included );
+ for ( String included : includedEntries )
+ {
+ System.out.println( "Checking for included archive entry " + included );
+ if ( jar.getEntry( included ) == null )
+ {
+ throw new IllegalStateException( "Missing archive entry: " + included + ". Artifact: " + fileName );
+ }
+ }
}
-}
-Manifest manifest = jar.getManifest();
-String manifestClassPath = manifest.getMainAttributes().getValue("Class-Path");
-if ( manifestClassPath != null && manifestClassPath.equals("lib/commons-lang-commons-lang-2.5.jar") )
-{
- throw new IllegalStateException( "Superfluous entry in war MANIFEST.MF: commons-lang-commons-lang-2.5.jar");
-}
+ if ( excludedEntries != null )
+ {
+ for ( String excluded : excludedEntries )
+ {
+ System.out.println( "Checking for excluded artifact " + excluded );
+ if ( jar.getEntry( excluded ) != null )
+ {
+ throw new IllegalStateException( "Archive entry should be excluded: " + excluded
+ + ". Artifact: " + fileName );
+ }
+ }
+ }
-String[] excludedEntries = {
- "WEB-INF/lib/commons-lang-2.5.jar"
-};
-for ( String excluded : excludedEntries )
-{
- System.out.println( "Checking for excluded artifact " + excluded );
- if ( jar.getEntry( excluded ) != null )
+ if ( assertManifest )
{
- throw new IllegalStateException( "Archive entry should be excluded: " + excluded );
+ Manifest manifest = jar.getManifest();
+ String manifestClassPath = manifest.getMainAttributes().getValue("Class-Path");
+ if ( expectedClassPathElements == null)
+ {
+ if ( manifestClassPath != null )
+ {
+ throw new IllegalStateException( "Superfluous Class-Path entry in MANIFEST.MF of artifact: "
+ + fileName );
+ }
+ }
+ else
+ {
+ if ( manifestClassPath == null )
+ {
+ throw new IllegalStateException( "Missing Class-Path entry in MANIFEST.MF of artifact: "
+ + fileName );
+ }
+ manifestClassPath = manifestClassPath.trim();
+ String[] actualClassPathElements = manifestClassPath.length() == 0 ?
+ new String[0] : manifestClassPath.split( " " );
+ if ( !Arrays.equals( expectedClassPathElements, actualClassPathElements ) )
+ {
+ throw new IllegalStateException( "Invalid Class-Path entry in MANIFEST.MF of artifact: "
+ + fileName
+ + ". Expected: " + Arrays.toString( expectedClassPathElements )
+ + ". Actual: " + Arrays.toString( actualClassPathElements ) );
+ }
+ }
}
}
-jar.close();
+String[] includedEntries = {
+ "WEB-INF/web.xml",
+ "META-INF/MANIFEST.MF",
+ "WEB-INF/lib/commons-lang-2.6.jar"
+};
+String[] excludedEntries = {};
-File jarFile = new File( basedir, "war-module/target/war-module-1.0.war" );
-System.out.println( "Checking for existence of " + jarFile );
-if ( !jarFile.isFile() )
-{
- throw new IllegalStateException( "Missing file: " + jarFile );
-}
+String[] expectedClassPathElements = { "commons-lang-2.6.jar" };
-JarFile jar = new JarFile( jarFile );
+assertJar( "war-module1/target/war-module1-1.0.war", includedEntries, excludedEntries, true,
+ expectedClassPathElements );
-String[] includedEntries = {
+assertJar( "war-module2/target/war-module2-1.0.war", includedEntries, excludedEntries, true, null );
+
+String[] warModule3IncludedEntries = {
"WEB-INF/web.xml",
"META-INF/MANIFEST.MF",
- "WEB-INF/lib/commons-lang-2.5.jar"
+ "WEB-INF/lib/commons-io-2.6.jar"
};
-for ( String included : includedEntries )
-{
- System.out.println( "Checking for included archive entry " + included );
- if ( jar.getEntry( included ) == null )
- {
- throw new IllegalStateException( "Missing archive entry: " + included );
- }
-}
-jar.close();
+String[] warModuleExcludedEntries = {
+ "WEB-INF/lib/commons-lang-2.6.jar",
+ "WEB-INF/lib/commons-collections4-4.2.jar"
+};
+
+String[] warModule3ExpectedClassPathElements = { "commons-io-2.6.jar" };
+
+assertJar( "war-module3/target/war-module3-1.0.war", warModule3IncludedEntries, warModuleExcludedEntries, true,
+ warModule3ExpectedClassPathElements );
+
+String earBaseDir = "ear-module/target/ear-module-1.0/";
+String earLibDir = earBaseDir + "lib/";
+
+assertJar( earLibDir + "commons-lang-commons-lang-2.6.jar", null, null, false, null );
+
+assertJar( earLibDir + "org.apache.commons-commons-collections4-4.2.jar", null, null, false, null );
+
+String[] includedEntries = {
+ "WEB-INF/web.xml",
+ "META-INF/MANIFEST.MF"
+};
+
+String[] warModule1ExpectedClassPathElements = { "lib/commons-lang-commons-lang-2.6.jar" };
+
+assertJar( earBaseDir + "org.apache.maven.its.ear.skinnywars-war-module1-1.0.war", includedEntries,
+ warModuleExcludedEntries, true, warModule1ExpectedClassPathElements );
+
+assertJar( earBaseDir + "org.apache.maven.its.ear.skinnywars-war-module2-1.0.war", includedEntries,
+ warModuleExcludedEntries, true, null );
+
+assertJar( earBaseDir + "org.apache.maven.its.ear.skinnywars-war-module3-1.0.war",
+ warModule3IncludedEntries, warModuleExcludedEntries, true, warModule3ExpectedClassPathElements );
return true;
diff --git a/src/it/skinny-wars-javaee5/war-module/pom.xml b/src/it/skinny-wars-javaee5/war-module1/pom.xml
similarity index 83%
rename from src/it/skinny-wars-javaee5/war-module/pom.xml
rename to src/it/skinny-wars-javaee5/war-module1/pom.xml
index 9604026a..c093103a 100644
--- a/src/it/skinny-wars-javaee5/war-module/pom.xml
+++ b/src/it/skinny-wars-javaee5/war-module1/pom.xml
@@ -23,7 +23,7 @@ under the License.
4.0.0
org.apache.maven.its.ear.skinnywars
- war-module
+ war-module1
1.0
war
@@ -31,7 +31,7 @@ under the License.
commons-lang
commons-lang
- 2.5
+ 2.6
@@ -40,7 +40,13 @@ under the License.
org.apache.maven.plugins
maven-war-plugin
- @mavenWarPluginVersion@
+
+
+
+ true
+
+
+
diff --git a/src/it/skinny-wars-javaee5/war-module/src/main/webapp/WEB-INF/web.xml b/src/it/skinny-wars-javaee5/war-module1/src/main/webapp/WEB-INF/web.xml
similarity index 100%
rename from src/it/skinny-wars-javaee5/war-module/src/main/webapp/WEB-INF/web.xml
rename to src/it/skinny-wars-javaee5/war-module1/src/main/webapp/WEB-INF/web.xml
diff --git a/src/it/skinny-wars-javaee5/war-module2/pom.xml b/src/it/skinny-wars-javaee5/war-module2/pom.xml
new file mode 100644
index 00000000..5d2fd3c1
--- /dev/null
+++ b/src/it/skinny-wars-javaee5/war-module2/pom.xml
@@ -0,0 +1,37 @@
+
+
+
+
+
+ 4.0.0
+
+ org.apache.maven.its.ear.skinnywars
+ war-module2
+ 1.0
+ war
+
+
+
+ commons-lang
+ commons-lang
+ 2.6
+
+
+
diff --git a/src/it/skinny-wars-javaee5/war-module2/src/main/webapp/WEB-INF/web.xml b/src/it/skinny-wars-javaee5/war-module2/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 00000000..c1af95de
--- /dev/null
+++ b/src/it/skinny-wars-javaee5/war-module2/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
diff --git a/src/it/skinny-wars-javaee5/war-module3/pom.xml b/src/it/skinny-wars-javaee5/war-module3/pom.xml
new file mode 100644
index 00000000..8041f63e
--- /dev/null
+++ b/src/it/skinny-wars-javaee5/war-module3/pom.xml
@@ -0,0 +1,53 @@
+
+
+
+
+
+ 4.0.0
+
+ org.apache.maven.its.ear.skinnywars
+ war-module3
+ 1.0
+ war
+
+
+
+ commons-io
+ commons-io
+ 2.6
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-war-plugin
+
+
+
+ true
+
+
+
+
+
+
+
diff --git a/src/it/skinny-wars-javaee5/war-module3/src/main/webapp/WEB-INF/web.xml b/src/it/skinny-wars-javaee5/war-module3/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 00000000..c1af95de
--- /dev/null
+++ b/src/it/skinny-wars-javaee5/war-module3/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
diff --git a/src/main/java/org/apache/maven/plugins/ear/EarMojo.java b/src/main/java/org/apache/maven/plugins/ear/EarMojo.java
index 258a1cc8..18fb926b 100644
--- a/src/main/java/org/apache/maven/plugins/ear/EarMojo.java
+++ b/src/main/java/org/apache/maven/plugins/ear/EarMojo.java
@@ -816,12 +816,15 @@ private void changeManifestClasspath( EarModule module, File original, JavaEEVer
Attribute classPath = mf.getMainSection().getAttribute( "Class-Path" );
List classPathElements = new ArrayList();
+ boolean classPathExists;
if ( classPath != null )
{
+ classPathExists = true;
classPathElements.addAll( Arrays.asList( classPath.getValue().split( " " ) ) );
}
else
{
+ classPathExists = false;
classPath = new Attribute( "Class-Path", "" );
}
@@ -888,6 +891,7 @@ private void changeManifestClasspath( EarModule module, File original, JavaEEVer
}
// Modify the classpath entries in the manifest
+ boolean forceClassPathModification = javaEEVersion.lt( JavaEEVersion.FIVE ) || defaultLibBundleDir == null;
for ( EarModule o : getModules() )
{
if ( o instanceof JarModule )
@@ -898,30 +902,27 @@ private void changeManifestClasspath( EarModule module, File original, JavaEEVer
{
classPathElements.set( moduleClassPathIndex, jm.getUri() );
}
- else
+ else if ( !skipClassPathModification )
{
- if ( !skipClassPathModification )
- {
- classPathElements.add( jm.getUri() );
- }
- else
- {
- if ( javaEEVersion.lt( JavaEEVersion.FIVE ) || defaultLibBundleDir == null )
- {
- classPathElements.add( jm.getUri() );
- }
- }
+ classPathElements.add( jm.getUri() );
+ }
+ else if ( forceClassPathModification )
+ {
+ classPathElements.add( jm.getUri() );
}
}
}
- classPath.setValue( StringUtils.join( classPathElements.iterator(), " " ) );
- mf.getMainSection().addConfiguredAttribute( classPath );
-
- // Write the manifest to disk
- try ( FileOutputStream out = new FileOutputStream( manifestFile );
- OutputStreamWriter writer = new OutputStreamWriter( out, StandardCharsets.UTF_8 ) )
+ if ( !skipClassPathModification || !classPathElements.isEmpty() || classPathExists )
{
- mf.write( writer );
+ classPath.setValue( StringUtils.join( classPathElements.iterator(), " " ) );
+ mf.getMainSection().addConfiguredAttribute( classPath );
+
+ // Write the manifest to disk
+ try ( FileOutputStream out = new FileOutputStream( manifestFile );
+ OutputStreamWriter writer = new OutputStreamWriter( out, StandardCharsets.UTF_8 ) )
+ {
+ mf.write( writer );
+ }
}
if ( original.isFile() )