From a1d3bac7c8d2542d06f6c7bbc6f28a092393defd Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 18 Mar 2014 14:26:24 +0000 Subject: [PATCH] More changes to teh way ExplodedArchive works in non-recursive mode It is sufficient for most purposes (e.g. the ones PropertieLauncher needs) to only read the META-INF directory (not the whole file tree). So a quick fix is to make META-INF a special case when initializing non-recursive entries. Fixes gh-520 --- .../boot/loader/PropertiesLauncher.java | 2 +- .../boot/loader/archive/ExplodedArchive.java | 3 ++- .../loader/archive/SpecialArchiveTests.java | 19 +++++++++++++++++++ .../root/META-INF/spring/application.xml | 7 +++++++ 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 spring-boot-tools/spring-boot-loader/src/test/resources/root/META-INF/spring/application.xml diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java index 1d232ca99d..23c27ef623 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java @@ -410,7 +410,7 @@ public class PropertiesLauncher extends Launcher { try { // Prefer home dir for MANIFEST if there is one - Manifest manifest = new ExplodedArchive(this.home).getManifest(); + Manifest manifest = new ExplodedArchive(this.home, false).getManifest(); if (manifest != null) { String value = manifest.getMainAttributes().getValue(manifestKey); this.logger.fine("Property '" + manifestKey diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/ExplodedArchive.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/ExplodedArchive.java index 9d0a07fa20..aca81420f7 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/ExplodedArchive.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/ExplodedArchive.java @@ -91,7 +91,8 @@ public class ExplodedArchive extends Archive { } for (File child : files) { if (!SKIPPED_NAMES.contains(child.getName())) { - if (file.equals(this.root) || this.recursive) { + if (file.equals(this.root) || this.recursive + || file.getName().equals("META-INF")) { buildEntries(child); } } diff --git a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/SpecialArchiveTests.java b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/SpecialArchiveTests.java index 37ff0c9267..60cb756201 100644 --- a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/SpecialArchiveTests.java +++ b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/SpecialArchiveTests.java @@ -22,7 +22,9 @@ import java.util.Map; import org.junit.Test; +import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; /** @@ -37,6 +39,23 @@ public class SpecialArchiveTests { assertThat(entries.size(), greaterThan(1)); } + @Test + public void getManifest() throws Exception { + ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root")); + assertNotNull(archive.getManifest()); + Map entries = getEntriesMap(archive); + assertThat(entries.size(), equalTo(4)); + } + + @Test + public void getManifestEvenIfNonRecursive() throws Exception { + ExplodedArchive archive = new ExplodedArchive( + new File("src/test/resources/root"), false); + assertNotNull(archive.getManifest()); + Map entries = getEntriesMap(archive); + assertThat(entries.size(), equalTo(3)); + } + private Map getEntriesMap(Archive archive) { Map entries = new HashMap(); for (Archive.Entry entry : archive.getEntries()) { diff --git a/spring-boot-tools/spring-boot-loader/src/test/resources/root/META-INF/spring/application.xml b/spring-boot-tools/spring-boot-loader/src/test/resources/root/META-INF/spring/application.xml new file mode 100644 index 0000000000..daac473bbf --- /dev/null +++ b/spring-boot-tools/spring-boot-loader/src/test/resources/root/META-INF/spring/application.xml @@ -0,0 +1,7 @@ + + + + +