Skip to content

Commit

Permalink
Write (empty) directories into JAR
Browse files Browse the repository at this point in the history
  • Loading branch information
mhalbritter committed Mar 5, 2024
1 parent 485685d commit 196928d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ private void createRunner(File directory, JarStructure jarStructure, Layers laye
try (JarOutputStream output = new JarOutputStream(Files.newOutputStream(launcherJar.toPath()), manifest)) {
withZipEntries(this.context.getArchiveFile(), ((stream, zipEntry) -> {
Entry entry = jarStructure.resolve(zipEntry);
if (isType(entry, Type.APPLICATION_CLASS_OR_RESOURCE)) {
if (isType(entry, Type.APPLICATION_CLASS_OR_RESOURCE) && StringUtils.hasLength(entry.location())) {
JarEntry jarEntry = createJarEntry(entry.location(), zipEntry);
output.putNextEntry(jarEntry);
StreamUtils.copy(stream, output);
Expand Down Expand Up @@ -304,7 +304,7 @@ private static void withZipEntries(File file, ThrowingConsumer callback) throws
() -> "File '%s' is not compatible; ensure jar file is valid and launch script is not enabled"
.formatted(file));
while (entry != null) {
if (StringUtils.hasLength(entry.getName()) && !entry.isDirectory()) {
if (StringUtils.hasLength(entry.getName())) {
callback.accept(stream, entry);
}
entry = stream.getNextEntry();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ public Entry resolve(ZipEntry entry) {
else if (name.startsWith(this.classesLocation)) {
return new Entry(name, name.substring(this.classesLocation.length()), Type.APPLICATION_CLASS_OR_RESOURCE);
}
else if (name.startsWith("org/springframework/boot/loader")) {
return new Entry(name, name, Type.LOADER);
}
return null;
}

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

LIBRARY, APPLICATION_CLASS_OR_RESOURCE
LIBRARY, APPLICATION_CLASS_OR_RESOURCE, LOADER

}
}
Expand Down

0 comments on commit 196928d

Please sign in to comment.