Skip to content

Commit

Permalink
Remove classpath index manifest attribute from repackaged war files
Browse files Browse the repository at this point in the history
Fixes gh-28895
  • Loading branch information
scottfrederick committed Dec 3, 2021
1 parent af60a8a commit 467c092
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* @author Dave Syer
* @author Andy Wilkinson
* @author Madhura Bhave
* @author Scott Frederick
* @since 1.0.0
*/
public final class Layouts {
Expand Down Expand Up @@ -160,11 +161,6 @@ public String getClassesLocation() {
return "WEB-INF/classes/";
}

@Override
public String getClasspathIndexFileLocation() {
return "WEB-INF/classpath.idx";
}

@Override
public String getLayersIndexFileLocation() {
return "WEB-INF/layers.idx";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,15 +510,15 @@ void write(AbstractJarWriter writer) throws IOException {
writtenPaths.add(path);
}
}
if (getLayout() instanceof RepackagingLayout) {
writeClasspathIndex(writtenPaths, (RepackagingLayout) getLayout(), writer);
}
writeClasspathIndexIfNecessary(writtenPaths, getLayout(), writer);
}

private void writeClasspathIndex(List<String> paths, RepackagingLayout layout, AbstractJarWriter writer)
private void writeClasspathIndexIfNecessary(List<String> paths, Layout layout, AbstractJarWriter writer)
throws IOException {
List<String> names = paths.stream().map((path) -> "- \"" + path + "\"").collect(Collectors.toList());
writer.writeIndexFile(layout.getClasspathIndexFileLocation(), names);
if (layout.getClasspathIndexFileLocation() != null) {
List<String> names = paths.stream().map((path) -> "- \"" + path + "\"").collect(Collectors.toList());
writer.writeIndexFile(layout.getClasspathIndexFileLocation(), names);
}
}

private class PackagedLibrariesUnpackHandler implements UnpackHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
* Base class for archive (jar or war) related Maven plugin integration tests.
*
* @author Andy Wilkinson
* @author Scott Frederick
*/
abstract class AbstractArchiveIntegrationTests {

Expand Down Expand Up @@ -201,6 +202,11 @@ ManifestAssert hasAttribute(String name, String value) {
return this;
}

ManifestAssert doesNotHaveAttribute(String name) {
assertThat(this.actual.getMainAttributes().getValue(name)).isNull();
return this;
}

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
*
* @author Andy Wilkinson
* @author Madhura Bhave
* @author Scott Frederick
*/
@ExtendWith(MavenBuildExtension.class)
class JarIntegrationTests extends AbstractArchiveIntegrationTests {
Expand Down Expand Up @@ -363,6 +364,16 @@ void whenJarIsRepackagedWithTheCustomLayers(MavenBuild mavenBuild) {
});
}

@TestTemplate
void repackagedJarContainsClasspathIndex(MavenBuild mavenBuild) {
mavenBuild.project("jar").execute((project) -> {
File repackaged = new File(project, "target/jar-0.0.1.BUILD-SNAPSHOT.jar");
assertThat(jar(repackaged)).manifest(
(manifest) -> manifest.hasAttribute("Spring-Boot-Classpath-Index", "BOOT-INF/classpath.idx"));
assertThat(jar(repackaged)).hasEntryWithName("BOOT-INF/classpath.idx");
});
}

@TestTemplate
void whenJarIsRepackagedWithOutputTimestampConfiguredThenJarIsReproducible(MavenBuild mavenBuild)
throws InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* Integration tests for the Maven plugin's war support.
*
* @author Andy Wilkinson
* @author Scott Frederick
*/
@ExtendWith(MavenBuildExtension.class)
class WarIntegrationTests extends AbstractArchiveIntegrationTests {
Expand Down Expand Up @@ -190,6 +191,16 @@ void whenWarIsRepackagedWithTheCustomLayers(MavenBuild mavenBuild) {
});
}

@TestTemplate
void repackagedWarDoesNotContainClasspathIndex(MavenBuild mavenBuild) {
mavenBuild.project("war").execute((project) -> {
File repackaged = new File(project, "target/war-0.0.1.BUILD-SNAPSHOT.war");
assertThat(jar(repackaged))
.manifest((manifest) -> manifest.doesNotHaveAttribute("Spring-Boot-Classpath-Index"));
assertThat(jar(repackaged)).doesNotHaveEntryWithName("BOOT-INF/classpath.idx");
});
}

@TestTemplate
void whenEntryIsExcludedItShouldNotBePresentInTheRepackagedWar(MavenBuild mavenBuild) {
mavenBuild.project("war-exclude-entry").execute((project) -> {
Expand Down

0 comments on commit 467c092

Please sign in to comment.