Remove META-INF/INDEX.LIST when repackaging a jar file

META-INF/INDEX.LIST files are pointless in an executable jar and
moving application classes from the root of the jar to
BOOT-INF/classes breaks the index, resulting in an
InvalidJarIndexException being thrown.

This commit updates the Repackager to automatically remove a
META-INF/INDEX.LIST file from a jar file that is being repackaged.

Closes gh-6601
pull/6588/head
Andy Wilkinson 8 years ago
parent f4985abf3c
commit 899b851c6f

@ -141,7 +141,10 @@ public class JarWriter {
jarFile.getInputStream(entry));
}
EntryWriter entryWriter = new InputStreamEntryWriter(inputStream, true);
writeEntry(entryTransformer.transform(entry), entryWriter);
JarEntry transformedEntry = entryTransformer.transform(entry);
if (transformedEntry != null) {
writeEntry(transformedEntry, entryWriter);
}
}
finally {
inputStream.close();

@ -337,6 +337,9 @@ public class Repackager {
@Override
public JarEntry transform(JarEntry entry) {
if (entry.getName().equals("META-INF/INDEX.LIST")) {
return null;
}
if (entry.getName().startsWith("META-INF/")
|| entry.getName().startsWith("BOOT-INF/")) {
return entry;

@ -518,6 +518,24 @@ public class RepackagerTests {
}
}
@Test
public void metaInfIndexListIsRemovedFromRepackagedJar() throws Exception {
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
this.testJarFile.addFile("META-INF/INDEX.LIST",
this.temporaryFolder.newFile("INDEX.LIST"));
File source = this.testJarFile.getFile();
File dest = this.temporaryFolder.newFile("dest.jar");
Repackager repackager = new Repackager(source);
repackager.repackage(dest, NO_LIBRARIES);
JarFile jarFile = new JarFile(dest);
try {
assertThat(jarFile.getEntry("META-INF/INDEX.LIST")).isNull();
}
finally {
jarFile.close();
}
}
private boolean hasLauncherClasses(File file) throws IOException {
return hasEntry(file, "org/springframework/boot/")
&& hasEntry(file, "org/springframework/boot/loader/JarLauncher.class");

Loading…
Cancel
Save