Skip to content

Commit

Permalink
Showing 4 changed files with 44 additions and 7 deletions.
34 changes: 33 additions & 1 deletion core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@
import org.jruby.util.NormalizedFile;
import org.jruby.util.SafePropertyAccessor;
import org.jruby.util.URLResource;
import org.jruby.util.UriLikePathHelper;
import org.jruby.util.cli.ArgumentProcessor;
import org.jruby.util.cli.Options;
import org.jruby.util.cli.OutputStrings;
@@ -65,6 +66,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -77,6 +79,7 @@
* embedding.
*/
public class RubyInstanceConfig {

public RubyInstanceConfig() {
currentDirectory = Ruby.isSecurityRestricted() ? "/" : JRubyFile.getFileProperty("user.dir");

@@ -670,7 +673,7 @@ private void setupEnvironment(String jrubyHome) {
if (RubyFile.PROTOCOL_PATTERN.matcher(jrubyHome).matches() && !environment.containsKey("RUBY")) {
// the assumption that if JRubyHome is not a regular file that jruby
// got launched in an embedded fashion
environment.put("RUBY", ClasspathLauncher.jrubyCommand(defaultClassLoader()) );
environment.put("RUBY", ClasspathLauncher.jrubyCommand(defaultClassLoader()));
}
}

@@ -686,6 +689,35 @@ public void setLoader(ClassLoader loader) {
this.loader = loader;
}

private final List<String> extraLoadPaths = new LinkedList<>();
public List<String> getExtraLoadPaths() {
return extraLoadPaths;
}
private final List<String> extraGemPaths = new LinkedList<>();
public List<String> getExtraGemPaths() {
return extraGemPaths;
}
public void addLoader(ClassLoader loader) {
addLoader((Object) loader);
}

/**
* adds a given "bundle" to jruby. an OSGi bundle and a classloader
* both have common set of method but do not share a common interface.
* for adding a bundle or classloader to jruby is done via the base URL of
* the classloader/bundle. all we need is the 'getResource'/'getResources'
* method to do so.
* @param bundle
*/
public void addLoader(Object bundle) {
// loader can be a ClassLoader or an Bundle from OSGi
UriLikePathHelper helper = new UriLikePathHelper(loader);
String uri = helper.getUriLikePath();
if (uri != null) extraLoadPaths.add(uri);
uri = helper.getUriLikePath();
if (uri != null) extraGemPaths.add(uri);
}

public String[] getArgv() {
return argv;
}
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/runtime/load/LoadService.java
Original file line number Diff line number Diff line change
@@ -251,6 +251,7 @@ public void init(List prependDirectories) {
}

} catch(SecurityException ignore) {}
addPaths(runtime.getInstanceConfig().getExtraLoadPaths());
}

/**
10 changes: 5 additions & 5 deletions core/src/main/java/org/jruby/util/UriLikePathHelper.java
Original file line number Diff line number Diff line change
@@ -43,19 +43,19 @@ public URL getResource(String ref) {
}
return url;
}

public String getUriLikePath() {
return createUri("/.jrubydir");
}

public String getUriLikePath(String ref) {
return createUri(ref);
public String getUriLikeGemPath() {
return createUri("/specifications/.jrubydir");
}

String createUri(String ref) {
URL url = getResource( ref );
if ( url == null ) {
throw new RuntimeException( "reference " + ref + " not found on classloader " + classLoader );
return null;
}
return "uri:" + url.toString().replaceFirst( ref + "$", "" );
}
6 changes: 5 additions & 1 deletion lib/ruby/stdlib/rubygems/defaults/jruby.rb
Original file line number Diff line number Diff line change
@@ -107,7 +107,11 @@ def dirs= dirs
end

def spec_directories_from_classpath
stuff = [ 'uri:classloader://specifications' ] + JRuby::Util.classloader_resources("specifications")
stuff = [ 'uri:classloader://specifications' ]
JRuby.runtime.instance_config.extra_gem_paths.each do |path|

This comment has been minimized.

Copy link
@swistaczek

swistaczek Sep 5, 2015

Hey @mkristian,
Method #extra_gem_paths does not exist in JRuby 9k release.

irb(main):001:0> JRuby.runtime.instance_config.extra_gem_paths
NoMethodError: undefined method `extra_gem_paths' for #<Java::OrgJruby::RubyInstanceConfig:0x1a4927d6>
    from (irb):1:in `<eval>'
    from org/jruby/RubyKernel.java:979:in `eval'
    from org/jruby/RubyKernel.java:1292:in `loop'
    from org/jruby/RubyKernel.java:1099:in `catch'
    from org/jruby/RubyKernel.java:1099:in `catch'
    from /Users/ernest.bursa/.rbenv/versions/jruby-9.0.0.0/bin/irb:13:in `<top>'

This comment has been minimized.

Copy link
@mkristian

mkristian Sep 5, 2015

Author Member

should be there on 9.0.1.0. this was not part of jruby-9.0.0.0 release

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

0 comments on commit 2adae43

Please sign in to comment.