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

Commits on Jul 14, 2015

  1. Copy the full SHA
    3b68bdb View commit details
  2. Copy the full SHA
    2a6a6f5 View commit details
  3. Copy the full SHA
    cef1af3 View commit details
  4. make sure -Dorg.jruby.embed.compat.version=1.8 works

    with (JSR223) scripting-container (fixes #1365)
    kares committed Jul 14, 2015
    Copy the full SHA
    05531ea View commit details
  5. Copy the full SHA
    fe236a6 View commit details
Original file line number Diff line number Diff line change
@@ -45,7 +45,8 @@
* @author Yoko Harada <yokolet@gmail.com>
*/
public class EmbedRubyInterfaceAdapterImpl implements EmbedRubyInterfaceAdapter {
private ScriptingContainer container;

private final ScriptingContainer container;

public EmbedRubyInterfaceAdapterImpl(ScriptingContainer container) {
this.container = container;
@@ -62,21 +63,24 @@ public <T> T getInstance(Object receiver, Class<T> clazz) {
if (clazz == null || !clazz.isInterface()) {
return null;
}
Ruby runtime = container.getProvider().getRuntime();
Object o;
final Ruby runtime = container.getProvider().getRuntime();
final Object obj;
if (receiver == null || receiver instanceof RubyNil) {
o = JavaEmbedUtils.rubyToJava(runtime, runtime.getTopSelf(), clazz);
obj = JavaEmbedUtils.rubyToJava(runtime, runtime.getTopSelf(), clazz);
} else if (receiver instanceof IRubyObject) {
o = JavaEmbedUtils.rubyToJava(runtime, (IRubyObject) receiver, clazz);
obj = JavaEmbedUtils.rubyToJava(runtime, (IRubyObject) receiver, clazz);
} else {
IRubyObject rubyReceiver = JavaUtil.convertJavaToRuby(runtime, receiver);
o = JavaEmbedUtils.rubyToJava(runtime, rubyReceiver, clazz);
obj = JavaEmbedUtils.rubyToJava(runtime, rubyReceiver, clazz);
}
String name = clazz.getName();
final String name = clazz.getName();
final ClassLoader loader = obj.getClass().getClassLoader();
try {
Class<T> c = (Class<T>) Class.forName(name, true, o.getClass().getClassLoader());
return c.cast(o);
} catch (ClassNotFoundException e) {
@SuppressWarnings("unchecked")
Class<T> klass = (Class<T>) Class.forName(name, true, loader);
return klass.cast(obj);
}
catch (ClassNotFoundException e) {
throw new InvokeFailedException(e);
}
}
Original file line number Diff line number Diff line change
@@ -61,10 +61,11 @@
* @author Yoko Harada <yokolet@gmail.com>
*/
public class EmbedRubyObjectAdapterImpl implements EmbedRubyObjectAdapter {
private RubyObjectAdapter adapter = JavaEmbedUtils.newObjectAdapter();
private ScriptingContainer container;

public enum MethodType {
private final RubyObjectAdapter adapter = JavaEmbedUtils.newObjectAdapter();
private final ScriptingContainer container;

public static enum MethodType {
CALLMETHOD_NOARG,
CALLMETHOD,
CALLMETHOD_WITHBLOCK,
@@ -79,15 +80,15 @@ public EmbedRubyObjectAdapterImpl(ScriptingContainer container) {
public boolean isKindOf(IRubyObject value, RubyModule rubyModule) {
return adapter.isKindOf(value, rubyModule);
}

public IRubyObject[] convertToJavaArray(IRubyObject array) {
return adapter.convertToJavaArray(array);
}

public RubyInteger convertToRubyInteger(IRubyObject obj) {
return adapter.convertToRubyInteger(obj);
}

public RubyString convertToRubyString(IRubyObject obj) {
return adapter.convertToRubyString(obj);
}
@@ -195,7 +196,7 @@ public <T> T callMethod(Object receiver, String methodName, Class<T> returnType,
throw new InvokeFailedException(e);
}
}

public <T> T callMethod(Object receiver, String methodName, Object[] args, Class<T> returnType, EmbedEvalUnit unit) {
try {
RubyObject rubyReceiver = getReceiverObject(receiver);
@@ -268,7 +269,7 @@ public Object callMethod(Object receiver, String methodName, Block block, Object
throw new InvokeFailedException(e);
}
}

public <T> T runRubyMethod(Class<T> returnType, Object receiver, String methodName, Block block, Object... args) {
try {
RubyObject rubyReceiver = (RubyObject)JavaEmbedUtils.javaToRuby(container.getProvider().getRuntime(), receiver);
@@ -289,7 +290,7 @@ private <T> T call(MethodType type, Class<T> returnType, RubyObject rubyReceiver
return null;
}
Ruby runtime = container.getProvider().getRuntime();

boolean sharing_variables = true;
Object obj = container.getAttribute(AttributeName.SHARING_VARIABLES);
if (obj != null && obj instanceof Boolean && ((Boolean) obj) == false) {
@@ -323,7 +324,7 @@ private <T> T call(MethodType type, Class<T> returnType, RubyObject rubyReceiver
}
}
}

private RubyObject getReceiverObject(Object receiver) {
Ruby runtime = container.getProvider().getRuntime();
if (receiver == null || !(receiver instanceof IRubyObject)) {
Original file line number Diff line number Diff line change
@@ -34,10 +34,8 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.StringReader;
import java.io.Writer;
import java.net.URL;

import org.jruby.Ruby;
@@ -73,8 +71,9 @@
* @author Yoko Harada <yokolet@gmail.com>
*/
public class EmbedRubyRuntimeAdapterImpl implements EmbedRubyRuntimeAdapter {
private RubyRuntimeAdapter adapter = JavaEmbedUtils.newRuntimeAdapter();
private ScriptingContainer container;

private final RubyRuntimeAdapter adapter = JavaEmbedUtils.newRuntimeAdapter();
private final ScriptingContainer container;

public EmbedRubyRuntimeAdapterImpl(ScriptingContainer container) {
this.container = container;
@@ -166,10 +165,10 @@ private EmbedEvalUnit runParser(Object input, String filename, int... lines) {
if (filename == null || filename.length() == 0) {
filename = container.getScriptFilename();
}
Ruby runtime = container.getProvider().getRuntime();
IAccessor d = new ValueAccessor(RubyString.newString(runtime, filename));
runtime.getGlobalVariables().define("$PROGRAM_NAME", d, GlobalVariable.Scope.GLOBAL);
runtime.getGlobalVariables().define("$0", d, GlobalVariable.Scope.GLOBAL);
final Ruby runtime = container.getProvider().getRuntime();
IAccessor $0 = new ValueAccessor(RubyString.newString(runtime, filename));
runtime.getGlobalVariables().define("$PROGRAM_NAME", $0, GlobalVariable.Scope.GLOBAL);
runtime.getGlobalVariables().define("$0", $0, GlobalVariable.Scope.GLOBAL);

int line = 0;
if (lines != null && lines.length > 0) {
@@ -185,7 +184,7 @@ private EmbedEvalUnit runParser(Object input, String filename, int... lines) {
if (sharing_variables) {
scope = getManyVarsDynamicScope(container, 0);
}
Node node = null;
final Node node;
if (input instanceof String) {
node = runtime.parseEval((String)input, filename, scope, line);
} else {
@@ -238,7 +237,7 @@ static ManyVarsDynamicScope getManyVarsDynamicScope(ScriptingContainer container

// JRUBY-5501: ensure we've set up a cref for the scope too
scope.getStaticScope().determineModule();

return scope;
}

109 changes: 53 additions & 56 deletions core/src/main/java/org/jruby/embed/util/SystemPropertyCatcher.java
Original file line number Diff line number Diff line change
@@ -66,18 +66,12 @@ public class SystemPropertyCatcher {
public static LocalContextScope getScope(LocalContextScope defaultScope) {
LocalContextScope scope = defaultScope;
String s = SafePropertyAccessor.getProperty(PropertyName.LOCALCONTEXT_SCOPE.toString());
if (s == null) {
return scope;
}
if ("singlethread".equalsIgnoreCase(s)) {
return LocalContextScope.SINGLETHREAD;
} else if ("singleton".equalsIgnoreCase(s)) {
return LocalContextScope.SINGLETON;
} else if ("threadsafe".equalsIgnoreCase(s)) {
return LocalContextScope.THREADSAFE;
} else if ("concurrent".equalsIgnoreCase(s)) {
return LocalContextScope.CONCURRENT;
}
if (s == null) return scope;

if ("singlethread".equalsIgnoreCase(s)) return LocalContextScope.SINGLETHREAD;
if ("singleton".equalsIgnoreCase(s)) return LocalContextScope.SINGLETON;
if ("threadsafe".equalsIgnoreCase(s)) return LocalContextScope.THREADSAFE;
if ("concurrent".equalsIgnoreCase(s)) return LocalContextScope.CONCURRENT;
return scope;
}

@@ -91,18 +85,12 @@ public static LocalContextScope getScope(LocalContextScope defaultScope) {
public static LocalVariableBehavior getBehavior(LocalVariableBehavior defaultBehavior) {
LocalVariableBehavior behavior = defaultBehavior;
String s = SafePropertyAccessor.getProperty(PropertyName.LOCALVARIABLE_BEHAVIOR.toString());
if (s == null) {
return behavior;
}
if ("global".equalsIgnoreCase(s)) {
return LocalVariableBehavior.GLOBAL;
} else if ("persistent".equalsIgnoreCase(s)) {
return LocalVariableBehavior.PERSISTENT;
} else if ("transient".equalsIgnoreCase(s)) {
return LocalVariableBehavior.TRANSIENT;
} else if ("bsf".equalsIgnoreCase(s)) {
return LocalVariableBehavior.BSF;
}
if (s == null) return behavior;

if ("global".equalsIgnoreCase(s)) return LocalVariableBehavior.GLOBAL;
if ("persistent".equalsIgnoreCase(s)) return LocalVariableBehavior.PERSISTENT;
if ("transient".equalsIgnoreCase(s)) return LocalVariableBehavior.TRANSIENT;
if ("bsf".equalsIgnoreCase(s)) return LocalVariableBehavior.BSF;
return behavior;
}

@@ -116,30 +104,30 @@ public static LocalVariableBehavior getBehavior(LocalVariableBehavior defaultBeh
public static boolean isLazy(boolean defaultLaziness) {
boolean lazy = defaultLaziness;
String s = SafePropertyAccessor.getProperty(PropertyName.LAZINESS.toString());
if (s == null) {
return lazy;
}
if (s == null) return lazy;
return Boolean.parseBoolean(s);
}

/**
* Sets classloader based on System property. This is only used from
* JRubyEgnineFactory.
*
*
* @param container ScriptingContainer to be set classloader
*/

public static void setClassLoader(ScriptingContainer container) {
String s = SafePropertyAccessor.getProperty(PropertyName.CLASSLOADER.toString());
String loader = SafePropertyAccessor.getProperty(PropertyName.CLASSLOADER.toString());

// current should be removed later
if (s == null || "container".equals(s) || "current".equals(s)) { // default
if (loader == null || "container".equals(loader) || "current".equals(loader)) { // default
container.setClassLoader(container.getClass().getClassLoader());
return;
} else if ("context".equals(s)) {
}
if ("context".equals(loader)) {
container.setClassLoader(Thread.currentThread().getContextClassLoader());
return;
} else if ("none".equals(s)) {
}
if ("none".equals(loader)) {
return;
}
// if incorrect value is set, no classloader will set by ScriptingContainer.
@@ -155,19 +143,28 @@ public static void setClassLoader(ScriptingContainer container) {
public static void setConfiguration(ScriptingContainer container) {
LocalContextProvider provider = container.getProvider();
RubyInstanceConfig config = provider.getRubyInstanceConfig();
String s = SafePropertyAccessor.getProperty(PropertyName.COMPILEMODE.toString());
if (s != null) {
if ("jit".equalsIgnoreCase(s)) {
String mode = SafePropertyAccessor.getProperty(PropertyName.COMPILEMODE.toString());
if (mode != null) {
if ("jit".equalsIgnoreCase(mode)) {
config.setCompileMode(CompileMode.JIT);
} else if ("force".equalsIgnoreCase(s)) {
}
else if ("force".equalsIgnoreCase(mode)) {
config.setCompileMode(CompileMode.FORCE);
} else {
}
else {
config.setCompileMode(CompileMode.OFF);
}
}
s = SafePropertyAccessor.getProperty(PropertyName.COMPATVERSION.toString());
if (s != null) {
if (isRuby19(s)) {
String compat = SafePropertyAccessor.getProperty(PropertyName.COMPATVERSION.toString());
if (compat != null) {
compat = compat.toLowerCase();
if ( matches(compat, "j?(ruby)?1[\\._]?8") ) {
config.setCompatVersion(CompatVersion.RUBY1_8);
}
else if ( matches(compat, "j?(ruby)?2[\\._]?0") ) {
config.setCompatVersion(CompatVersion.RUBY2_0);
}
else if ( matches(compat, "j?(ruby)?1[\\._]?9") ) {
config.setCompatVersion(CompatVersion.RUBY1_9);
}
}
@@ -199,13 +196,14 @@ public static String findJRubyHome(Object instance) {
String jrubyhome;
if ((jrubyhome = SafePropertyAccessor.getenv("JRUBY_HOME")) != null) {
return jrubyhome;
} else if ((jrubyhome = SafePropertyAccessor.getProperty("jruby.home")) != null) {
}
if ((jrubyhome = SafePropertyAccessor.getProperty("jruby.home")) != null) {
return jrubyhome;
} else if ((jrubyhome = findFromJar(instance)) != null) {
}
if ((jrubyhome = findFromJar(instance)) != null) {
return jrubyhome;
} else {
return null;
}
return null;
}

public static String findFromJar(Object instance) {
@@ -218,7 +216,7 @@ public static String findFromJar(Object instance) {
if (resource == null) return null;
}

String location = null;
String location;
if (resource.getProtocol().equals("jar")) {
location = getPath(resource);
if (!location.startsWith("file:")) {
@@ -278,15 +276,14 @@ public static List<String> findLoadPaths() {
* @return true is the given name is correct to choose Ruby 1.9 version. Otherwise,
* returns false.
*/
@Deprecated
public static boolean isRuby19(String name) {
String n = name.toLowerCase();
Pattern p = Pattern.compile("j?ruby1[\\._]?9");
Matcher m = p.matcher(n);
if (m.matches()) {
return true;
} else {
return false;
}
return matches(name.toLowerCase(), "j?ruby1[\\._]?9");
}

private static boolean matches(final String name, final String pattern) {
Matcher matcher = Pattern.compile(pattern).matcher( name );
return matcher.matches();
}

/**
Loading