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
pull/523/head
Dave Syer 11 years ago
parent 2c60449836
commit a1d3bac7c8

@ -410,7 +410,7 @@ public class PropertiesLauncher extends Launcher {
try { try {
// Prefer home dir for MANIFEST if there is one // 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) { if (manifest != null) {
String value = manifest.getMainAttributes().getValue(manifestKey); String value = manifest.getMainAttributes().getValue(manifestKey);
this.logger.fine("Property '" + manifestKey this.logger.fine("Property '" + manifestKey

@ -91,7 +91,8 @@ public class ExplodedArchive extends Archive {
} }
for (File child : files) { for (File child : files) {
if (!SKIPPED_NAMES.contains(child.getName())) { 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); buildEntries(child);
} }
} }

@ -22,7 +22,9 @@ import java.util.Map;
import org.junit.Test; import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
/** /**
@ -37,6 +39,23 @@ public class SpecialArchiveTests {
assertThat(entries.size(), greaterThan(1)); 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<String, Archive.Entry> 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<String, Archive.Entry> entries = getEntriesMap(archive);
assertThat(entries.size(), equalTo(3));
}
private Map<String, Archive.Entry> getEntriesMap(Archive archive) { private Map<String, Archive.Entry> getEntriesMap(Archive archive) {
Map<String, Archive.Entry> entries = new HashMap<String, Archive.Entry>(); Map<String, Archive.Entry> entries = new HashMap<String, Archive.Entry>();
for (Archive.Entry entry : archive.getEntries()) { for (Archive.Entry entry : archive.getEntries()) {

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
</beans>
Loading…
Cancel
Save