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

Commits on Jan 29, 2015

  1. Copy the full SHA
    a939cef View commit details
  2. Reformat code properly.

    headius committed Jan 29, 2015
    Copy the full SHA
    0e20c3d View commit details
  3. Fix BC self-first-classloader tests.

    System properties are often loaded only once, as is the case for
    this value loaded into a static field of RubyInstanceConfig. This
    fix sets the mode in the container's config, removes the static
    field (just go directly to the Option), and provides get/set
    on ScriptingContainer.
    headius committed Jan 29, 2015
    Copy the full SHA
    9b4d8e9 View commit details
3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
@@ -1494,7 +1494,7 @@ public void setProfilingService( String service ) {
* Whether native code is enabled for this configuration.
*/
private boolean _nativeEnabled = NATIVE_ENABLED;
private boolean _selfFirstClassLoader = SELF_FIRST_CLASS_LOADER;
private boolean _selfFirstClassLoader = Options.SELF_FIRST_CLASS_LOADER.load();

private TraceType traceType =
TraceType.traceTypeFor(Options.BACKTRACE_STYLE.load());
@@ -1697,7 +1697,6 @@ public boolean shouldPrecompileAll() {
* Set with the <tt>jruby.native.enabled</tt> system property.
*/
public static final boolean NATIVE_ENABLED = Options.NATIVE_ENABLED.load();
public static final boolean SELF_FIRST_CLASS_LOADER = Options.SELF_FIRST_CLASS_LOADER.load();

@Deprecated
public final static boolean CEXT_ENABLED = false;
27 changes: 27 additions & 0 deletions core/src/main/java/org/jruby/embed/ScriptingContainer.java
Original file line number Diff line number Diff line change
@@ -1858,4 +1858,31 @@ public void finalize() throws Throwable {
// singleton containers share global runtime, and should not tear it down
if (scope != LocalContextScope.SINGLETON) terminate();
}

/**
* Force dynamically-loaded Java classes to load first from the classloader provided by
* JRuby before searching parent classloaders. This can be used to isolated dependency
* in different runtimes from each other and from parent classloaders. The default
* behavior is to defer to parent classloaders if they can provide the requested
* classes.
*
* Note that if different versions of a library are loaded by both a parent
* classloader and the JRuby classloader, those classess would be incompatible
* with each other and with other library objects from the opposing classloader.
*
* @param selfFirstClassloader set whether prefer the JRuby classloader when dynamically loading classes
* @since JRuby 9.0.0.0
*/
public void setSelfFirstClassloader(boolean selfFirstClassloader) {
getProvider().getRubyInstanceConfig().setSelfFirstClassLoader(selfFirstClassloader);
}

/**
* Retrieve the self-first classloader setting.
*
* @see ScriptingContainer#setSelfFirstClassloader(boolean)
*/
public boolean getSelfFirstClassloader() {
return getProvider().getRubyInstanceConfig().isSelfFirstClassLoader();
}
}
Original file line number Diff line number Diff line change
@@ -11,23 +11,24 @@
import org.jruby.embed.ScriptingContainer;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

public class BouncyCastleTestCase {

@Test
public void java(){
assertEquals( "BouncyCastle Security Provider v1.47", new BouncyCastleProvider().getInfo() );
public void java() {
assertEquals("BouncyCastle Security Provider v1.47", new BouncyCastleProvider().getInfo());
}

@Test
public void ruby(){
System.setProperty( "jruby.self.first.class.loader", "true" );
public void ruby() {
ScriptingContainer container = new ScriptingContainer();
container.setSelfFirstClassloader(true);
Object result = container.parse( "gem 'bouncy-castle-java', '1.5.0146.1'; require 'bouncy-castle-java'; Java::OrgBouncycastleJceProvider::BouncyCastleProvider.new.info").run();
assertEquals( "BouncyCastle Security Provider v1.46", result.toString() );

result = container.parse( "JRuby.runtime.jruby_class_loader").run();
assertEquals( "org.jruby.util.SelfFirstJRubyClassLoader", result.toString().replaceFirst( "@.*$", "" ) );
result = container.parse("JRuby.runtime.jruby_class_loader").run();
assertEquals("org.jruby.util.SelfFirstJRubyClassLoader", result.toString().replaceFirst("@.*$", ""));
}
}
Original file line number Diff line number Diff line change
@@ -5,22 +5,23 @@
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.jruby.embed.ScriptingContainer;
import org.junit.Test;

import static org.junit.Assert.*;

public class BouncyCastleTestCase {
@Test
public void java(){
assertEquals( "BouncyCastle Security Provider v1.47", new BouncyCastleProvider().getInfo() );
public void java() {
assertEquals("BouncyCastle Security Provider v1.47", new BouncyCastleProvider().getInfo());
}

@Test
public void ruby(){
System.setProperty( "jruby.self.first.class.loader", "true" );
ScriptingContainer container = new ScriptingContainer();
container.setSelfFirstClassloader(true);
Object result = container.parse( "require 'openssl'; Java::OrgBouncycastleJceProvider::BouncyCastleProvider.new.info").run();
assertEquals( "BouncyCastle Security Provider v1.49", result.toString() );

result = container.parse( "JRuby.runtime.jruby_class_loader").run();
assertEquals( "org.jruby.util.SelfFirstJRubyClassLoader", result.toString().replaceFirst( "@.*$", "" ) );
result = container.parse("JRuby.runtime.jruby_class_loader").run();
assertEquals("org.jruby.util.SelfFirstJRubyClassLoader", result.toString().replaceFirst("@.*$", ""));
}
}
Original file line number Diff line number Diff line change
@@ -11,23 +11,24 @@
import org.jruby.embed.ScriptingContainer;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

public class BouncyCastleTestCase {

@Test
public void java(){
assertEquals( "BouncyCastle Security Provider v1.49", new BouncyCastleProvider().getInfo() );
public void java() {
assertEquals("BouncyCastle Security Provider v1.49", new BouncyCastleProvider().getInfo());
}

@Test
public void ruby(){
System.setProperty( "jruby.self.first.class.loader", "true" );
ScriptingContainer container = new ScriptingContainer();
container.setSelfFirstClassloader(true);
Object result = container.parse( "gem 'bouncy-castle-java', '1.5.0146.1'; require 'bouncy-castle-java'; Java::OrgBouncycastleJceProvider::BouncyCastleProvider.new.info").run();
assertEquals( "BouncyCastle Security Provider v1.46", result.toString() );

result = container.parse( "JRuby.runtime.jruby_class_loader").run();
assertEquals( "org.jruby.util.SelfFirstJRubyClassLoader", result.toString().replaceFirst( "@.*$", "" ) );
result = container.parse("JRuby.runtime.jruby_class_loader").run();
assertEquals("org.jruby.util.SelfFirstJRubyClassLoader", result.toString().replaceFirst("@.*$", ""));
}
}
Original file line number Diff line number Diff line change
@@ -11,28 +11,29 @@
import org.jruby.embed.ScriptingContainer;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

public class BouncyCastleTestCase {

@Before
public void setupProvider() throws Exception{
Security.addProvider( new BouncyCastleProvider() );
public void setupProvider() throws Exception {
Security.addProvider(new BouncyCastleProvider());
}

@Test
public void java(){
assertEquals( "BouncyCastle Security Provider v1.47", new BouncyCastleProvider().getInfo() );
public void java() {
assertEquals("BouncyCastle Security Provider v1.47", new BouncyCastleProvider().getInfo());
}

@Test
public void ruby(){
System.setProperty( "jruby.self.first.class.loader", "true" );
ScriptingContainer container = new ScriptingContainer();
container.setSelfFirstClassloader(true);
Object result = container.parse( "require 'openssl'; Java::OrgBouncycastleJceProvider::BouncyCastleProvider.new.info").run();
assertEquals( "BouncyCastle Security Provider v1.49", result.toString() );

result = container.parse( "JRuby.runtime.jruby_class_loader").run();
assertEquals( "org.jruby.util.SelfFirstJRubyClassLoader", result.toString().replaceFirst( "@.*$", "" ) );
result = container.parse("JRuby.runtime.jruby_class_loader").run();
assertEquals("org.jruby.util.SelfFirstJRubyClassLoader", result.toString().replaceFirst("@.*$", ""));
}
}
7 changes: 7 additions & 0 deletions test/pom.xml
Original file line number Diff line number Diff line change
@@ -34,12 +34,19 @@
<version>2.0.7</version>
<scope>test</scope>
</dependency>
<!-- FIXME: only depend on lib, ideally -->
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby-core</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby-truffle</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>