From 2f64cdfa98d6c65a093e73965a6f4e5eca6d893c Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 5 Apr 2017 10:29:05 +0100 Subject: [PATCH] Include directory entries when copying loader into a Boot archive See gh-8816 --- .../gradle/tasks/bundling/BootZipCopyAction.java | 13 ++++++++++++- .../tasks/bundling/AbstractBootArchiveTests.java | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootZipCopyAction.java b/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootZipCopyAction.java index 6a8086f21b..65a4076fb1 100644 --- a/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootZipCopyAction.java +++ b/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootZipCopyAction.java @@ -115,6 +115,9 @@ class BootZipCopyAction implements CopyAction { try (ZipInputStream in = new ZipInputStream(getClass() .getResourceAsStream("/META-INF/loader/spring-boot-loader.jar"))) { while ((entry = in.getNextEntry()) != null) { + if (entry.isDirectory() && !entry.getName().startsWith("META-INF/")) { + writeDirectory(entry, out); + } if (entry.getName().endsWith(".class")) { writeClass(entry, in, out); } @@ -125,13 +128,21 @@ class BootZipCopyAction implements CopyAction { } } + private void writeDirectory(ZipEntry entry, ZipOutputStream out) throws IOException { + if (!this.preserveFileTimestamps) { + entry.setTime(GUtil.CONSTANT_TIME_FOR_ZIP_ENTRIES); + } + out.putNextEntry(entry); + out.closeEntry(); + } + private void writeClass(ZipEntry entry, ZipInputStream in, ZipOutputStream out) throws IOException { - byte[] buffer = new byte[4096]; if (!this.preserveFileTimestamps) { entry.setTime(GUtil.CONSTANT_TIME_FOR_ZIP_ENTRIES); } out.putNextEntry(entry); + byte[] buffer = new byte[4096]; int read; while ((read = in.read(buffer)) > 0) { out.write(buffer, 0, read); diff --git a/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveTests.java b/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveTests.java index befdd65f61..8e74fa4d7c 100644 --- a/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveTests.java +++ b/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveTests.java @@ -132,6 +132,7 @@ public abstract class AbstractBootArchiveTests { assertThat(jarFile.getEntry( "org/springframework/boot/loader/LaunchedURLClassLoader.class")) .isNotNull(); + assertThat(jarFile.getEntry("org/springframework/boot/loader/")).isNotNull(); } } @@ -146,6 +147,7 @@ public abstract class AbstractBootArchiveTests { assertThat(jarFile.getEntry( "org/springframework/boot/loader/LaunchedURLClassLoader.class")) .isNotNull(); + assertThat(jarFile.getEntry("org/springframework/boot/loader/")).isNotNull(); } }