From b610fd0c94f829516417c83111502653952bea1f Mon Sep 17 00:00:00 2001 From: Marat Abrarov Date: Sun, 6 Dec 2020 18:05:03 +0300 Subject: [PATCH 1/2] [MEAR-292] - Don't add MANFIEST.mf Class-Path entry for EAR module if skipClassPathModification is true and original MANFIEST.mf of EAR module artifact doesn't contain Class-Path entry. --- src/it/skinny-wars-javaee5/ear-module/pom.xml | 19 ++- src/it/skinny-wars-javaee5/pom.xml | 23 ++- src/it/skinny-wars-javaee5/verify.bsh | 153 ++++++++++++------ .../{war-module => war-module1}/pom.xml | 10 +- .../src/main/webapp/WEB-INF/web.xml | 0 .../skinny-wars-javaee5/war-module2/pom.xml | 37 +++++ .../src/main/webapp/WEB-INF/web.xml | 23 +++ .../skinny-wars-javaee5/war-module3/pom.xml | 53 ++++++ .../src/main/webapp/WEB-INF/web.xml | 23 +++ .../org/apache/maven/plugins/ear/EarMojo.java | 39 ++--- 10 files changed, 308 insertions(+), 72 deletions(-) rename src/it/skinny-wars-javaee5/{war-module => war-module1}/pom.xml (85%) rename src/it/skinny-wars-javaee5/{war-module => war-module1}/src/main/webapp/WEB-INF/web.xml (100%) create mode 100644 src/it/skinny-wars-javaee5/war-module2/pom.xml create mode 100644 src/it/skinny-wars-javaee5/war-module2/src/main/webapp/WEB-INF/web.xml create mode 100644 src/it/skinny-wars-javaee5/war-module3/pom.xml create mode 100644 src/it/skinny-wars-javaee5/war-module3/src/main/webapp/WEB-INF/web.xml diff --git a/src/it/skinny-wars-javaee5/ear-module/pom.xml b/src/it/skinny-wars-javaee5/ear-module/pom.xml index 20bfc634..0c9958fb 100644 --- a/src/it/skinny-wars-javaee5/ear-module/pom.xml +++ b/src/it/skinny-wars-javaee5/ear-module/pom.xml @@ -33,9 +33,26 @@ under the License. commons-lang 2.5 + + org.apache.commons + commons-lang3 + 3.11 + + + 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..36bde87d 100644 --- a/src/it/skinny-wars-javaee5/verify.bsh +++ b/src/it/skinny-wars-javaee5/verify.bsh @@ -22,73 +22,130 @@ 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 ); + } + String[] actualClassPathElements = 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.5.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.5.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-io-2.8.0.jar" +}; + +String[] warModule3ExcludedEntries = { + "WEB-INF/lib/commons-lang-2.5.jar", + "WEB-INF/lib/commons-lang3-3.11.jar" +}; + +String[] warModule3ExpectedClassPathElements = { "commons-io-2.8.0.jar" }; + +assertJar( "war-module3/target/war-module3-1.0.war", warModule3IncludedEntries, warModule3ExcludedEntries, true, + warModule3ExpectedClassPathElements ); + +String earBaseDir = "ear-module/target/ear-module-1.0/"; +String earLibDir = earBaseDir + "lib/"; + +assertJar( earLibDir + "commons-lang-commons-lang-2.5.jar", null, null, false, null ); + +assertJar( earLibDir + "org.apache.commons-commons-lang3-3.11.jar", null, null, false, null ); + +String[] includedEntries = { + "WEB-INF/web.xml", + "META-INF/MANIFEST.MF" +}; + +String[] excludedEntries = { "WEB-INF/lib/commons-lang-2.5.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[] expectedClassPathElements = { "lib/commons-lang-commons-lang-2.5.jar" }; + +assertJar( earBaseDir + "org.apache.maven.its.ear.skinnywars-war-module1-1.0.war", includedEntries, excludedEntries, + true, expectedClassPathElements ); + +assertJar( earBaseDir + "org.apache.maven.its.ear.skinnywars-war-module2-1.0.war", includedEntries, excludedEntries, + true, null ); + +assertJar( earBaseDir + "org.apache.maven.its.ear.skinnywars-war-module3-1.0.war", + warModule3IncludedEntries, warModule3ExcludedEntries, 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 85% rename from src/it/skinny-wars-javaee5/war-module/pom.xml rename to src/it/skinny-wars-javaee5/war-module1/pom.xml index 9604026a..b0c8688e 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 @@ -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..3130a969 --- /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.5 + + + 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..d13bc3d7 --- /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.8.0 + + + + + + + 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..1624722f 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 classPathExisted; if ( classPath != null ) { + classPathExisted = true; classPathElements.addAll( Arrays.asList( classPath.getValue().split( " " ) ) ); } else { + classPathExisted = 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() || classPathExisted ) { - 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() ) From 726de94bcdd4989f7f5cdf42772e9ae313b318a4 Mon Sep 17 00:00:00 2001 From: Marat Abrarov Date: Sun, 20 Dec 2020 17:32:13 +0300 Subject: [PATCH 2/2] [MEAR-292] - skinnyWar integration test supporting Java 7. --- src/it/skinny-wars-javaee5/ear-module/pom.xml | 6 +-- src/it/skinny-wars-javaee5/verify.bsh | 40 +++++++++---------- .../skinny-wars-javaee5/war-module1/pom.xml | 2 +- .../skinny-wars-javaee5/war-module2/pom.xml | 2 +- .../skinny-wars-javaee5/war-module3/pom.xml | 2 +- .../org/apache/maven/plugins/ear/EarMojo.java | 8 ++-- 6 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/it/skinny-wars-javaee5/ear-module/pom.xml b/src/it/skinny-wars-javaee5/ear-module/pom.xml index 0c9958fb..dc3371b7 100644 --- a/src/it/skinny-wars-javaee5/ear-module/pom.xml +++ b/src/it/skinny-wars-javaee5/ear-module/pom.xml @@ -31,12 +31,12 @@ under the License. commons-lang commons-lang - 2.5 + 2.6 org.apache.commons - commons-lang3 - 3.11 + commons-collections4 + 4.2 org.apache.maven.its.ear.skinnywars diff --git a/src/it/skinny-wars-javaee5/verify.bsh b/src/it/skinny-wars-javaee5/verify.bsh index 36bde87d..45c2419b 100644 --- a/src/it/skinny-wars-javaee5/verify.bsh +++ b/src/it/skinny-wars-javaee5/verify.bsh @@ -78,7 +78,9 @@ assertJar( String fileName, String[] includedEntries, String[] excludedEntries, throw new IllegalStateException( "Missing Class-Path entry in MANIFEST.MF of artifact: " + fileName ); } - String[] actualClassPathElements = manifestClassPath.split( " " ); + 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: " @@ -93,12 +95,12 @@ assertJar( String fileName, String[] includedEntries, String[] excludedEntries, String[] includedEntries = { "WEB-INF/web.xml", "META-INF/MANIFEST.MF", - "WEB-INF/lib/commons-lang-2.5.jar" + "WEB-INF/lib/commons-lang-2.6.jar" }; String[] excludedEntries = {}; -String[] expectedClassPathElements = { "commons-lang-2.5.jar" }; +String[] expectedClassPathElements = { "commons-lang-2.6.jar" }; assertJar( "war-module1/target/war-module1-1.0.war", includedEntries, excludedEntries, true, expectedClassPathElements ); @@ -108,44 +110,40 @@ assertJar( "war-module2/target/war-module2-1.0.war", includedEntries, excludedEn String[] warModule3IncludedEntries = { "WEB-INF/web.xml", "META-INF/MANIFEST.MF", - "WEB-INF/lib/commons-io-2.8.0.jar" + "WEB-INF/lib/commons-io-2.6.jar" }; -String[] warModule3ExcludedEntries = { - "WEB-INF/lib/commons-lang-2.5.jar", - "WEB-INF/lib/commons-lang3-3.11.jar" +String[] warModuleExcludedEntries = { + "WEB-INF/lib/commons-lang-2.6.jar", + "WEB-INF/lib/commons-collections4-4.2.jar" }; -String[] warModule3ExpectedClassPathElements = { "commons-io-2.8.0.jar" }; +String[] warModule3ExpectedClassPathElements = { "commons-io-2.6.jar" }; -assertJar( "war-module3/target/war-module3-1.0.war", warModule3IncludedEntries, warModule3ExcludedEntries, true, +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.5.jar", null, null, false, null ); +assertJar( earLibDir + "commons-lang-commons-lang-2.6.jar", null, null, false, null ); -assertJar( earLibDir + "org.apache.commons-commons-lang3-3.11.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[] excludedEntries = { - "WEB-INF/lib/commons-lang-2.5.jar" -}; - -String[] expectedClassPathElements = { "lib/commons-lang-commons-lang-2.5.jar" }; +String[] warModule1ExpectedClassPathElements = { "lib/commons-lang-commons-lang-2.6.jar" }; -assertJar( earBaseDir + "org.apache.maven.its.ear.skinnywars-war-module1-1.0.war", includedEntries, excludedEntries, - true, expectedClassPathElements ); +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, excludedEntries, - true, null ); +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, warModule3ExcludedEntries, true, warModule3ExpectedClassPathElements ); + warModule3IncludedEntries, warModuleExcludedEntries, true, warModule3ExpectedClassPathElements ); return true; diff --git a/src/it/skinny-wars-javaee5/war-module1/pom.xml b/src/it/skinny-wars-javaee5/war-module1/pom.xml index b0c8688e..c093103a 100644 --- a/src/it/skinny-wars-javaee5/war-module1/pom.xml +++ b/src/it/skinny-wars-javaee5/war-module1/pom.xml @@ -31,7 +31,7 @@ under the License. commons-lang commons-lang - 2.5 + 2.6 diff --git a/src/it/skinny-wars-javaee5/war-module2/pom.xml b/src/it/skinny-wars-javaee5/war-module2/pom.xml index 3130a969..5d2fd3c1 100644 --- a/src/it/skinny-wars-javaee5/war-module2/pom.xml +++ b/src/it/skinny-wars-javaee5/war-module2/pom.xml @@ -31,7 +31,7 @@ under the License. commons-lang commons-lang - 2.5 + 2.6 diff --git a/src/it/skinny-wars-javaee5/war-module3/pom.xml b/src/it/skinny-wars-javaee5/war-module3/pom.xml index d13bc3d7..8041f63e 100644 --- a/src/it/skinny-wars-javaee5/war-module3/pom.xml +++ b/src/it/skinny-wars-javaee5/war-module3/pom.xml @@ -31,7 +31,7 @@ under the License. commons-io commons-io - 2.8.0 + 2.6 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 1624722f..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,15 +816,15 @@ private void changeManifestClasspath( EarModule module, File original, JavaEEVer Attribute classPath = mf.getMainSection().getAttribute( "Class-Path" ); List classPathElements = new ArrayList(); - boolean classPathExisted; + boolean classPathExists; if ( classPath != null ) { - classPathExisted = true; + classPathExists = true; classPathElements.addAll( Arrays.asList( classPath.getValue().split( " " ) ) ); } else { - classPathExisted = false; + classPathExists = false; classPath = new Attribute( "Class-Path", "" ); } @@ -912,7 +912,7 @@ else if ( forceClassPathModification ) } } } - if ( !skipClassPathModification || !classPathElements.isEmpty() || classPathExisted ) + if ( !skipClassPathModification || !classPathElements.isEmpty() || classPathExists ) { classPath.setValue( StringUtils.join( classPathElements.iterator(), " " ) ); mf.getMainSection().addConfiguredAttribute( classPath );