Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/it/skinny-wars-javaee5/verify.bsh
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
48 changes: 21 additions & 27 deletions src/main/java/org/apache/maven/plugins/ear/EarMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ private void changeManifestClasspath(
EarModule module, File original, JavaEEVersion javaEEVersion, Collection<String> 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;
}

Expand Down Expand Up @@ -713,12 +713,9 @@ private void changeManifestClasspath(
Attribute classPath = mf.getMainSection().getAttribute("Class-Path");
List<String> 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", "");
}

Expand Down Expand Up @@ -776,34 +773,31 @@ 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);

Expand Down
10 changes: 7 additions & 3 deletions src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
}

Expand All @@ -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(
Expand All @@ -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);
}

Expand Down Expand Up @@ -1211,7 +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);

Expand Down
Loading