Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
always look into classloader resources to find directory entries
Browse files Browse the repository at this point in the history
mkristian committed Apr 9, 2016
1 parent bd45d9f commit aad8946
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions core/src/main/java/org/jruby/util/URLResource.java
Original file line number Diff line number Diff line change
@@ -162,39 +162,39 @@ public static FileResource createClassloaderURI(Ruby runtime, String pathname, b
pathname = pathname.replaceAll("^[.]?/*", "");
}
final URL url = cl.getResource(pathname);

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,

0 comments on commit aad8946

Please sign in to comment.