From 968d1f24961f70b79b8b971f0ba3b37c0c124328 Mon Sep 17 00:00:00 2001 From: Marat Abrarov Date: Sat, 3 Oct 2020 22:17:08 +0300 Subject: [PATCH 01/13] [MEAR-267] - Fixed detection if EAR JAR module is included into classpath of particular EAR module manifest --- .../org/apache/maven/plugins/ear/EarMojo.java | 56 ++++++++++++++++++- 1 file changed, 54 insertions(+), 2 deletions(-) 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 3bc47ae4..1676645c 100644 --- a/src/main/java/org/apache/maven/plugins/ear/EarMojo.java +++ b/src/main/java/org/apache/maven/plugins/ear/EarMojo.java @@ -40,6 +40,7 @@ import org.apache.maven.archiver.MavenArchiveConfiguration; import org.apache.maven.archiver.MavenArchiver; +import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecutionException; @@ -56,6 +57,7 @@ import org.apache.maven.shared.filtering.MavenFilteringException; import org.apache.maven.shared.filtering.MavenResourcesExecution; import org.apache.maven.shared.filtering.MavenResourcesFiltering; +import org.apache.maven.shared.mapping.MappingUtils; import org.apache.maven.shared.utils.io.FileUtils; import org.codehaus.plexus.archiver.Archiver; import org.codehaus.plexus.archiver.ArchiverException; @@ -70,6 +72,7 @@ import org.codehaus.plexus.archiver.zip.ZipArchiver; import org.codehaus.plexus.archiver.zip.ZipUnArchiver; import org.codehaus.plexus.components.io.filemappers.FileMapper; +import org.codehaus.plexus.interpolation.InterpolationException; import org.codehaus.plexus.util.DirectoryScanner; import org.codehaus.plexus.util.StringUtils; @@ -84,6 +87,16 @@ public class EarMojo extends AbstractEarMojo { + /** + * File name mappings which can be used by elements of Class-Path manifest entry of EAR modules to identify if + * classpath element matches particular EAR module. + */ + private static final List CLASSPATH_ELEMENT_FILE_NAME_MAPPINGS = Arrays.asList( + "@{artifactId}@-@{version}@@{dashClassifier?}@.@{extension}@", + "@{groupId}@-@{artifactId}@-@{version}@@{dashClassifier?}@.@{extension}@", + "@{artifactId}@-@{baseVersion}@@{dashClassifier?}@.@{extension}@", + "@{groupId}@-@{artifactId}@-@{baseVersion}@@{dashClassifier?}@.@{extension}@" ); + /** * Single directory for extra files to include in the EAR. */ @@ -845,9 +858,10 @@ private void changeManifestClasspath( EarModule module, File original, JavaEEVer if ( o instanceof JarModule ) { JarModule jm = (JarModule) o; - if ( classPathElements.contains( jm.getBundleFileName() ) ) + final int moduleClassPathIndex = findModuleInClassPathElements( classPathElements, jm ); + if ( moduleClassPathIndex != -1 ) { - classPathElements.set( classPathElements.indexOf( jm.getBundleFileName() ), jm.getUri() ); + classPathElements.set( moduleClassPathIndex, jm.getUri() ); } else { @@ -946,4 +960,42 @@ private void deleteOutdatedResources( final Collection outdatedResources } } } + + /** + * Searches JAR module in the list of classpath elements. + * + * @param classPathElements classpath elements to search among. + * @param module module to find among classpath elements defined by {@code classPathElements} + * @return -1 if {@code module} was not found in {@code classPathElements} or index of item of + * {@code classPathElements} which matches {@code module} + */ + private int findModuleInClassPathElements( final List classPathElements, final JarModule module ) + { + int moduleClassPathIndex = classPathElements.indexOf( module.getBundleFileName() ); + if ( moduleClassPathIndex != -1 ) + { + return moduleClassPathIndex; + } + // Check the case when classpath entry uses some of default file name mappings + // instead of file name mapping configured for EAR plugin + final Artifact artifact = module.getArtifact(); + for ( String fileNameMapping : CLASSPATH_ELEMENT_FILE_NAME_MAPPINGS ) + { + try + { + final String bundleFileName = MappingUtils.evaluateFileNameMapping( fileNameMapping, artifact ); + moduleClassPathIndex = classPathElements.indexOf( bundleFileName ); + if ( moduleClassPathIndex != -1 ) + { + return moduleClassPathIndex; + } + } + catch ( InterpolationException e ) + { + getLog().warn( "Failed to build bundle file name for artifact [" + module + + "] using file name mapping: " + fileNameMapping, e ); + } + } + return -1; + } } From 89816ae618efa1fd63f288afe18ff5690c54d2f1 Mon Sep 17 00:00:00 2001 From: Marat Abrarov Date: Sun, 4 Oct 2020 01:13:49 +0300 Subject: [PATCH 02/13] [MEAR-267] - Fixed detection of need of modification of Class-Path entry of EAR module manifest --- src/main/java/org/apache/maven/plugins/ear/EarMojo.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 1676645c..327d799a 100644 --- a/src/main/java/org/apache/maven/plugins/ear/EarMojo.java +++ b/src/main/java/org/apache/maven/plugins/ear/EarMojo.java @@ -462,7 +462,7 @@ private void copyModules( final JavaEEVersion javaEEVersion, } unpack( sourceFile, destinationFile, outdatedResources ); - if ( skinnyWars && module.changeManifestClasspath() ) + if ( module.changeManifestClasspath() && ( skinnyWars || module.getLibDir() == null ) ) { changeManifestClasspath( module, destinationFile, javaEEVersion ); } @@ -474,7 +474,7 @@ private void copyModules( final JavaEEVersion javaEEVersion, getLog().info( "Copying artifact [" + module + "] to [" + module.getUri() + "]" ); FileUtils.copyFile( sourceFile, destinationFile ); - if ( skinnyWars && module.changeManifestClasspath() ) + if ( module.changeManifestClasspath() && ( skinnyWars || module.getLibDir() == null ) ) { changeManifestClasspath( module, destinationFile, javaEEVersion ); } From c926ab02ea8507315d94c894485677477e12e98b Mon Sep 17 00:00:00 2001 From: Marat Abrarov Date: Sun, 4 Oct 2020 01:31:32 +0300 Subject: [PATCH 03/13] [MEAR-267] - Performance optimization for the case when EAR module manifest has no Class-Path entry --- src/main/java/org/apache/maven/plugins/ear/EarMojo.java | 4 ++++ 1 file changed, 4 insertions(+) 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 327d799a..db9f0ad2 100644 --- a/src/main/java/org/apache/maven/plugins/ear/EarMojo.java +++ b/src/main/java/org/apache/maven/plugins/ear/EarMojo.java @@ -971,6 +971,10 @@ private void deleteOutdatedResources( final Collection outdatedResources */ private int findModuleInClassPathElements( final List classPathElements, final JarModule module ) { + if ( classPathElements.isEmpty() ) + { + return -1; + } int moduleClassPathIndex = classPathElements.indexOf( module.getBundleFileName() ); if ( moduleClassPathIndex != -1 ) { From a05d1f827d280bd1f39aa7c1a7837575f32b3dc6 Mon Sep 17 00:00:00 2001 From: Marat Abrarov Date: Sun, 4 Oct 2020 06:50:12 +0300 Subject: [PATCH 04/13] [MEAR-267] - Integration tests --- pom.xml | 14 ++- .../plugins/ear/it/AbstractEarPluginIT.java | 118 ++++++++++++++++-- .../maven/plugins/ear/it/EarMojoIT.java | 65 +++++++++- .../ear/expected-META-INF/application.xml | 32 +++++ .../projects/project-089/ear/pom.xml | 67 ++++++++++ .../projects/project-089/ejb/pom.xml | 55 ++++++++ .../ejb/src/main/java/eartest/Stub.java | 22 ++++ .../resources/projects/project-089/pom.xml | 92 ++++++++++++++ .../projects/project-089/war/pom.xml | 54 ++++++++ .../war/src/main/webapp/WEB-INF/web.xml | 24 ++++ .../ear/expected-META-INF/application.xml | 32 +++++ .../projects/project-090/ear/pom.xml | 68 ++++++++++ .../projects/project-090/ejb/pom.xml | 55 ++++++++ .../ejb/src/main/java/eartest/Stub.java | 22 ++++ .../resources/projects/project-090/pom.xml | 92 ++++++++++++++ .../projects/project-090/war/pom.xml | 54 ++++++++ .../war/src/main/webapp/WEB-INF/web.xml | 24 ++++ .../ear/expected-META-INF/application.xml | 31 +++++ .../projects/project-091/ear/pom.xml | 55 ++++++++ .../projects/project-091/ejb/pom.xml | 55 ++++++++ .../ejb/src/main/java/eartest/Stub.java | 22 ++++ .../resources/projects/project-091/pom.xml | 80 ++++++++++++ .../projects/project-091/war/pom.xml | 54 ++++++++ .../war/src/main/webapp/WEB-INF/web.xml | 24 ++++ 24 files changed, 1192 insertions(+), 19 deletions(-) create mode 100644 src/test/resources/projects/project-089/ear/expected-META-INF/application.xml create mode 100644 src/test/resources/projects/project-089/ear/pom.xml create mode 100644 src/test/resources/projects/project-089/ejb/pom.xml create mode 100644 src/test/resources/projects/project-089/ejb/src/main/java/eartest/Stub.java create mode 100644 src/test/resources/projects/project-089/pom.xml create mode 100644 src/test/resources/projects/project-089/war/pom.xml create mode 100644 src/test/resources/projects/project-089/war/src/main/webapp/WEB-INF/web.xml create mode 100644 src/test/resources/projects/project-090/ear/expected-META-INF/application.xml create mode 100644 src/test/resources/projects/project-090/ear/pom.xml create mode 100644 src/test/resources/projects/project-090/ejb/pom.xml create mode 100644 src/test/resources/projects/project-090/ejb/src/main/java/eartest/Stub.java create mode 100644 src/test/resources/projects/project-090/pom.xml create mode 100644 src/test/resources/projects/project-090/war/pom.xml create mode 100644 src/test/resources/projects/project-090/war/src/main/webapp/WEB-INF/web.xml create mode 100644 src/test/resources/projects/project-091/ear/expected-META-INF/application.xml create mode 100644 src/test/resources/projects/project-091/ear/pom.xml create mode 100644 src/test/resources/projects/project-091/ejb/pom.xml create mode 100644 src/test/resources/projects/project-091/ejb/src/main/java/eartest/Stub.java create mode 100644 src/test/resources/projects/project-091/pom.xml create mode 100644 src/test/resources/projects/project-091/war/pom.xml create mode 100644 src/test/resources/projects/project-091/war/src/main/webapp/WEB-INF/web.xml diff --git a/pom.xml b/pom.xml index fe5def04..7527f4b2 100644 --- a/pom.xml +++ b/pom.xml @@ -86,6 +86,12 @@ 7 2.22.2 2020-09-26T20:10:30Z + 2.1.1 + 2.5.1 + 2.3 + false + ${invoker.skip} + ${invoker.skip} @@ -280,10 +286,12 @@ package - org.apache.maven.plugins:maven-war-plugin:2.1.1:jar - org.apache.maven.plugins:maven-compiler-plugin:2.5.1:jar - org.apache.maven.plugins:maven-ejb-plugin:2.3:jar + org.apache.maven.plugins:maven-war-plugin:${mavenWarPluginVersion}:jar + org.apache.maven.plugins:maven-compiler-plugin:${mavenCompilerPluginVersion}:jar + org.apache.maven.plugins:maven-ejb-plugin:${mavenEjbPluginVersion}:jar + ${invoker.install.skip} + ${invoker.it.skip} diff --git a/src/test/java/org/apache/maven/plugins/ear/it/AbstractEarPluginIT.java b/src/test/java/org/apache/maven/plugins/ear/it/AbstractEarPluginIT.java index d30599f1..8b3be9da 100644 --- a/src/test/java/org/apache/maven/plugins/ear/it/AbstractEarPluginIT.java +++ b/src/test/java/org/apache/maven/plugins/ear/it/AbstractEarPluginIT.java @@ -22,10 +22,15 @@ import java.io.File; import java.io.FilenameFilter; import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Properties; +import java.util.jar.JarFile; +import java.util.jar.JarInputStream; +import java.util.jar.Manifest; +import java.util.zip.ZipEntry; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -39,6 +44,7 @@ import org.apache.maven.plugins.ear.util.ResourceEntityResolver; import org.custommonkey.xmlunit.Diff; import org.custommonkey.xmlunit.XMLAssert; +import org.junit.Assert; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; @@ -68,14 +74,17 @@ public abstract class AbstractEarPluginIT * @param projectName the name of the project * @param properties extra properties to be used by the embedder * @param expectNoError true/false + * @param cleanBeforeExecute call clean plugin before execution * @return the base directory of the project */ - protected File executeMojo( final String projectName, final Properties properties, boolean expectNoError ) throws VerificationException, IOException + protected File executeMojo( final String projectName, final Properties properties, boolean expectNoError, + boolean cleanBeforeExecute ) throws VerificationException, IOException { System.out.println( " Building: " + projectName ); File testDir = getTestDir( projectName ); Verifier verifier = new Verifier( testDir.getAbsolutePath() ); + verifier.setAutoclean( cleanBeforeExecute ); // Let's add alternate settings.xml setting so that the latest dependencies are used String localRepo = System.getProperty( "localRepositoryPath" ); verifier.setLocalRepo( localRepo ); @@ -119,31 +128,109 @@ protected File executeMojo( final String projectName, final Properties propertie protected File executeMojo( final String projectName, final Properties properties ) throws VerificationException, IOException { - return executeMojo( projectName, properties, true ); + return executeMojo( projectName, properties, true, true ); } /** * Executes the specified projects and asserts the given artifacts. Assert the deployment descriptors are valid - * + * * @param projectName the project to test + * @param earModuleName the name of 1st level EAR module in multi-module project or null if project is single-module * @param expectedArtifacts the list of artifacts to be found in the EAR archive * @param artifactsDirectory whether the artifact is an exploded artifactsDirectory or not + * @param cleanBeforeExecute call clean plugin before execution * @return the base directory of the project */ - protected File doTestProject( final String projectName, final String[] expectedArtifacts, - final boolean[] artifactsDirectory ) + protected File doTestProject( final String projectName, final String earModuleName, final String[] expectedArtifacts, + final boolean[] artifactsDirectory, boolean cleanBeforeExecute ) throws VerificationException, IOException { - final File baseDir = executeMojo( projectName, new Properties() ); - assertEarArchive( baseDir, projectName ); - assertEarDirectory( baseDir, projectName ); - - assertArchiveContent( baseDir, projectName, expectedArtifacts, artifactsDirectory ); - - assertDeploymentDescriptors( baseDir, projectName ); - + final File baseDir = executeMojo( projectName, new Properties(), true, cleanBeforeExecute ); + final File earDir = getEarModuleDirectory( baseDir, earModuleName ); + assertEarArchive( earDir, projectName ); + assertEarDirectory( earDir, projectName ); + + assertArchiveContent( earDir, projectName, expectedArtifacts, artifactsDirectory ); + + assertDeploymentDescriptors( earDir, projectName ); + return baseDir; + } + + /** + * Executes the specified projects and asserts the given artifacts. Asserts the deployment descriptors are valid. + * Asserts Class-Path entry of manifest of EAR modules. + * + * @param projectName the project to test + * @param earModuleName the name of 1st level EAR module in multi-module project or null if project is single-module + * @param expectedArtifacts the list of artifacts to be found in the EAR archive + * @param moduleArtifacts the list of artifacts representing EAR modules which manifest needs to be asserted + * @param expectedClassPathElements the list of elements of Class-Path entry of manifest. Rows should match + * modules passed in {@code moduleArtifacts} parameter + * @return the base directory of the project + */ + protected File doTestProject( final String projectName, final String earModuleName, final String[] expectedArtifacts, + final String[] moduleArtifacts, final String[][] expectedClassPathElements ) + throws VerificationException, IOException + { + assertEquals( "Rows of expectedClassPathElements parameter should match items of moduleArtifacts parameter", + moduleArtifacts.length, expectedClassPathElements.length ); + + final File baseDir = doTestProject( projectName, earModuleName, expectedArtifacts, new boolean[expectedArtifacts.length], true ); + + final File earFile = getEarArchive( getEarModuleDirectory( baseDir, earModuleName ), projectName ); + for ( int i = 0; i != moduleArtifacts.length; ++i ) + { + final String moduleArtifact = moduleArtifacts[i]; + Assert.assertArrayEquals( "Wrong elements of Class-Path entry of module [" + moduleArtifact + "] manifest", + expectedClassPathElements[i], getClassPathElements( earFile, moduleArtifact ) ); + } + return baseDir; + } + + /** + * Extracts elements of Class-Path entry of manifest of given EAR module. + * + * @param earFile the EAR file to investigate + * @param moduleArtifact the name of artifact in EAR representing EAR module + * @return elements of Class-Path entry of manifest of EAR module which is represented by + * {@code moduleArtifact} artifact in {@code earFile} file + */ + protected String[] getClassPathElements( final File earFile, final String moduleArtifact ) throws IOException + { + try ( JarFile earJarFile = new JarFile( earFile ) ) + { + final ZipEntry moduleEntry = earJarFile.getEntry( moduleArtifact ); + assertNotNull( "Artifact [" + moduleArtifact + "] should exist in EAR", moduleEntry ); + try ( InputStream moduleInputStream = earJarFile.getInputStream( moduleEntry ); + JarInputStream moduleJarInputStream = new JarInputStream( moduleInputStream ) ) + { + final Manifest manifest = moduleJarInputStream.getManifest(); + assertNotNull( "Artifact [" + moduleArtifact + "] of EAR should have manifest", manifest ); + final String classPath = manifest.getMainAttributes().getValue( "Class-Path" ); + if ( classPath == null ) + { + return new String[0]; + } + return classPath.split( " " ); + } + } + } + + /** + * Executes the specified projects and asserts the given artifacts. Assert the deployment descriptors are valid + * + * @param projectName the project to test + * @param expectedArtifacts the list of artifacts to be found in the EAR archive + * @param artifactsDirectory whether the artifact is an exploded artifactsDirectory or not + * @return the base directory of the project + */ + protected File doTestProject( final String projectName, final String[] expectedArtifacts, + final boolean[] artifactsDirectory ) + throws VerificationException, IOException + { + return doTestProject( projectName, null, expectedArtifacts, artifactsDirectory, true ); } /** @@ -186,6 +273,11 @@ protected void assertEarDirectory( final File baseDir, final String projectName assertTrue( "EAR archive directory does not exist", getEarDirectory( baseDir, projectName ).exists() ); } + protected File getEarModuleDirectory( final File baseDir, final String earModuleName) + { + return earModuleName == null ? baseDir : new File( baseDir, earModuleName ); + } + protected File getTargetDirectory( final File basedir ) { return new File( basedir, "target" ); diff --git a/src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java b/src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java index fb1e5f53..dce9ed7f 100644 --- a/src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java +++ b/src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java @@ -203,8 +203,7 @@ public void testProject016() { final File baseDir = doTestProject( "project-016", new String[] { "eartest-ejb-sample-one-1.0.jar" } ); - final File targetFolder = new File( baseDir, "target" ); - final File createdEarFile = new File( targetFolder, "maven-ear-plugin-test-project-016-99.0.ear" ); + final File createdEarFile = getEarArchive( baseDir, "project-016" ); final File sourceManifestFile = new File( baseDir, "src/main/ear/MANIFEST.MF" ); @@ -332,7 +331,7 @@ public void testProject025() public void testProject026() throws Exception { - final File baseDir = executeMojo( "project-026", new Properties(), false ); + final File baseDir = executeMojo( "project-026", new Properties(), false, true ); // Stupido, checks that the ear archive is not there assertFalse( "Execution should have failed", getEarArchive( baseDir, "project-026" ).exists() ); } @@ -993,4 +992,64 @@ public void testProject087() { doTestProject( "project-087", new String[] { "eartest-ejb-sample-one-1.0.jar", "eartest-ejb-sample-two-1.0.jar" } ); } + + /** + * Validates modification of Class-Path entry of EAR modules manifest when + *
    + *
  • skinnyWars option is turned on
  • + *
  • skipClassPathModification option is turned off
  • + *
+ *
  • skinnyWars option is turned on
  • + *
  • skipClassPathModification option is turned on
  • + * + *
  • skinnyWars option is turned off
  • + *
  • skipClassPathModification option is turned off
  • + * + + + maven-ear-plugin-test-project-089 + + + eartest-war-sample-three-1.0.war + /war-sample-three + + + + eartest-ejb-sample-three-1.0.jar + + lib + diff --git a/src/test/resources/projects/project-089/ear/pom.xml b/src/test/resources/projects/project-089/ear/pom.xml new file mode 100644 index 00000000..7bdd2448 --- /dev/null +++ b/src/test/resources/projects/project-089/ear/pom.xml @@ -0,0 +1,67 @@ + + + + + 4.0.0 + + ear + maven-ear-plugin-test-project-089-parent + 99.0 + + maven-ear-plugin-test-project-089 + ear + + + eartest + war-sample-three + war + + + eartest + war-sample-three + pom + + + eartest + ejb-sample-three + ejb + + + eartest + ejb-sample-three + pom + + + + + + org.apache.maven.plugins + maven-ear-plugin + @project.version@ + + 6 + lib + true + + + + + diff --git a/src/test/resources/projects/project-089/ejb/pom.xml b/src/test/resources/projects/project-089/ejb/pom.xml new file mode 100644 index 00000000..328f5d2d --- /dev/null +++ b/src/test/resources/projects/project-089/ejb/pom.xml @@ -0,0 +1,55 @@ + + + + + 4.0.0 + + ear + maven-ear-plugin-test-project-089-parent + 99.0 + + eartest + ejb-sample-three + 1.0 + ejb + + + eartest + jar-sample-three-with-deps + + + + + + org.apache.maven.plugins + maven-ejb-plugin + + 3.1 + + + true + + + + + + + diff --git a/src/test/resources/projects/project-089/ejb/src/main/java/eartest/Stub.java b/src/test/resources/projects/project-089/ejb/src/main/java/eartest/Stub.java new file mode 100644 index 00000000..b8b0059c --- /dev/null +++ b/src/test/resources/projects/project-089/ejb/src/main/java/eartest/Stub.java @@ -0,0 +1,22 @@ +package eartest; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +public class Stub {} diff --git a/src/test/resources/projects/project-089/pom.xml b/src/test/resources/projects/project-089/pom.xml new file mode 100644 index 00000000..f9f04b19 --- /dev/null +++ b/src/test/resources/projects/project-089/pom.xml @@ -0,0 +1,92 @@ + + + + + 4.0.0 + ear + maven-ear-plugin-test-project-089-parent + 99.0 + pom + + war + ejb + ear + + + + + eartest + jar-sample-two + 1.0 + + + eartest + jar-sample-three-with-deps + 1.0 + + + eartest + war-sample-three + 1.0 + war + + + eartest + war-sample-three + 1.0 + pom + + + eartest + ejb-sample-three + 1.0 + ejb + + + eartest + ejb-sample-three + 1.0 + pom + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + @mavenCompilerPluginVersion@ + + + org.apache.maven.plugins + maven-war-plugin + @mavenWarPluginVersion@ + + + org.apache.maven.plugins + maven-ejb-plugin + @mavenEjbPluginVersion@ + + + + + diff --git a/src/test/resources/projects/project-089/war/pom.xml b/src/test/resources/projects/project-089/war/pom.xml new file mode 100644 index 00000000..860fcf4c --- /dev/null +++ b/src/test/resources/projects/project-089/war/pom.xml @@ -0,0 +1,54 @@ + + + + + 4.0.0 + + ear + maven-ear-plugin-test-project-089-parent + 99.0 + + eartest + war-sample-three + 1.0 + war + + + eartest + jar-sample-two + + + + + + org.apache.maven.plugins + maven-war-plugin + + + + true + + + + + + + diff --git a/src/test/resources/projects/project-089/war/src/main/webapp/WEB-INF/web.xml b/src/test/resources/projects/project-089/war/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000..fbbf3070 --- /dev/null +++ b/src/test/resources/projects/project-089/war/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,24 @@ + + + + diff --git a/src/test/resources/projects/project-090/ear/expected-META-INF/application.xml b/src/test/resources/projects/project-090/ear/expected-META-INF/application.xml new file mode 100644 index 00000000..c3b3c3f9 --- /dev/null +++ b/src/test/resources/projects/project-090/ear/expected-META-INF/application.xml @@ -0,0 +1,32 @@ + + + + maven-ear-plugin-test-project-090 + + + eartest-war-sample-three-1.0.war + /war-sample-three + + + + eartest-ejb-sample-three-1.0.jar + + lib + diff --git a/src/test/resources/projects/project-090/ear/pom.xml b/src/test/resources/projects/project-090/ear/pom.xml new file mode 100644 index 00000000..655f1a2e --- /dev/null +++ b/src/test/resources/projects/project-090/ear/pom.xml @@ -0,0 +1,68 @@ + + + + + 4.0.0 + + ear + maven-ear-plugin-test-project-090-parent + 99.0 + + maven-ear-plugin-test-project-090 + ear + + + eartest + war-sample-three + war + + + eartest + war-sample-three + pom + + + eartest + ejb-sample-three + ejb + + + eartest + ejb-sample-three + pom + + + + + + org.apache.maven.plugins + maven-ear-plugin + @project.version@ + + 6 + lib + true + true + + + + + diff --git a/src/test/resources/projects/project-090/ejb/pom.xml b/src/test/resources/projects/project-090/ejb/pom.xml new file mode 100644 index 00000000..772fa09c --- /dev/null +++ b/src/test/resources/projects/project-090/ejb/pom.xml @@ -0,0 +1,55 @@ + + + + + 4.0.0 + + ear + maven-ear-plugin-test-project-090-parent + 99.0 + + eartest + ejb-sample-three + 1.0 + ejb + + + eartest + jar-sample-three-with-deps + + + + + + org.apache.maven.plugins + maven-ejb-plugin + + 3.1 + + + true + + + + + + + diff --git a/src/test/resources/projects/project-090/ejb/src/main/java/eartest/Stub.java b/src/test/resources/projects/project-090/ejb/src/main/java/eartest/Stub.java new file mode 100644 index 00000000..b8b0059c --- /dev/null +++ b/src/test/resources/projects/project-090/ejb/src/main/java/eartest/Stub.java @@ -0,0 +1,22 @@ +package eartest; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +public class Stub {} diff --git a/src/test/resources/projects/project-090/pom.xml b/src/test/resources/projects/project-090/pom.xml new file mode 100644 index 00000000..e4672144 --- /dev/null +++ b/src/test/resources/projects/project-090/pom.xml @@ -0,0 +1,92 @@ + + + + + 4.0.0 + ear + maven-ear-plugin-test-project-090-parent + 99.0 + pom + + war + ejb + ear + + + + + eartest + jar-sample-two + 1.0 + + + eartest + jar-sample-three-with-deps + 1.0 + + + eartest + war-sample-three + 1.0 + war + + + eartest + war-sample-three + 1.0 + pom + + + eartest + ejb-sample-three + 1.0 + ejb + + + eartest + ejb-sample-three + 1.0 + pom + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + @mavenCompilerPluginVersion@ + + + org.apache.maven.plugins + maven-war-plugin + @mavenWarPluginVersion@ + + + org.apache.maven.plugins + maven-ejb-plugin + @mavenEjbPluginVersion@ + + + + + diff --git a/src/test/resources/projects/project-090/war/pom.xml b/src/test/resources/projects/project-090/war/pom.xml new file mode 100644 index 00000000..8314bdc1 --- /dev/null +++ b/src/test/resources/projects/project-090/war/pom.xml @@ -0,0 +1,54 @@ + + + + + 4.0.0 + + ear + maven-ear-plugin-test-project-090-parent + 99.0 + + eartest + war-sample-three + 1.0 + war + + + eartest + jar-sample-two + + + + + + org.apache.maven.plugins + maven-war-plugin + + + + true + + + + + + + diff --git a/src/test/resources/projects/project-090/war/src/main/webapp/WEB-INF/web.xml b/src/test/resources/projects/project-090/war/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000..fbbf3070 --- /dev/null +++ b/src/test/resources/projects/project-090/war/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,24 @@ + + + + diff --git a/src/test/resources/projects/project-091/ear/expected-META-INF/application.xml b/src/test/resources/projects/project-091/ear/expected-META-INF/application.xml new file mode 100644 index 00000000..5ad9ffc0 --- /dev/null +++ b/src/test/resources/projects/project-091/ear/expected-META-INF/application.xml @@ -0,0 +1,31 @@ + + + + maven-ear-plugin-test-project-091 + + + eartest-war-sample-three-1.0.war + /war-sample-three + + + + eartest-ejb-sample-three-1.0.jar + + diff --git a/src/test/resources/projects/project-091/ear/pom.xml b/src/test/resources/projects/project-091/ear/pom.xml new file mode 100644 index 00000000..40bc28af --- /dev/null +++ b/src/test/resources/projects/project-091/ear/pom.xml @@ -0,0 +1,55 @@ + + + + + 4.0.0 + + ear + maven-ear-plugin-test-project-091-parent + 99.0 + + maven-ear-plugin-test-project-091 + ear + + + eartest + war-sample-three + war + + + eartest + ejb-sample-three + ejb + + + + + + org.apache.maven.plugins + maven-ear-plugin + @project.version@ + + 6 + + + + + diff --git a/src/test/resources/projects/project-091/ejb/pom.xml b/src/test/resources/projects/project-091/ejb/pom.xml new file mode 100644 index 00000000..47028134 --- /dev/null +++ b/src/test/resources/projects/project-091/ejb/pom.xml @@ -0,0 +1,55 @@ + + + + + 4.0.0 + + ear + maven-ear-plugin-test-project-091-parent + 99.0 + + eartest + ejb-sample-three + 1.0 + ejb + + + eartest + jar-sample-three-with-deps + + + + + + org.apache.maven.plugins + maven-ejb-plugin + + 3.1 + + + true + + + + + + + diff --git a/src/test/resources/projects/project-091/ejb/src/main/java/eartest/Stub.java b/src/test/resources/projects/project-091/ejb/src/main/java/eartest/Stub.java new file mode 100644 index 00000000..b8b0059c --- /dev/null +++ b/src/test/resources/projects/project-091/ejb/src/main/java/eartest/Stub.java @@ -0,0 +1,22 @@ +package eartest; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +public class Stub {} diff --git a/src/test/resources/projects/project-091/pom.xml b/src/test/resources/projects/project-091/pom.xml new file mode 100644 index 00000000..efae418e --- /dev/null +++ b/src/test/resources/projects/project-091/pom.xml @@ -0,0 +1,80 @@ + + + + + 4.0.0 + ear + maven-ear-plugin-test-project-091-parent + 99.0 + pom + + war + ejb + ear + + + + + eartest + jar-sample-two + 1.0 + + + eartest + jar-sample-three-with-deps + 1.0 + + + eartest + war-sample-three + 1.0 + war + + + eartest + ejb-sample-three + 1.0 + ejb + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + @mavenCompilerPluginVersion@ + + + org.apache.maven.plugins + maven-war-plugin + @mavenWarPluginVersion@ + + + org.apache.maven.plugins + maven-ejb-plugin + @mavenEjbPluginVersion@ + + + + + diff --git a/src/test/resources/projects/project-091/war/pom.xml b/src/test/resources/projects/project-091/war/pom.xml new file mode 100644 index 00000000..30017872 --- /dev/null +++ b/src/test/resources/projects/project-091/war/pom.xml @@ -0,0 +1,54 @@ + + + + + 4.0.0 + + ear + maven-ear-plugin-test-project-091-parent + 99.0 + + eartest + war-sample-three + 1.0 + war + + + eartest + jar-sample-two + + + + + + org.apache.maven.plugins + maven-war-plugin + + + + true + + + + + + + diff --git a/src/test/resources/projects/project-091/war/src/main/webapp/WEB-INF/web.xml b/src/test/resources/projects/project-091/war/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000..fbbf3070 --- /dev/null +++ b/src/test/resources/projects/project-091/war/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,24 @@ + + + + From 3c34038cd5e4f4847d1c671c5f4e58cce73d831c Mon Sep 17 00:00:00 2001 From: Marat Abrarov Date: Sun, 4 Oct 2020 07:58:30 +0300 Subject: [PATCH 05/13] [MEAR-267] - The same rules applied to modification of Class-Path manifest entry as used for removal of JAR modules from EAR modules --- .../org/apache/maven/plugins/ear/EarMojo.java | 51 ++++--------------- 1 file changed, 11 insertions(+), 40 deletions(-) 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 db9f0ad2..11228913 100644 --- a/src/main/java/org/apache/maven/plugins/ear/EarMojo.java +++ b/src/main/java/org/apache/maven/plugins/ear/EarMojo.java @@ -40,7 +40,6 @@ import org.apache.maven.archiver.MavenArchiveConfiguration; import org.apache.maven.archiver.MavenArchiver; -import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecutionException; @@ -57,7 +56,6 @@ import org.apache.maven.shared.filtering.MavenFilteringException; import org.apache.maven.shared.filtering.MavenResourcesExecution; import org.apache.maven.shared.filtering.MavenResourcesFiltering; -import org.apache.maven.shared.mapping.MappingUtils; import org.apache.maven.shared.utils.io.FileUtils; import org.codehaus.plexus.archiver.Archiver; import org.codehaus.plexus.archiver.ArchiverException; @@ -72,7 +70,6 @@ import org.codehaus.plexus.archiver.zip.ZipArchiver; import org.codehaus.plexus.archiver.zip.ZipUnArchiver; import org.codehaus.plexus.components.io.filemappers.FileMapper; -import org.codehaus.plexus.interpolation.InterpolationException; import org.codehaus.plexus.util.DirectoryScanner; import org.codehaus.plexus.util.StringUtils; @@ -87,16 +84,6 @@ public class EarMojo extends AbstractEarMojo { - /** - * File name mappings which can be used by elements of Class-Path manifest entry of EAR modules to identify if - * classpath element matches particular EAR module. - */ - private static final List CLASSPATH_ELEMENT_FILE_NAME_MAPPINGS = Arrays.asList( - "@{artifactId}@-@{version}@@{dashClassifier?}@.@{extension}@", - "@{groupId}@-@{artifactId}@-@{version}@@{dashClassifier?}@.@{extension}@", - "@{artifactId}@-@{baseVersion}@@{dashClassifier?}@.@{extension}@", - "@{groupId}@-@{artifactId}@-@{baseVersion}@@{dashClassifier?}@.@{extension}@" ); - /** * Single directory for extra files to include in the EAR. */ @@ -819,8 +806,8 @@ private void changeManifestClasspath( EarModule module, File original, JavaEEVer // We use the original name, cause in case of outputFileNameMapping // we could not not delete it and it will end up in the resulting EAR and the WAR // will not be cleaned up. - File artifact = new File( new File( workDirectory, module.getLibDir() ), - module.getArtifact().getFile().getName() ); + final File workLibDir = new File( workDirectory, module.getLibDir() ); + File artifact = new File( workLibDir, getArtifactFileName( module ) ); // MEAR-217 // If WAR contains files with timestamps, but EAR strips them away (useBaseVersion=true) @@ -829,16 +816,15 @@ private void changeManifestClasspath( EarModule module, File original, JavaEEVer if ( !artifact.exists() ) { getLog().debug( "module does not exist with original file name." ); - artifact = new File( new File( workDirectory, module.getLibDir() ), jm.getBundleFileName() ); + artifact = new File( workLibDir, jm.getBundleFileName() ); getLog().debug( "Artifact with mapping:" + artifact.getAbsolutePath() ); } if ( !artifact.exists() ) { getLog().debug( "Artifact with mapping does not exist." ); - artifact = new File( new File( workDirectory, module.getLibDir() ), - jm.getArtifact().getFile().getName() ); - getLog().debug( "Artifact with orignal file name:" + artifact.getAbsolutePath() ); + artifact = new File( workLibDir, getArtifactFileName( jm ) ); + getLog().debug( "Artifact with original file name:" + artifact.getAbsolutePath() ); } if ( artifact.exists() ) @@ -980,26 +966,11 @@ private int findModuleInClassPathElements( final List classPathElements, { return moduleClassPathIndex; } - // Check the case when classpath entry uses some of default file name mappings - // instead of file name mapping configured for EAR plugin - final Artifact artifact = module.getArtifact(); - for ( String fileNameMapping : CLASSPATH_ELEMENT_FILE_NAME_MAPPINGS ) - { - try - { - final String bundleFileName = MappingUtils.evaluateFileNameMapping( fileNameMapping, artifact ); - moduleClassPathIndex = classPathElements.indexOf( bundleFileName ); - if ( moduleClassPathIndex != -1 ) - { - return moduleClassPathIndex; - } - } - catch ( InterpolationException e ) - { - getLog().warn( "Failed to build bundle file name for artifact [" + module - + "] using file name mapping: " + fileNameMapping, e ); - } - } - return -1; + return classPathElements.indexOf( getArtifactFileName( module ) ); + } + + private String getArtifactFileName( final EarModule module ) + { + return module.getArtifact().getFile().getName(); } } From d7ec060678c86b5191551d2edeed6064195eee9b Mon Sep 17 00:00:00 2001 From: Marat Abrarov Date: Sun, 4 Oct 2020 15:43:03 +0300 Subject: [PATCH 06/13] [MEAR-267] - Fixed formatting of JavaDoc in tests --- .../java/org/apache/maven/plugins/ear/it/EarMojoIT.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java b/src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java index dce9ed7f..b5883a81 100644 --- a/src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java +++ b/src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java @@ -998,7 +998,7 @@ public void testProject087() *
      *
    • skinnyWars option is turned on
    • *
    • skipClassPathModification option is turned off
    • - *
    */ public void testProject089() throws Exception @@ -1018,7 +1018,7 @@ public void testProject089() *
      *
    • skinnyWars option is turned on
    • *
    • skipClassPathModification option is turned on
    • - *
    */ public void testProject090() throws Exception @@ -1038,7 +1038,7 @@ public void testProject090() *
      *
    • skinnyWars option is turned off
    • *
    • skipClassPathModification option is turned off
    • - *
    */ public void testProject091() throws Exception From a8e582699c3da34eaeccc5970f1c7c875c934305 Mon Sep 17 00:00:00 2001 From: Marat Abrarov Date: Mon, 5 Oct 2020 15:51:22 +0300 Subject: [PATCH 07/13] [MEAR-267] - Test for the case when unpacking of EJB JARs is turned on --- .../plugins/ear/it/AbstractEarPluginIT.java | 184 +++++++++--------- .../maven/plugins/ear/it/EarMojoIT.java | 16 +- .../projects/project-091/ear/pom.xml | 1 + 3 files changed, 109 insertions(+), 92 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/ear/it/AbstractEarPluginIT.java b/src/test/java/org/apache/maven/plugins/ear/it/AbstractEarPluginIT.java index 8b3be9da..b1915cef 100644 --- a/src/test/java/org/apache/maven/plugins/ear/it/AbstractEarPluginIT.java +++ b/src/test/java/org/apache/maven/plugins/ear/it/AbstractEarPluginIT.java @@ -131,32 +131,6 @@ protected File executeMojo( final String projectName, final Properties propertie return executeMojo( projectName, properties, true, true ); } - /** - * Executes the specified projects and asserts the given artifacts. Assert the deployment descriptors are valid - * - * @param projectName the project to test - * @param earModuleName the name of 1st level EAR module in multi-module project or null if project is single-module - * @param expectedArtifacts the list of artifacts to be found in the EAR archive - * @param artifactsDirectory whether the artifact is an exploded artifactsDirectory or not - * @param cleanBeforeExecute call clean plugin before execution - * @return the base directory of the project - */ - protected File doTestProject( final String projectName, final String earModuleName, final String[] expectedArtifacts, - final boolean[] artifactsDirectory, boolean cleanBeforeExecute ) - throws VerificationException, IOException - { - final File baseDir = executeMojo( projectName, new Properties(), true, cleanBeforeExecute ); - final File earDir = getEarModuleDirectory( baseDir, earModuleName ); - assertEarArchive( earDir, projectName ); - assertEarDirectory( earDir, projectName ); - - assertArchiveContent( earDir, projectName, expectedArtifacts, artifactsDirectory ); - - assertDeploymentDescriptors( earDir, projectName ); - - return baseDir; - } - /** * Executes the specified projects and asserts the given artifacts. Asserts the deployment descriptors are valid. * Asserts Class-Path entry of manifest of EAR modules. @@ -164,60 +138,36 @@ protected File doTestProject( final String projectName, final String earModuleNa * @param projectName the project to test * @param earModuleName the name of 1st level EAR module in multi-module project or null if project is single-module * @param expectedArtifacts the list of artifacts to be found in the EAR archive - * @param moduleArtifacts the list of artifacts representing EAR modules which manifest needs to be asserted + * @param artifactsDirectory whether the artifact is an exploded artifactsDirectory or not + * @param moduleArtifacts the list of artifacts representing EAR modules which manifest needs to be asserted or + * {@code null} if there is no need to validate Class-Path entry of EAR modules manifests + * @param moduleArtifactsDirectory whether the artifact from {@code moduleArtifacts} list is an exploded or not. + * Can be {@code null} if {@code moduleArtifacts} is {@code null} * @param expectedClassPathElements the list of elements of Class-Path entry of manifest. Rows should match - * modules passed in {@code moduleArtifacts} parameter + * modules passed in {@code moduleArtifacts} parameter. Can be {@code null} if + * {@code moduleArtifacts} is {@code null} + * @param cleanBeforeExecute call clean plugin before execution * @return the base directory of the project */ - protected File doTestProject( final String projectName, final String earModuleName, final String[] expectedArtifacts, - final String[] moduleArtifacts, final String[][] expectedClassPathElements ) + protected File doTestProject( final String projectName, final String earModuleName, + final String[] expectedArtifacts, boolean[] artifactsDirectory, + final String[] moduleArtifacts, boolean[] moduleArtifactsDirectory, + final String[][] expectedClassPathElements, + final boolean cleanBeforeExecute ) throws VerificationException, IOException { - assertEquals( "Rows of expectedClassPathElements parameter should match items of moduleArtifacts parameter", - moduleArtifacts.length, expectedClassPathElements.length ); - - final File baseDir = doTestProject( projectName, earModuleName, expectedArtifacts, new boolean[expectedArtifacts.length], true ); + final File baseDir = executeMojo( projectName, new Properties(), true, cleanBeforeExecute ); - final File earFile = getEarArchive( getEarModuleDirectory( baseDir, earModuleName ), projectName ); - for ( int i = 0; i != moduleArtifacts.length; ++i ) - { - final String moduleArtifact = moduleArtifacts[i]; - Assert.assertArrayEquals( "Wrong elements of Class-Path entry of module [" + moduleArtifact + "] manifest", - expectedClassPathElements[i], getClassPathElements( earFile, moduleArtifact ) ); - } + final File earModuleDir = getEarModuleDirectory( baseDir, earModuleName ); + assertEarArchive( earModuleDir, projectName ); + assertEarDirectory( earModuleDir, projectName ); + assertArchiveContent( earModuleDir, projectName, expectedArtifacts, artifactsDirectory ); + assertDeploymentDescriptors( earModuleDir, projectName ); + assertClassPathElements( earModuleDir, projectName, moduleArtifacts, moduleArtifactsDirectory, expectedClassPathElements ); return baseDir; } - /** - * Extracts elements of Class-Path entry of manifest of given EAR module. - * - * @param earFile the EAR file to investigate - * @param moduleArtifact the name of artifact in EAR representing EAR module - * @return elements of Class-Path entry of manifest of EAR module which is represented by - * {@code moduleArtifact} artifact in {@code earFile} file - */ - protected String[] getClassPathElements( final File earFile, final String moduleArtifact ) throws IOException - { - try ( JarFile earJarFile = new JarFile( earFile ) ) - { - final ZipEntry moduleEntry = earJarFile.getEntry( moduleArtifact ); - assertNotNull( "Artifact [" + moduleArtifact + "] should exist in EAR", moduleEntry ); - try ( InputStream moduleInputStream = earJarFile.getInputStream( moduleEntry ); - JarInputStream moduleJarInputStream = new JarInputStream( moduleInputStream ) ) - { - final Manifest manifest = moduleJarInputStream.getManifest(); - assertNotNull( "Artifact [" + moduleArtifact + "] of EAR should have manifest", manifest ); - final String classPath = manifest.getMainAttributes().getValue( "Class-Path" ); - if ( classPath == null ) - { - return new String[0]; - } - return classPath.split( " " ); - } - } - } - /** * Executes the specified projects and asserts the given artifacts. Assert the deployment descriptors are valid * @@ -230,7 +180,7 @@ protected File doTestProject( final String projectName, final String[] expectedA final boolean[] artifactsDirectory ) throws VerificationException, IOException { - return doTestProject( projectName, null, expectedArtifacts, artifactsDirectory, true ); + return doTestProject( projectName, null, expectedArtifacts, artifactsDirectory, null, null, null, true ); } /** @@ -238,31 +188,14 @@ protected File doTestProject( final String projectName, final String[] expectedA * * @param projectName the project to test * @param expectedArtifacts the list of artifacts to be found in the EAR archive - * @param testDeploymentDescriptors whether we should test deployment descriptors * @return the base directory of the project */ - private File doTestProject( final String projectName, final String[] expectedArtifacts, - boolean testDeploymentDescriptors ) + protected File doTestProject( final String projectName, final String[] expectedArtifacts ) throws VerificationException, IOException { return doTestProject( projectName, expectedArtifacts, new boolean[expectedArtifacts.length] ); } - /** - * Executes the specified projects and asserts the given artifacts as artifacts (non directory). Assert the - * deployment descriptors are valid - * - * @param projectName the project to test - * @param expectedArtifacts the list of artifacts to be found in the EAR archive - * @return the base directory of the project - * @throws Exception Mojo exception in case of an error. - */ - protected File doTestProject( final String projectName, final String[] expectedArtifacts ) - throws Exception - { - return doTestProject( projectName, expectedArtifacts, true ); - } - protected void assertEarArchive( final File baseDir, final String projectName ) { assertTrue( "EAR archive does not exist", getEarArchive( baseDir, projectName ).exists() ); @@ -476,4 +409,77 @@ public boolean accept( File dir, String name ) } } ); } + + private void assertClassPathElements( final File baseDir, String projectName, String[] moduleArtifacts, + boolean[] moduleArtifactsDirectory, String[][] expectedClassPathElements ) + throws IOException + { + if ( moduleArtifacts == null ) + { + return; + } + + assertNotNull( "moduleArtifactsDirectory should be provided if moduleArtifacts is provided", + moduleArtifactsDirectory ); + assertTrue( "Size of moduleArtifactsDirectory should match size of moduleArtifacts parameter", + moduleArtifacts.length <= moduleArtifactsDirectory.length ); + assertNotNull( "expectedClassPathElements should be provided if moduleArtifacts is provided", + expectedClassPathElements ); + assertTrue( "Rows of expectedClassPathElements parameter should match items of moduleArtifacts parameter", + moduleArtifacts.length <= expectedClassPathElements.length ); + + final File earFile = getEarArchive( baseDir, projectName ); + for ( int i = 0; i != moduleArtifacts.length; ++i ) + { + final String moduleArtifact = moduleArtifacts[i]; + Assert.assertArrayEquals( "Wrong elements of Class-Path entry of module [" + moduleArtifact + "] manifest", + expectedClassPathElements[i], + getClassPathElements( earFile, moduleArtifact, moduleArtifactsDirectory[i] ) ); + } + } + + /** + * Extracts elements of Class-Path entry of manifest of given EAR module. + * + * @param earFile the EAR file to investigate + * @param moduleArtifact the name of artifact in EAR representing EAR module + * @return elements of Class-Path entry of manifest of EAR module which is represented by + * {@code moduleArtifact} artifact in {@code earFile} file + */ + protected String[] getClassPathElements( final File earFile, final String moduleArtifact, final boolean directory ) + throws IOException + { + final String classPath; + try ( JarFile earJarFile = new JarFile( earFile ) ) + { + final ZipEntry moduleEntry = earJarFile.getEntry( moduleArtifact ); + assertNotNull( "Artifact [" + moduleArtifact + "] should exist in EAR", moduleEntry ); + if (directory) + { + final String manifestEntryName = moduleArtifact + "/META-INF/MANIFEST.MF"; + final ZipEntry manifestEntry = earJarFile.getEntry( manifestEntryName ); + assertNotNull( manifestEntryName + " manifest file should exist in EAR", manifestEntry ); + try ( InputStream manifestInputStream = earJarFile.getInputStream( manifestEntry ) ) + { + final Manifest manifest = new Manifest(manifestInputStream); + classPath = manifest.getMainAttributes().getValue( "Class-Path" ); + } + } + else + { + try ( InputStream moduleInputStream = earJarFile.getInputStream( moduleEntry ); + JarInputStream moduleJarInputStream = new JarInputStream( moduleInputStream ) ) + { + final Manifest manifest = moduleJarInputStream.getManifest(); + assertNotNull( "Artifact [" + moduleArtifact + "] of EAR should have manifest", manifest ); + classPath = manifest.getMainAttributes().getValue( "Class-Path" ); + } + } + } + if ( classPath == null ) + { + return new String[0]; + } + return classPath.split( " " ); + } } diff --git a/src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java b/src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java index b5883a81..566ab407 100644 --- a/src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java +++ b/src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java @@ -1009,8 +1009,11 @@ public void testProject089() final String jarSampleThreeArtifact = "lib/eartest-jar-sample-three-with-deps-1.0.jar"; doTestProject( "project-089", "ear", new String[] { warModuleArtifact, ejbModuleArtifact, jarSampleTwoArtifact, jarSampleThreeArtifact }, + new boolean[] { false, false, false, false}, new String[] { warModuleArtifact, ejbModuleArtifact }, - new String[][] { { jarSampleTwoArtifact, jarSampleThreeArtifact }, { jarSampleThreeArtifact, jarSampleTwoArtifact } } ); + new boolean[] { false, false }, + new String[][] { { jarSampleTwoArtifact, jarSampleThreeArtifact }, { jarSampleThreeArtifact, jarSampleTwoArtifact } }, + true ); } /** @@ -1029,8 +1032,11 @@ public void testProject090() final String jarSampleThreeArtifact = "lib/eartest-jar-sample-three-with-deps-1.0.jar"; doTestProject( "project-090", "ear", new String[] { warModuleArtifact, ejbModuleArtifact, jarSampleTwoArtifact, jarSampleThreeArtifact }, + new boolean[] { false, false, false, false }, new String[] { warModuleArtifact, ejbModuleArtifact }, - new String[][] { { jarSampleTwoArtifact }, { jarSampleThreeArtifact, jarSampleTwoArtifact } } ); + new boolean[] { false, false }, + new String[][] { { jarSampleTwoArtifact }, { jarSampleThreeArtifact, jarSampleTwoArtifact } }, + true ); } /** @@ -1038,6 +1044,7 @@ public void testProject090() *
      *
    • skinnyWars option is turned off
    • *
    • skipClassPathModification option is turned off
    • + *
    • unpacking of EJB JARs is turned on
    • *
    */ public void testProject091() @@ -1049,7 +1056,10 @@ public void testProject091() final String jarSampleThreeArtifact = "eartest-jar-sample-three-with-deps-1.0.jar"; doTestProject( "project-091", "ear", new String[] { warModuleArtifact, ejbModuleArtifact, jarSampleTwoArtifact, jarSampleThreeArtifact }, + new boolean[] { false, true, false, false }, new String[] { warModuleArtifact, ejbModuleArtifact }, - new String[][] { { "jar-sample-two-1.0.jar" }, { jarSampleThreeArtifact, jarSampleTwoArtifact } } ); + new boolean[] { false, true }, + new String[][] { { "jar-sample-two-1.0.jar" }, { jarSampleThreeArtifact, jarSampleTwoArtifact } }, + true ); } } diff --git a/src/test/resources/projects/project-091/ear/pom.xml b/src/test/resources/projects/project-091/ear/pom.xml index 40bc28af..fecde971 100644 --- a/src/test/resources/projects/project-091/ear/pom.xml +++ b/src/test/resources/projects/project-091/ear/pom.xml @@ -48,6 +48,7 @@ under the License. @project.version@ 6 + ejb
    From 97bd17774666619f4c42f990425e5101ee3be0f2 Mon Sep 17 00:00:00 2001 From: Marat Abrarov Date: Wed, 7 Oct 2020 18:52:33 +0300 Subject: [PATCH 08/13] [MEAR-267] - Renamed test method parameters and rephrased / fixed formatting of JavaDoc, inlined simple single-line code. --- .../org/apache/maven/plugins/ear/EarMojo.java | 16 ++-- .../plugins/ear/it/AbstractEarPluginIT.java | 79 +++++++++++-------- .../maven/plugins/ear/it/EarMojoIT.java | 42 +++++----- 3 files changed, 75 insertions(+), 62 deletions(-) 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 11228913..e745293a 100644 --- a/src/main/java/org/apache/maven/plugins/ear/EarMojo.java +++ b/src/main/java/org/apache/maven/plugins/ear/EarMojo.java @@ -807,7 +807,7 @@ private void changeManifestClasspath( EarModule module, File original, JavaEEVer // we could not not delete it and it will end up in the resulting EAR and the WAR // will not be cleaned up. final File workLibDir = new File( workDirectory, module.getLibDir() ); - File artifact = new File( workLibDir, getArtifactFileName( module ) ); + File artifact = new File( workLibDir, module.getArtifact().getFile().getName() ); // MEAR-217 // If WAR contains files with timestamps, but EAR strips them away (useBaseVersion=true) @@ -823,7 +823,7 @@ private void changeManifestClasspath( EarModule module, File original, JavaEEVer if ( !artifact.exists() ) { getLog().debug( "Artifact with mapping does not exist." ); - artifact = new File( workLibDir, getArtifactFileName( jm ) ); + artifact = new File( workLibDir, jm.getArtifact().getFile().getName() ); getLog().debug( "Artifact with original file name:" + artifact.getAbsolutePath() ); } @@ -948,9 +948,10 @@ private void deleteOutdatedResources( final Collection outdatedResources } /** - * Searches JAR module in the list of classpath elements. + * Searches for the given JAR module in the list of classpath elements and if found matching returns index of + * class path element matching JAR module or -1 otherwise. * - * @param classPathElements classpath elements to search among. + * @param classPathElements classpath elements to search among * @param module module to find among classpath elements defined by {@code classPathElements} * @return -1 if {@code module} was not found in {@code classPathElements} or index of item of * {@code classPathElements} which matches {@code module} @@ -966,11 +967,6 @@ private int findModuleInClassPathElements( final List classPathElements, { return moduleClassPathIndex; } - return classPathElements.indexOf( getArtifactFileName( module ) ); - } - - private String getArtifactFileName( final EarModule module ) - { - return module.getArtifact().getFile().getName(); + return classPathElements.indexOf( module.getArtifact().getFile().getName() ); } } diff --git a/src/test/java/org/apache/maven/plugins/ear/it/AbstractEarPluginIT.java b/src/test/java/org/apache/maven/plugins/ear/it/AbstractEarPluginIT.java index b1915cef..0a4fa2e2 100644 --- a/src/test/java/org/apache/maven/plugins/ear/it/AbstractEarPluginIT.java +++ b/src/test/java/org/apache/maven/plugins/ear/it/AbstractEarPluginIT.java @@ -139,19 +139,21 @@ protected File executeMojo( final String projectName, final Properties propertie * @param earModuleName the name of 1st level EAR module in multi-module project or null if project is single-module * @param expectedArtifacts the list of artifacts to be found in the EAR archive * @param artifactsDirectory whether the artifact is an exploded artifactsDirectory or not - * @param moduleArtifacts the list of artifacts representing EAR modules which manifest needs to be asserted or - * {@code null} if there is no need to validate Class-Path entry of EAR modules manifests - * @param moduleArtifactsDirectory whether the artifact from {@code moduleArtifacts} list is an exploded or not. - * Can be {@code null} if {@code moduleArtifacts} is {@code null} - * @param expectedClassPathElements the list of elements of Class-Path entry of manifest. Rows should match - * modules passed in {@code moduleArtifacts} parameter. Can be {@code null} if - * {@code moduleArtifacts} is {@code null} + * @param artifactsToValidateManifest the list of EAR archive artifacts to validate Class-Path entry of artifact + * manifest or {@code null} if there is no need to validate Class-Path entry + * @param artifactsToValidateManifestDirectory whether the artifact from {@code artifactsToValidateManifest} list is + * an exploded or not, can be {@code null} if + * {@code artifactsToValidateManifest} is {@code null} + * @param expectedClassPathElements the list of elements of Class-Path entry of manifest, rows should match + * artifacts passed in {@code artifactsToValidateManifest} parameter; + * can be {@code null} if {@code artifactsToValidateManifest} is {@code null} * @param cleanBeforeExecute call clean plugin before execution * @return the base directory of the project */ protected File doTestProject( final String projectName, final String earModuleName, final String[] expectedArtifacts, boolean[] artifactsDirectory, - final String[] moduleArtifacts, boolean[] moduleArtifactsDirectory, + final String[] artifactsToValidateManifest, + boolean[] artifactsToValidateManifestDirectory, final String[][] expectedClassPathElements, final boolean cleanBeforeExecute ) throws VerificationException, IOException @@ -163,13 +165,14 @@ protected File doTestProject( final String projectName, final String earModuleNa assertEarDirectory( earModuleDir, projectName ); assertArchiveContent( earModuleDir, projectName, expectedArtifacts, artifactsDirectory ); assertDeploymentDescriptors( earModuleDir, projectName ); - assertClassPathElements( earModuleDir, projectName, moduleArtifacts, moduleArtifactsDirectory, expectedClassPathElements ); + assertClassPathElements( earModuleDir, projectName, artifactsToValidateManifest, + artifactsToValidateManifestDirectory, expectedClassPathElements ); return baseDir; } /** - * Executes the specified projects and asserts the given artifacts. Assert the deployment descriptors are valid + * Executes the specified projects and asserts the given artifacts. Assert the deployment descriptors are valid. * * @param projectName the project to test * @param expectedArtifacts the list of artifacts to be found in the EAR archive @@ -410,53 +413,67 @@ public boolean accept( File dir, String name ) } ); } - private void assertClassPathElements( final File baseDir, String projectName, String[] moduleArtifacts, - boolean[] moduleArtifactsDirectory, String[][] expectedClassPathElements ) + /** + * Asserts that given EAR archive artifacts have expected elements in artifact manifest Class-Path entry. + * + * @param baseDir the directory of the tested project + * @param projectName the name of the project + * @param artifacts the list of EAR archive artifacts to validate Class-Path entry of artifact manifest or + * {@code null} if there is no need to validate Class-Path entry + * @param artifactsDirectory whether the artifact from {@code artifacts} list is an exploded or not, + * can be {@code null} if {@code artifacts} is {@code null} + * @param expectedClassPathElements the list of expected elements of Class-Path entry of manifest, rows should match + * artifacts passed in {@code artifacts} parameter; can be {@code null} + * if {@code artifacts} is {@code null} + * @throws IOException exception in case of an failure during reading of artifact manifest. + */ + protected void assertClassPathElements( final File baseDir, String projectName, String[] artifacts, + boolean[] artifactsDirectory, String[][] expectedClassPathElements ) throws IOException { - if ( moduleArtifacts == null ) + if ( artifacts == null ) { return; } - assertNotNull( "moduleArtifactsDirectory should be provided if moduleArtifacts is provided", - moduleArtifactsDirectory ); - assertTrue( "Size of moduleArtifactsDirectory should match size of moduleArtifacts parameter", - moduleArtifacts.length <= moduleArtifactsDirectory.length ); - assertNotNull( "expectedClassPathElements should be provided if moduleArtifacts is provided", + assertNotNull( "artifactsDirectory should be provided if artifacts is provided", + artifactsDirectory ); + assertTrue( "Size of artifactsDirectory should match size of artifacts parameter", + artifacts.length <= artifactsDirectory.length ); + assertNotNull( "expectedClassPathElements should be provided if artifacts is provided", expectedClassPathElements ); - assertTrue( "Rows of expectedClassPathElements parameter should match items of moduleArtifacts parameter", - moduleArtifacts.length <= expectedClassPathElements.length ); + assertTrue( "Rows of expectedClassPathElements parameter should match items of artifacts parameter", + artifacts.length <= expectedClassPathElements.length ); final File earFile = getEarArchive( baseDir, projectName ); - for ( int i = 0; i != moduleArtifacts.length; ++i ) + for ( int i = 0; i != artifacts.length; ++i ) { - final String moduleArtifact = moduleArtifacts[i]; + final String moduleArtifact = artifacts[i]; Assert.assertArrayEquals( "Wrong elements of Class-Path entry of module [" + moduleArtifact + "] manifest", expectedClassPathElements[i], - getClassPathElements( earFile, moduleArtifact, moduleArtifactsDirectory[i] ) ); + getClassPathElements( earFile, moduleArtifact, artifactsDirectory[i] ) ); } } /** - * Extracts elements of Class-Path entry of manifest of given EAR module. + * Retrieves elements of Class-Path entry of manifest of given EAR module. * * @param earFile the EAR file to investigate - * @param moduleArtifact the name of artifact in EAR representing EAR module + * @param artifact the name of artifact in EAR archive representing EAR module * @return elements of Class-Path entry of manifest of EAR module which is represented by - * {@code moduleArtifact} artifact in {@code earFile} file + * {@code artifact} artifact in {@code earFile} file */ - protected String[] getClassPathElements( final File earFile, final String moduleArtifact, final boolean directory ) + protected String[] getClassPathElements( final File earFile, final String artifact, final boolean directory ) throws IOException { final String classPath; try ( JarFile earJarFile = new JarFile( earFile ) ) { - final ZipEntry moduleEntry = earJarFile.getEntry( moduleArtifact ); - assertNotNull( "Artifact [" + moduleArtifact + "] should exist in EAR", moduleEntry ); + final ZipEntry moduleEntry = earJarFile.getEntry( artifact ); + assertNotNull( "Artifact [" + artifact + "] should exist in EAR", moduleEntry ); if (directory) { - final String manifestEntryName = moduleArtifact + "/META-INF/MANIFEST.MF"; + final String manifestEntryName = artifact + "/META-INF/MANIFEST.MF"; final ZipEntry manifestEntry = earJarFile.getEntry( manifestEntryName ); assertNotNull( manifestEntryName + " manifest file should exist in EAR", manifestEntry ); try ( InputStream manifestInputStream = earJarFile.getInputStream( manifestEntry ) ) @@ -471,7 +488,7 @@ protected String[] getClassPathElements( final File earFile, final String module JarInputStream moduleJarInputStream = new JarInputStream( moduleInputStream ) ) { final Manifest manifest = moduleJarInputStream.getManifest(); - assertNotNull( "Artifact [" + moduleArtifact + "] of EAR should have manifest", manifest ); + assertNotNull( "Artifact [" + artifact + "] of EAR should have manifest", manifest ); classPath = manifest.getMainAttributes().getValue( "Class-Path" ); } } diff --git a/src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java b/src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java index 566ab407..d195309d 100644 --- a/src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java +++ b/src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java @@ -1003,16 +1003,16 @@ public void testProject087() public void testProject089() throws Exception { - final String warModuleArtifact = "eartest-war-sample-three-1.0.war"; - final String ejbModuleArtifact = "eartest-ejb-sample-three-1.0.jar"; - final String jarSampleTwoArtifact = "lib/eartest-jar-sample-two-1.0.jar"; - final String jarSampleThreeArtifact = "lib/eartest-jar-sample-three-with-deps-1.0.jar"; + final String warModule = "eartest-war-sample-three-1.0.war"; + final String ejbModule = "eartest-ejb-sample-three-1.0.jar"; + final String jarSampleTwoLibrary = "lib/eartest-jar-sample-two-1.0.jar"; + final String jarSampleThreeLibrary = "lib/eartest-jar-sample-three-with-deps-1.0.jar"; doTestProject( "project-089", "ear", - new String[] { warModuleArtifact, ejbModuleArtifact, jarSampleTwoArtifact, jarSampleThreeArtifact }, + new String[] { warModule, ejbModule, jarSampleTwoLibrary, jarSampleThreeLibrary }, new boolean[] { false, false, false, false}, - new String[] { warModuleArtifact, ejbModuleArtifact }, + new String[] { warModule, ejbModule }, new boolean[] { false, false }, - new String[][] { { jarSampleTwoArtifact, jarSampleThreeArtifact }, { jarSampleThreeArtifact, jarSampleTwoArtifact } }, + new String[][] { { jarSampleTwoLibrary, jarSampleThreeLibrary }, { jarSampleThreeLibrary, jarSampleTwoLibrary } }, true ); } @@ -1026,16 +1026,16 @@ public void testProject089() public void testProject090() throws Exception { - final String warModuleArtifact = "eartest-war-sample-three-1.0.war"; - final String ejbModuleArtifact = "eartest-ejb-sample-three-1.0.jar"; - final String jarSampleTwoArtifact = "lib/eartest-jar-sample-two-1.0.jar"; - final String jarSampleThreeArtifact = "lib/eartest-jar-sample-three-with-deps-1.0.jar"; + final String warModule = "eartest-war-sample-three-1.0.war"; + final String ejbModule = "eartest-ejb-sample-three-1.0.jar"; + final String jarSampleTwoLibrary = "lib/eartest-jar-sample-two-1.0.jar"; + final String jarSampleThreeLibrary = "lib/eartest-jar-sample-three-with-deps-1.0.jar"; doTestProject( "project-090", "ear", - new String[] { warModuleArtifact, ejbModuleArtifact, jarSampleTwoArtifact, jarSampleThreeArtifact }, + new String[] { warModule, ejbModule, jarSampleTwoLibrary, jarSampleThreeLibrary }, new boolean[] { false, false, false, false }, - new String[] { warModuleArtifact, ejbModuleArtifact }, + new String[] { warModule, ejbModule }, new boolean[] { false, false }, - new String[][] { { jarSampleTwoArtifact }, { jarSampleThreeArtifact, jarSampleTwoArtifact } }, + new String[][] { { jarSampleTwoLibrary }, { jarSampleThreeLibrary, jarSampleTwoLibrary } }, true ); } @@ -1050,16 +1050,16 @@ public void testProject090() public void testProject091() throws Exception { - final String warModuleArtifact = "eartest-war-sample-three-1.0.war"; - final String ejbModuleArtifact = "eartest-ejb-sample-three-1.0.jar"; - final String jarSampleTwoArtifact = "eartest-jar-sample-two-1.0.jar"; - final String jarSampleThreeArtifact = "eartest-jar-sample-three-with-deps-1.0.jar"; + final String warModule = "eartest-war-sample-three-1.0.war"; + final String ejbModule = "eartest-ejb-sample-three-1.0.jar"; + final String jarSampleTwoLibrary = "eartest-jar-sample-two-1.0.jar"; + final String jarSampleThreeLibrary = "eartest-jar-sample-three-with-deps-1.0.jar"; doTestProject( "project-091", "ear", - new String[] { warModuleArtifact, ejbModuleArtifact, jarSampleTwoArtifact, jarSampleThreeArtifact }, + new String[] { warModule, ejbModule, jarSampleTwoLibrary, jarSampleThreeLibrary }, new boolean[] { false, true, false, false }, - new String[] { warModuleArtifact, ejbModuleArtifact }, + new String[] { warModule, ejbModule }, new boolean[] { false, true }, - new String[][] { { "jar-sample-two-1.0.jar" }, { jarSampleThreeArtifact, jarSampleTwoArtifact } }, + new String[][] { { "jar-sample-two-1.0.jar" }, { jarSampleThreeLibrary, jarSampleTwoLibrary } }, true ); } } From 2fba3987bd2b3e2cc886db2e280bd88f2cdfc94a Mon Sep 17 00:00:00 2001 From: Marat Abrarov Date: Wed, 7 Oct 2020 19:03:36 +0300 Subject: [PATCH 09/13] [MEAR-267] - Minor code style fix. --- src/main/java/org/apache/maven/plugins/ear/EarMojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e745293a..c635c4dc 100644 --- a/src/main/java/org/apache/maven/plugins/ear/EarMojo.java +++ b/src/main/java/org/apache/maven/plugins/ear/EarMojo.java @@ -962,7 +962,7 @@ private int findModuleInClassPathElements( final List classPathElements, { return -1; } - int moduleClassPathIndex = classPathElements.indexOf( module.getBundleFileName() ); + final int moduleClassPathIndex = classPathElements.indexOf( module.getBundleFileName() ); if ( moduleClassPathIndex != -1 ) { return moduleClassPathIndex; From c6d6d0acf7bcbb60000dce37bb56d26c8603eace Mon Sep 17 00:00:00 2001 From: Marat Abrarov Date: Mon, 12 Oct 2020 15:41:03 +0300 Subject: [PATCH 10/13] [MEAR-267] - JavaDoc simplified. --- src/main/java/org/apache/maven/plugins/ear/EarMojo.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 c635c4dc..5a7a9b82 100644 --- a/src/main/java/org/apache/maven/plugins/ear/EarMojo.java +++ b/src/main/java/org/apache/maven/plugins/ear/EarMojo.java @@ -948,8 +948,8 @@ private void deleteOutdatedResources( final Collection outdatedResources } /** - * Searches for the given JAR module in the list of classpath elements and if found matching returns index of - * class path element matching JAR module or -1 otherwise. + * Searches for the given JAR module in the list of classpath elements. If JAR module is found among specified + * classpath elements then returns index of first matching element. Returns -1 otherwise. * * @param classPathElements classpath elements to search among * @param module module to find among classpath elements defined by {@code classPathElements} From 9c41a3f4c0f0b8d6dfcecf3f83653581699c19be Mon Sep 17 00:00:00 2001 From: Marat Abrarov Date: Mon, 12 Oct 2020 17:13:40 +0300 Subject: [PATCH 11/13] [MEAR-267] - Test for "dirty" build. --- .../apache/maven/plugins/ear/it/EarMojoIT.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java b/src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java index a184b128..91ca4be2 100644 --- a/src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java +++ b/src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java @@ -908,16 +908,22 @@ public void testProject087() public void testProject088() throws Exception { - final String[] expectedArtifacts = { - "eartest-war-sample-two-1.0.war", - "eartest-ejb-sample-one-1.0.jar", - "lib/eartest-jar-sample-two-1.0.jar" }; + final String warModule = "eartest-war-sample-two-1.0.war"; + final String ejbModule = "eartest-ejb-sample-one-1.0.jar"; + final String jarSampleTwoLibrary = "lib/eartest-jar-sample-two-1.0.jar"; + final String[] expectedArtifacts = { warModule, ejbModule, jarSampleTwoLibrary }; final boolean[] artifactsDirectory = { false, true, false }; + final String[] artifactsToValidateManifest = { warModule, ejbModule }; + final boolean[] artifactsToValidateManifestDirectory = { false, true }; + final String[][] expectedClassPathElements = { { jarSampleTwoLibrary }, { jarSampleTwoLibrary } }; + // "Clean" build - target directories and files do not exist // Pass cleanBeforeExecute parameter to ensure that target location is cleaned before Mojo execution - doTestProject( "project-088", "ear", expectedArtifacts, artifactsDirectory, null, null, null, true ); + doTestProject( "project-088", "ear", expectedArtifacts, artifactsDirectory, + artifactsToValidateManifest, artifactsToValidateManifestDirectory, expectedClassPathElements, true ); // "Dirty" build - target directories and files exist - doTestProject( "project-088", "ear", expectedArtifacts, artifactsDirectory, null, null, null, false ); + doTestProject( "project-088", "ear", expectedArtifacts, artifactsDirectory, + artifactsToValidateManifest, artifactsToValidateManifestDirectory, expectedClassPathElements, false ); } /** From f070e47d78dd3671cd0b912458f0eba2dbdb4766 Mon Sep 17 00:00:00 2001 From: Marat Abrarov Date: Mon, 12 Oct 2020 17:50:35 +0300 Subject: [PATCH 12/13] [MEAR-267] - Fixed modification of Class-Path entry of manifest of EAR modules when doing "dirty" build, i.e. when element with desired path already exists in target manifest Class-Path entry --- src/main/java/org/apache/maven/plugins/ear/EarMojo.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 1cd6592d..3b7cd919 100644 --- a/src/main/java/org/apache/maven/plugins/ear/EarMojo.java +++ b/src/main/java/org/apache/maven/plugins/ear/EarMojo.java @@ -964,11 +964,16 @@ private int findModuleInClassPathElements( final List classPathElements, { return -1; } - final int moduleClassPathIndex = classPathElements.indexOf( module.getBundleFileName() ); + int moduleClassPathIndex = classPathElements.indexOf( module.getBundleFileName() ); if ( moduleClassPathIndex != -1 ) { return moduleClassPathIndex; } - return classPathElements.indexOf( module.getArtifact().getFile().getName() ); + moduleClassPathIndex = classPathElements.indexOf( module.getArtifact().getFile().getName() ); + if ( moduleClassPathIndex != -1 ) + { + return moduleClassPathIndex; + } + return classPathElements.indexOf( module.getUri() ); } } From e5ea347f4fab011489acbf7f2eeefdf208cbf1f7 Mon Sep 17 00:00:00 2001 From: Marat Abrarov Date: Mon, 12 Oct 2020 21:30:56 +0300 Subject: [PATCH 13/13] [MEAR-267] - Support of JDK 11+ in integration tests --- src/test/resources/projects/project-089/pom.xml | 4 ++++ src/test/resources/projects/project-090/pom.xml | 4 ++++ src/test/resources/projects/project-091/pom.xml | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/src/test/resources/projects/project-089/pom.xml b/src/test/resources/projects/project-089/pom.xml index f9f04b19..968ece76 100644 --- a/src/test/resources/projects/project-089/pom.xml +++ b/src/test/resources/projects/project-089/pom.xml @@ -30,6 +30,10 @@ under the License. ejb ear + + 1.7 + 1.7 + diff --git a/src/test/resources/projects/project-090/pom.xml b/src/test/resources/projects/project-090/pom.xml index e4672144..6bac0f13 100644 --- a/src/test/resources/projects/project-090/pom.xml +++ b/src/test/resources/projects/project-090/pom.xml @@ -30,6 +30,10 @@ under the License. ejb ear + + 1.7 + 1.7 + diff --git a/src/test/resources/projects/project-091/pom.xml b/src/test/resources/projects/project-091/pom.xml index efae418e..61a5fc8f 100644 --- a/src/test/resources/projects/project-091/pom.xml +++ b/src/test/resources/projects/project-091/pom.xml @@ -30,6 +30,10 @@ under the License. ejb ear + + 1.7 + 1.7 +