diff --git a/src/it/skinny-wars-javaee5/verify.bsh b/src/it/skinny-wars-javaee5/verify.bsh index c2b77232..5e82942d 100644 --- a/src/it/skinny-wars-javaee5/verify.bsh +++ b/src/it/skinny-wars-javaee5/verify.bsh @@ -135,7 +135,7 @@ String[] includedEntries = { "META-INF/MANIFEST.MF" }; -String[] warModule1ExpectedClassPathElements = { "lib/commons-lang-commons-lang-2.6.jar" }; +String[] warModule1ExpectedClassPathElements = { "commons-lang-2.6.jar" }; assertJar( earBaseDir + "org.apache.maven.its.ear.skinnywars-war-module1-1.0.war", includedEntries, warModuleExcludedEntries, true, warModule1ExpectedClassPathElements ); 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 576a0097..cbf4df32 100644 --- a/src/main/java/org/apache/maven/plugins/ear/EarMojo.java +++ b/src/main/java/org/apache/maven/plugins/ear/EarMojo.java @@ -665,7 +665,7 @@ private void changeManifestClasspath( EarModule module, File original, JavaEEVersion javaEEVersion, Collection outdatedResources) throws MojoFailureException { final String moduleLibDir = module.getLibDir(); - if (!((moduleLibDir == null) || skinnyModules || (skinnyWars && module instanceof WebModule))) { + if (!(skinnyModules || (skinnyWars && (module instanceof WebModule || moduleLibDir == null)))) { return; } @@ -713,12 +713,9 @@ private void changeManifestClasspath( Attribute classPath = mf.getMainSection().getAttribute("Class-Path"); List classPathElements = new ArrayList<>(); - boolean classPathExists; if (classPath != null) { - classPathExists = true; classPathElements.addAll(Arrays.asList(classPath.getValue().split(" "))); } else { - classPathExists = false; classPath = new Attribute("Class-Path", ""); } @@ -776,50 +773,47 @@ private void changeManifestClasspath( } // Modify the classpath entries in the manifest - final boolean forceClassPathModification = - javaEEVersion.lt(JavaEEVersion.FIVE) || defaultLibBundleDir == null; - final boolean classPathExtension = !skipClassPathModification || forceClassPathModification; - for (EarModule otherModule : getModules()) { - if (module.equals(otherModule)) { - continue; - } - final int moduleClassPathIndex = findModuleInClassPathElements(classPathElements, otherModule); - if (moduleClassPathIndex != -1) { - if (otherModule.isClassPathItem()) { - classPathElements.set(moduleClassPathIndex, otherModule.getUri()); - } else { - classPathElements.remove(moduleClassPathIndex); + if (!skipClassPathModification) { + for (EarModule otherModule : getModules()) { + if (module.equals(otherModule)) { + continue; + } + final int moduleClassPathIndex = findModuleInClassPathElements(classPathElements, otherModule); + if (moduleClassPathIndex != -1) { + if (otherModule.isClassPathItem()) { + classPathElements.set(moduleClassPathIndex, otherModule.getUri()); + } else { + classPathElements.remove(moduleClassPathIndex); + } + } else if (otherModule.isClassPathItem()) { + classPathElements.add(otherModule.getUri()); } - } else if (otherModule.isClassPathItem() && classPathExtension) { - classPathElements.add(otherModule.getUri()); } - } - // Remove provided modules from classpath - for (EarModule otherModule : getProvidedEarModules()) { - final int moduleClassPathIndex = findModuleInClassPathElements(classPathElements, otherModule); - if (moduleClassPathIndex != -1) { - classPathElements.remove(moduleClassPathIndex); + // Remove provided modules from classpath + for (EarModule otherModule : getProvidedEarModules()) { + final int moduleClassPathIndex = findModuleInClassPathElements(classPathElements, otherModule); + if (moduleClassPathIndex != -1) { + classPathElements.remove(moduleClassPathIndex); + } } - } - if (!skipClassPathModification || !classPathElements.isEmpty() || classPathExists) { classPath.setValue(StringUtils.join(classPathElements.iterator(), " ")); mf.getMainSection().addConfiguredAttribute(classPath); + } - // Write the manifest to disk, preserve timestamp - FileTime lastModifiedTime = Files.getLastModifiedTime(manifestFile); - try (BufferedWriter writer = Files.newBufferedWriter( - manifestFile, - StandardCharsets.UTF_8, - StandardOpenOption.WRITE, - StandardOpenOption.CREATE, - StandardOpenOption.TRUNCATE_EXISTING)) { - mf.write(writer); - } - Files.setLastModifiedTime(manifestFile, lastModifiedTime); - removeFromOutdatedResources(manifestFile, outdatedResources); + // Write the manifest to disk, preserve timestamp + FileTime lastModifiedTime = Files.getLastModifiedTime(manifestFile); + try (BufferedWriter writer = Files.newBufferedWriter( + manifestFile, + StandardCharsets.UTF_8, + StandardOpenOption.WRITE, + StandardOpenOption.CREATE, + StandardOpenOption.TRUNCATE_EXISTING)) { + mf.write(writer); } + Files.setLastModifiedTime(manifestFile, lastModifiedTime); + removeFromOutdatedResources(manifestFile, outdatedResources); if (fileSystem != null) { fileSystem.close(); 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 159a6f67..504e7605 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 @@ -951,6 +951,8 @@ void testProject089() throws Exception { void testProject090() throws Exception { final String warModule = "eartest-war-sample-three-1.0.war"; final String ejbModule = "eartest-ejb-sample-three-1.0.jar"; + final String jarSampleTwo = "jar-sample-two-1.0.jar"; + final String jarSampleThreeWithDeps = "jar-sample-three-with-deps-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( @@ -960,7 +962,7 @@ void testProject090() throws Exception { new boolean[] {false, false, false, false}, new String[] {warModule, ejbModule}, new boolean[] {false, false}, - new String[][] {{jarSampleTwoLibrary}, {jarSampleThreeLibrary, jarSampleTwoLibrary}}, + new String[][] {{jarSampleTwo}, {jarSampleThreeWithDeps, jarSampleTwo}}, true); } @@ -976,6 +978,8 @@ void testProject090() throws Exception { void testProject091() throws Exception { final String warModule = "eartest-war-sample-three-1.0.war"; final String ejbModule = "eartest-ejb-sample-three-1.0.jar"; + final String jarSampleTwo = "jar-sample-two-1.0.jar"; + final String jarSampleThreeWithDeps = "jar-sample-three-with-deps-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( @@ -985,7 +989,7 @@ void testProject091() throws Exception { new boolean[] {false, true, false, false}, new String[] {warModule, ejbModule}, new boolean[] {false, true}, - new String[][] {{"jar-sample-two-1.0.jar"}, {jarSampleThreeLibrary, jarSampleTwoLibrary}}, + new String[][] {{jarSampleTwo}, {jarSampleThreeWithDeps, jarSampleTwo}}, true); } @@ -1211,8 +1215,7 @@ void testProject094() throws Exception { new boolean[] {false, false, false, false, false, false, false}, earModules, earModuleDirectory, - new String[][] {null, null, null, null, new String[] {jarSampleThreeEarLibrary, jarSampleTwoEarLibrary} - }, + new String[][] {null, null, null, null, new String[] {jarSampleThreeLibrary, jarSampleTwoLibrary}}, true); assertEarModulesContent(