Skip to content

Commit

Permalink
Extract all files under META-INF
Browse files Browse the repository at this point in the history
Closes gh-40456
  • Loading branch information
mhalbritter committed Apr 22, 2024
1 parent 4118de7 commit de560a9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.nio.file.Files;
import java.nio.file.attribute.BasicFileAttributeView;
import java.nio.file.attribute.FileTime;
import java.util.EnumSet;
import java.util.Enumeration;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -249,9 +250,10 @@ private void createApplication(JarStructure jarStructure, FileResolver fileResol
Manifest manifest = jarStructure.createLauncherManifest((library) -> librariesDirectory + library);
mkdirs(file.getParentFile());
try (JarOutputStream output = new JarOutputStream(new FileOutputStream(file), manifest)) {
EnumSet<Type> allowedTypes = EnumSet.of(Type.APPLICATION_CLASS_OR_RESOURCE, Type.META_INF);
withJarEntries(this.context.getArchiveFile(), ((stream, jarEntry) -> {
Entry entry = jarStructure.resolve(jarEntry);
if (isType(entry, Type.APPLICATION_CLASS_OR_RESOURCE) && StringUtils.hasLength(entry.location())) {
if (entry != null && allowedTypes.contains(entry.type()) && StringUtils.hasLength(entry.location())) {
JarEntry newJarEntry = createJarEntry(entry.location(), jarEntry);
output.putNextEntry(newJarEntry);
StreamUtils.copy(stream, output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.function.UnaryOperator;
import java.util.jar.Attributes;
import java.util.jar.Attributes.Name;
Expand All @@ -48,6 +49,9 @@ class IndexedJarStructure implements JarStructure {
private static final List<String> MANIFEST_DENY_LIST = List.of("Start-Class", "Spring-Boot-Classes",
"Spring-Boot-Lib", "Spring-Boot-Classpath-Index", "Spring-Boot-Layers-Index");

private static final Set<String> ENTRY_IGNORE_LIST = Set.of("META-INF/", "META-INF/MANIFEST.MF",
"META-INF/services/java.nio.file.spi.FileSystemProvider");

private final Manifest originalManifest;

private final String libLocation;
Expand Down Expand Up @@ -89,6 +93,9 @@ public String getClassesLocation() {

@Override
public Entry resolve(String name) {
if (ENTRY_IGNORE_LIST.contains(name)) {
return null;
}
if (this.classpathEntries.contains(name)) {
return new Entry(name, toStructureDependency(name), Type.LIBRARY);
}
Expand All @@ -98,6 +105,9 @@ public Entry resolve(String name) {
if (name.startsWith("org/springframework/boot/loader")) {
return new Entry(name, name, Type.LOADER);
}
if (name.startsWith("META-INF/")) {
return new Entry(name, name, Type.META_INF);
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ record Entry(String originalLocation, String location, Type type) {

enum Type {

LIBRARY, APPLICATION_CLASS_OR_RESOURCE, LOADER
LIBRARY, APPLICATION_CLASS_OR_RESOURCE, LOADER, META_INF

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ void setUp() throws IOException {
"BOOT-INF/lib/dependency-2.jar", "/jar-contents/dependency-2", "BOOT-INF/lib/dependency-3-SNAPSHOT.jar",
"/jar-contents/dependency-3-SNAPSHOT", "org/springframework/boot/loader/launch/JarLauncher.class",
"/jar-contents/JarLauncher", "BOOT-INF/classes/application.properties",
"/jar-contents/application.properties");
"/jar-contents/application.properties", "META-INF/build-info.properties",
"/jar-contents/build-info.properties");
}

private File file(String name) {
Expand Down Expand Up @@ -207,6 +208,14 @@ void shouldNotFailIfDirectoryIsNotEmptyButForceIsPassed() throws IOException {
.contains("out/test.jar");
}

@Test
void shouldExtractFilesUnderMetaInf() throws IOException {
run(ExtractCommandTests.this.archive);
File application = file("test/test.jar");
List<String> entryNames = getJarEntryNames(application);
assertThat(entryNames).contains("META-INF/build-info.properties");
}

}

@Nested
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build.artifact=test

0 comments on commit de560a9

Please sign in to comment.