Fix URL filtering when loading from a directory

The ExplodedArchive would erroneously always attempt to filter
its contents (and thereby shield them from a classloader that wrapped
it) even if they haven't been explicitly provided.

See gh-1352
This commit is contained in:
Dave Syer
2014-08-19 13:49:55 +01:00
parent fbd429c6c1
commit ccfc47091c
3 changed files with 31 additions and 7 deletions

View File

@@ -147,6 +147,7 @@ public class ExplodedArchiveTests {
new URL[] { filteredArchive.getUrl() });
assertThat(classLoader.getResourceAsStream("1.dat").read(), equalTo(1));
assertThat(classLoader.getResourceAsStream("2.dat"), nullValue());
classLoader.close();
}
@Test
@@ -173,6 +174,25 @@ public class ExplodedArchiveTests {
assertThat(entries.size(), equalTo(3));
}
@Test
public void getResourceAsStream() throws Exception {
ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"));
assertNotNull(archive.getManifest());
URLClassLoader loader = new URLClassLoader(new URL[] { archive.getUrl() });
assertNotNull(loader.getResourceAsStream("META-INF/spring/application.xml"));
loader.close();
}
@Test
public void getResourceAsStreamNonRecursive() throws Exception {
ExplodedArchive archive = new ExplodedArchive(
new File("src/test/resources/root"), false);
assertNotNull(archive.getManifest());
URLClassLoader loader = new URLClassLoader(new URL[] { archive.getUrl() });
assertNotNull(loader.getResourceAsStream("META-INF/spring/application.xml"));
loader.close();
}
private Map<String, Archive.Entry> getEntriesMap(Archive archive) {
Map<String, Archive.Entry> entries = new HashMap<String, Archive.Entry>();
for (Archive.Entry entry : archive.getEntries()) {

View File

@@ -97,6 +97,7 @@ public class JarFileTests {
assertThat(urlClassLoader.getResource("special/\u00EB.dat"), notNullValue());
assertThat(urlClassLoader.getResource("d/9.dat"), notNullValue());
jarFile.close();
urlClassLoader.close();
}
@Test
@@ -139,6 +140,7 @@ public class JarFileTests {
URLClassLoader urlClassLoader = new URLClassLoader(
new URL[] { this.jarFile.getUrl() });
assertThat(urlClassLoader.getResource("special/\u00EB.dat"), notNullValue());
urlClassLoader.close();
}
@Test