Update classpath index to use jar name instead of full path

See gh-20564
This commit is contained in:
Madhura Bhave
2020-03-25 10:46:10 -07:00
parent 2ceec65b5d
commit ad164269e9
7 changed files with 25 additions and 57 deletions

View File

@@ -125,7 +125,8 @@ public class BootJar extends Jar implements BootArchive {
}
private File createClasspathIndex(List<String> dependencies) {
String content = dependencies.stream().collect(Collectors.joining("\n", "", "\n"));
String content = dependencies.stream().map((name) -> name.substring(name.lastIndexOf('/') + 1))
.collect(Collectors.joining("\n", "", "\n"));
File source = getProject().getResources().getText().fromString(content).asFile();
File indexFile = new File(source.getParentFile(), "classpath.idx");
source.renameTo(indexFile);

View File

@@ -164,10 +164,8 @@ class BootJarTests extends AbstractBootArchiveTests<BootJar> {
@Test
void whenJarIsLayeredClasspathIndexPointsToLayeredLibs() throws IOException {
try (JarFile jarFile = new JarFile(createLayeredJar())) {
assertThat(entryLines(jarFile, "BOOT-INF/classpath.idx")).containsExactly(
"BOOT-INF/layers/dependencies/lib/first-library.jar",
"BOOT-INF/layers/dependencies/lib/second-library.jar",
"BOOT-INF/layers/snapshot-dependencies/lib/third-library-SNAPSHOT.jar");
assertThat(entryLines(jarFile, "BOOT-INF/classpath.idx")).containsExactly("first-library.jar",
"second-library.jar", "third-library-SNAPSHOT.jar");
}
}
@@ -189,8 +187,8 @@ class BootJarTests extends AbstractBootArchiveTests<BootJar> {
try (JarFile jarFile = new JarFile(createPopulatedJar())) {
assertThat(jarFile.getManifest().getMainAttributes().getValue("Spring-Boot-Classpath-Index"))
.isEqualTo("BOOT-INF/classpath.idx");
assertThat(entryLines(jarFile, "BOOT-INF/classpath.idx")).containsExactly("BOOT-INF/lib/first-library.jar",
"BOOT-INF/lib/second-library.jar", "BOOT-INF/lib/third-library-SNAPSHOT.jar");
assertThat(entryLines(jarFile, "BOOT-INF/classpath.idx")).containsExactly("first-library.jar",
"second-library.jar", "third-library-SNAPSHOT.jar");
}
}