Skip to content

Commit

Permalink
always look into classloader resources to find directory entries
Browse files Browse the repository at this point in the history
mkristian committed Apr 11, 2016
1 parent 9e4721d commit 7386d65
Showing 2 changed files with 30 additions and 32 deletions.
58 changes: 28 additions & 30 deletions core/src/main/java/org/jruby/util/URLResource.java
Original file line number Diff line number Diff line change
@@ -165,36 +165,34 @@ public static FileResource createClassloaderURI(Ruby runtime, String pathname, b
String[] files = null;
if (!asFile) {
files = listClassLoaderFiles(cl, pathname);
if (files == null) {
// no .jrubydir found
boolean isDirectory = false;
// we do not want double entries
Set<String> list = new LinkedHashSet<String>();
list.add(".");
list.add("..");
try {
// first look at the enum from the classloader
// may or may not contain directory entries
Enumeration<URL> urls = cl.getResources(pathname);
while(urls.hasMoreElements()){
isDirectory = addDirectoryEntries(list, urls.nextElement(), isDirectory);
}
if (runtime != null) {
// we have a runtime, so look at the JRubyClassLoader
// and its parent classloader
isDirectory = addDirectoriesFromClassloader(cl, list, pathname, isDirectory);
isDirectory = addDirectoriesFromClassloader(cl.getParent(), list, pathname, isDirectory);
}
else {
// just look at what we have
isDirectory = addDirectoriesFromClassloader(cl, list, pathname, isDirectory);
}
if (isDirectory) files = list.toArray(new String[list.size()]);

} catch (IOException e) {
// we tried
}
}
// look for classloader resource which do not have .jrubydir
boolean isDirectory = files != null;
// we do not want double entries
Set<String> list = files == null ? new LinkedHashSet<String>(): new LinkedHashSet<String>(Arrays.asList(files));
list.add(".");
list.add("..");
try {
// first look at the enum from the classloader
// may or may not contain directory entries
Enumeration<URL> urls = cl.getResources(pathname);
while(urls.hasMoreElements()){
isDirectory = addDirectoryEntries(list, urls.nextElement(), isDirectory);
}
if (runtime != null) {
// we have a runtime, so look at the JRubyClassLoader
// and its parent classloader
isDirectory = addDirectoriesFromClassloader(cl, list, pathname, isDirectory);
isDirectory = addDirectoriesFromClassloader(cl.getParent(), list, pathname, isDirectory);
}
else {
// just look at what we have
isDirectory = addDirectoriesFromClassloader(cl, list, pathname, isDirectory);
}
if (isDirectory) files = list.toArray(new String[list.size()]);

} catch (IOException e) {
// we tried
}
}
return new URLResource(URI_CLASSLOADER + '/' + pathname,
cl,
4 changes: 2 additions & 2 deletions core/src/test/java/org/jruby/util/URLResourceTest.java
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@ public void testDirectoryClassloader() {
assertTrue(resource.exists());
assertEquals(Arrays.asList(resource.list()),
Arrays.asList(new String[]{".", "dir_without_listing",
"dir_with_listing"}));
"dir_with_listing", "..", ".jrubydir"}));
}

public void testDirectoryWithTrailingClassloader()
@@ -89,7 +89,7 @@ public void testDirectoryWithTrailingClassloader()
assertTrue(resource.exists());
assertEquals(Arrays.asList(resource.list()),
Arrays.asList(new String[]{".", "dir_without_listing",
"dir_with_listing"}));
"dir_with_listing", "..", ".jrubydir"}));
}

public void testNoneDirectoryClassloader()

0 comments on commit 7386d65

Please sign in to comment.