Restore manifest support for nested directory jars
Update `NestedJarFile` so that the `getManifest()` method returns the manifest from the parent jar file for nested jars based on directory entries. This restores the previous behavior supported by Spring Boot 3.1 and allows class methods such as `getPackage().getImplementationVersion()` to return non `null` results. Fixes gh-38996
This commit is contained in:
@@ -110,6 +110,26 @@ class NestedJarFileTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void getManifestWhenNestedJarReturnsManifestOfNestedJar() throws Exception {
|
||||
try (JarFile jar = new JarFile(this.file)) {
|
||||
try (NestedJarFile nestedJar = new NestedJarFile(this.file, "nested.jar")) {
|
||||
Manifest manifest = nestedJar.getManifest();
|
||||
assertThat(manifest).isNotEqualTo(jar.getManifest());
|
||||
assertThat(manifest.getMainAttributes().getValue("Built-By")).isEqualTo("j2");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void getManifestWhenNestedJarDirectoryReturnsManifestOfParent() throws Exception {
|
||||
try (JarFile jar = new JarFile(this.file)) {
|
||||
try (NestedJarFile nestedJar = new NestedJarFile(this.file, "d/")) {
|
||||
assertThat(nestedJar.getManifest()).isEqualTo(jar.getManifest());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void createWhenJarHasFrontMatterOpensJar() throws IOException {
|
||||
File file = new File(this.tempDir, "frontmatter.jar");
|
||||
|
||||
@@ -48,6 +48,7 @@ import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.boot.loader.testsupport.TestJar;
|
||||
import org.springframework.boot.loader.zip.ZipContent.Entry;
|
||||
import org.springframework.boot.loader.zip.ZipContent.Kind;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
@@ -168,6 +169,25 @@ class ZipContentTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void getKindWhenZipReturnsZip() {
|
||||
assertThat(this.zipContent.getKind()).isEqualTo(Kind.ZIP);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getKindWhenNestedZipReturnsNestedZip() throws IOException {
|
||||
try (ZipContent nested = ZipContent.open(this.file.toPath(), "nested.jar")) {
|
||||
assertThat(nested.getKind()).isEqualTo(Kind.NESTED_ZIP);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void getKindWhenNestedDirectoryReturnsNestedDirectory() throws IOException {
|
||||
try (ZipContent nested = ZipContent.open(this.file.toPath(), "d/")) {
|
||||
assertThat(nested.getKind()).isEqualTo(Kind.NESTED_DIRECTORY);
|
||||
}
|
||||
}
|
||||
|
||||
private void assertThatFieldsAreEqual(ZipEntry actual, ZipEntry expected) {
|
||||
assertThat(actual.getName()).isEqualTo(expected.getName());
|
||||
assertThat(actual.getTime()).isEqualTo(expected.getTime());
|
||||
|
||||
Reference in New Issue
Block a user