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: d53595e805bd
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4c034b4ad1e5
Choose a head ref
  • 2 commits
  • 7 files changed
  • 1 contributor

Commits on Jul 30, 2015

  1. Copy the full SHA
    168f6fb View commit details
  2. Copy the full SHA
    4c034b4 View commit details
23 changes: 22 additions & 1 deletion core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
@@ -693,15 +693,36 @@ public void setLoader(ClassLoader loader) {
public List<String> getExtraLoadPaths() {
return extraLoadPaths;
}

private final List<String> extraGemPaths = new LinkedList<>();
public List<String> getExtraGemPaths() {
return extraGemPaths;
}

/**
* adds a given ClassLoader to jruby. i.e. adds the root of
* the classloader to the LOAD_PATH so embedded ruby scripts
* can be found. dito for embedded gems.
* @param loader
*/
public void addLoader(ClassLoader loader) {
addLoader(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();
uri = helper.getUriLikeGemPath();
if (uri != null) extraGemPaths.add(uri);
}

11 changes: 11 additions & 0 deletions core/src/main/java/org/jruby/embed/ScriptingContainer.java
Original file line number Diff line number Diff line change
@@ -1905,14 +1905,24 @@ public boolean getClassloaderDelegate() {
return getProvider().getRubyInstanceConfig().isClassloaderDelegate();
}

/**
* add the given classloader to the LOAD_PATH and GEM_PATH
* @param classloader
*/
public void addClassLoader(ClassLoader classLoader) {
getProvider().getRubyInstanceConfig().addLoader(classLoader);
}

/**
* add the given classloader to the LOAD_PATH
* @param classloader
*/
@Deprecated
public void addLoadPath(ClassLoader classloader) {
addLoadPath(createUri(classloader, "/.jrubydir"));
}

@Deprecated
protected void addLoadPath(String uri) {
runScriptlet( "$LOAD_PATH << '" + uri + "' unless $LOAD_PATH.member?( '" + uri + "' )" );
}
@@ -1921,6 +1931,7 @@ protected void addLoadPath(String uri) {
* add the given classloader to the GEM_PATH
* @param classloader
*/
@Deprecated
public void addGemPath(ClassLoader classloader) {
addGemPath(createUri(classloader, "/specifications/.jrubydir"));
}
Original file line number Diff line number Diff line change
@@ -62,8 +62,9 @@ private Bundle toBundle(String symbolicName) {
return bundle;
}

@Deprecated
private String createUri(Bundle cl, String ref) {
URL url = cl.getResource( ref );
URL url = cl.getResource(ref);
if ( url == null && ref.startsWith( "/" ) ) {
url = cl.getResource( ref.substring( 1 ) );
}
@@ -76,6 +77,7 @@ private String createUri(Bundle cl, String ref) {
* add the classloader from the given bundle to the LOAD_PATH
* @param bundle
*/
@Deprecated
public void addBundleToLoadPath(Bundle bundle) {
addLoadPath(createUri(bundle, "/.jrubydir"));
}
@@ -86,24 +88,44 @@ public void addBundleToLoadPath(Bundle bundle) {
*
* @param symbolicName
*/
@Deprecated
public void addBundleToLoadPath(String symbolicName) {
addBundleToLoadPath(toBundle(symbolicName));
}

/**
* add the classloader from the given bundle to the LOAD_PATH and the GEM_PATH
* using the bundle symbolic name
* @param symbolicName
*/
public void addBundle(String symbolicName) {
addBundle(toBundle(symbolicName));
}

/**
* add the classloader from the given bundle to the LOAD_PATH and the GEM_PATH
* @param bundle
*/
public void addBundle(Bundle bundle) {
getProvider().getRubyInstanceConfig().addLoader(bundle);
}

/**
* add the classloader from the given bundle to the GEM_PATH
* @param bundle
*/
@Deprecated
public void addBundleToGemPath(Bundle bundle) {
addGemPath(createUri(bundle, "/specifications/.jrubydir"));
}

/**
* add the classloader from the given bundle to the GEM_PATH
* using the bundle symbolic name
*
* @param symbolicName
*/
@Deprecated
public void addBundleToGemPath(String symbolicName) {
addBundleToGemPath(toBundle(symbolicName));
}
38 changes: 31 additions & 7 deletions core/src/main/java/org/jruby/util/UriLikePathHelper.java
Original file line number Diff line number Diff line change
@@ -26,24 +26,48 @@
***** END LICENSE BLOCK *****/
package org.jruby.util;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;

public class UriLikePathHelper {

private final ClassLoader classLoader;
private final Method method;
private final Object loader;

public UriLikePathHelper(ClassLoader classLoader) {
this.classLoader = classLoader;
public UriLikePathHelper(Object classLoader) {
this.loader = classLoader;
Method m = null;
try {
m = classLoader.getClass().getDeclaredMethod("getResource", String.class);
} catch (NoSuchMethodException e) {
}
this.method = m;
}

public URL getResource(String ref) {
URL url = classLoader.getResource( ref );
URL url = get( ref );
if ( url == null && ref.startsWith( "/" ) ) {
url = classLoader.getResource( ref.substring( 1 ) );
url = get( ref.substring( 1 ) );
}
return url;
}

private URL get(String ref) {
if(loader instanceof ClassLoader) {
return ((ClassLoader) loader).getResource(ref);
}
if (method != null) {
try {
return (URL) method.invoke(loader, ref);
} catch (IllegalAccessException e) {
return null;
} catch (InvocationTargetException e) {
return null;
}
}
return null;
}
public String getUriLikePath() {
return createUri("/.jrubydir");
}
@@ -52,7 +76,7 @@ public String getUriLikeGemPath() {
return createUri("/specifications/.jrubydir");
}

String createUri(String ref) {
private String createUri(String ref) {
URL url = getResource( ref );
if ( url == null ) {
return null;
2 changes: 1 addition & 1 deletion lib/ruby/stdlib/rubygems/defaults/jruby.rb
Original file line number Diff line number Diff line change
@@ -109,7 +109,7 @@ def dirs= dirs
def spec_directories_from_classpath
stuff = [ 'uri:classloader://specifications' ]
JRuby.runtime.instance_config.extra_gem_paths.each do |path|
stuff += File.join(path, 'specifications')
stuff << File.join(path, 'specifications')
end
stuff += JRuby::Util.classloader_resources('specifications')
# some classloader return directory info. use only the "protocols"
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@
import java.util.ArrayList;
import java.util.Arrays;

import org.jruby.embed.IsolatedScriptingContainer;
import org.jruby.embed.osgi.OSGiIsolatedScriptingContainer;
import org.junit.Test;
import org.junit.Ignore;
@@ -71,7 +72,57 @@ public Option[] config() {
}

@Test
public void testJRubyCreate() throws Exception {
public void testJRubyWithoutOSGiApi() throws Exception {

System.err.println();
System.err.println();

//System.setProperty( "jruby.debug.loadService", "true" );
//System.setProperty( "jruby.native.enabled", "true" );

IsolatedScriptingContainer jruby = new IsolatedScriptingContainer();
jruby.addClassLoader( Gems.class.getClassLoader() );
jruby.addClassLoader( Scripts.class.getClassLoader() );

// run a script from LOAD_PATH
String hello = (String) jruby.runScriptlet( "require 'hello'; Hello.say" );
assertEquals( "world", hello );

System.err.println();
System.err.println();

String gemPath = (String) jruby.runScriptlet( "Gem::Specification.dirs.inspect" );
gemPath = gemPath.replaceAll( "bundle[^:]*://[^/]*", "bundle:/" );
assertEquals( gemPath, "[\"uri:bundle://specifications\"]" );

// ensure we can load rake from the default gems
boolean loaded = (Boolean) jruby.runScriptlet( "require 'rake'" );
assertEquals(true, loaded);

String list = (String) jruby.runScriptlet( "Gem.loaded_specs.keys.inspect" );
assertEquals( "[\"rake\"]", list );

// ensure we have native working
loaded = (Boolean) jruby.runScriptlet( "JRuby.runtime.posix.is_native" );
assertEquals(true, loaded);

// ensure we can load openssl (with its bouncy-castle jars)
loaded = (Boolean) jruby.runScriptlet( "require 'openssl'" );
assertEquals(true, loaded);

jruby.runScriptlet( "require 'jar-dependencies'" );

assertGemListEquals(jruby, "jar-dependencies", "jruby-openssl", "rake");

// ensure we can load can load embedded gems
loaded = (Boolean) jruby.runScriptlet( "require 'virtus'" );
assertEquals(true, loaded);

assertGemListEquals(jruby, "axiom-types", "coercible", "descendants_tracker", "equalizer", "ice_nine", "jar-dependencies", "jruby-openssl", "rake", "thread_safe", "virtus");
}

@Test
public void testJRubyWithOSGiApi() throws Exception {

System.err.println();
System.err.println();
@@ -80,8 +131,8 @@ public void testJRubyCreate() throws Exception {
//System.setProperty( "jruby.native.enabled", "true" );

OSGiIsolatedScriptingContainer jruby = new OSGiIsolatedScriptingContainer();
jruby.addBundleToLoadPath( "org.jruby.osgi.scripts-bundle" );
jruby.addBundleToGemPath( FrameworkUtil.getBundle( Gems.class ) );
jruby.addBundle( "org.jruby.osgi.scripts-bundle" );
jruby.addBundle( FrameworkUtil.getBundle( Gems.class ) );

// run a script from LOAD_PATH
String hello = (String) jruby.runScriptlet( "require 'hello'; Hello.say" );
@@ -120,7 +171,7 @@ public void testJRubyCreate() throws Exception {
assertGemListEquals(jruby, "axiom-types", "coercible", "descendants_tracker", "equalizer", "ice_nine", "jar-dependencies", "jruby-openssl", "rake", "thread_safe", "virtus");
}

private static void assertGemListEquals(final OSGiIsolatedScriptingContainer jruby, final String... expected) {
private static void assertGemListEquals(final IsolatedScriptingContainer jruby, final String... expected) {
String list = (String) jruby.runScriptlet( "Gem.loaded_specs.keys.sort.join(', ')" );

Arrays.sort(expected);
@@ -138,7 +189,7 @@ private static void assertGemListEquals(final OSGiIsolatedScriptingContainer jru
}
}

private static boolean gemJOpenSSLPreRelease(final OSGiIsolatedScriptingContainer jruby) {
private static boolean gemJOpenSSLPreRelease(final IsolatedScriptingContainer jruby) {
String josslVersion = (String) jruby.runScriptlet( "require 'jopenssl/version'; Jopenssl::Version::VERSION" );
return josslVersion.matches(".*?[a-zA-Z]");
}
6 changes: 3 additions & 3 deletions maven/jruby/src/templates/osgi_all_inclusive/pom.rb
Original file line number Diff line number Diff line change
@@ -6,14 +6,14 @@
'exam.version' => '3.0.3',
'url.version' => '1.5.2',
'logback.version' => '1.0.13',
'jruby.version' => '@project.version@' )
'jruby.version' => '9.0.0.0' )

pom 'org.jruby:jruby', '${jruby.version}'
pom 'org.jruby:jruby', '@project.version@'

repository( :url => 'http://rubygems-proxy.torquebox.org/releases',
:id => 'tb-rubygems-releases' )
repository( :url => 'https://otto.takari.io/content/repositories/rubygems/maven/releases',
:id => 'rubygems-releases' )
:id => 'takari-rubygems-releases' )

jruby_plugin! :gem, :includeRubygemsInResources => true