Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a494386c0a5a
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9e4721db9d07
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Apr 10, 2016

  1. Copy the full SHA
    142b8f9 View commit details
  2. Revert "remove obsolete gem_paths via classloader resource"

    This reverts commit bd45d9f.
    mkristian committed Apr 10, 2016

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9e4721d View commit details
Showing with 33 additions and 35 deletions.
  1. +30 −32 core/src/main/java/org/jruby/util/URLResource.java
  2. +2 −2 core/src/test/java/org/jruby/util/URLResourceTest.java
  3. +1 −1 lib/ruby/stdlib/rubygems/defaults/jruby.rb
62 changes: 30 additions & 32 deletions core/src/main/java/org/jruby/util/URLResource.java
Original file line number Diff line number Diff line change
@@ -162,38 +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);
// 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
}
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
}
}
}
return new URLResource(URI_CLASSLOADER + '/' + pathname,
cl,
@@ -215,15 +216,13 @@ private static boolean addDirectoriesFromClassloader(ClassLoader cl, Set<String>

private static boolean addDirectoryEntries(Set<String> entries, URL url,
boolean isDirectory) {
if (url.getPath().endsWith(".jrubydir")) return isDirectory;
switch (url.getProtocol()) {
case "jar":
// maybe the jar itself contains directory entries (which are actually optional)
FileResource jar = JarResource.create(url.toString());
if (jar != null && jar.isDirectory()) {
if (!isDirectory) isDirectory = true;
entries.addAll(Arrays.asList(jar.list()));
entries.remove(".jrubydir");
}
break;
case "file":
@@ -232,7 +231,6 @@ private static boolean addDirectoryEntries(Set<String> entries, URL url,
if (file.isDirectory()) {
if (!isDirectory) isDirectory = true;
entries.addAll(Arrays.asList(file.list()));
entries.remove(".jrubydir");
}
break;
default:
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"}));
}

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"}));
}

public void testNoneDirectoryClassloader()
2 changes: 1 addition & 1 deletion lib/ruby/stdlib/rubygems/defaults/jruby.rb
Original file line number Diff line number Diff line change
@@ -92,10 +92,10 @@ def dirs= dirs

def spec_directories_from_classpath
stuff = [ 'uri:classloader://specifications' ]
# extra gem paths when a classloader gets added to the instance-config
JRuby.runtime.instance_config.extra_gem_paths.each do |path|
stuff << File.join(path, 'specifications')
end
stuff += JRuby::Util.classloader_resources('specifications')
# some classloader return directory info. use only the "protocols"
# which jruby understands
stuff.select { |s| File.directory?( s ) }