assets/src/org/ruboto/JRubyAdapter.java in ruboto-0.10.2 vs assets/src/org/ruboto/JRubyAdapter.java in ruboto-0.11.0.rc.0

- old
+ new

@@ -248,11 +248,11 @@ System.setProperty("jruby.interfaces.useProxy", "true"); System.setProperty("jruby.management.enabled", "false"); System.setProperty("jruby.objectspace.enabled", "false"); System.setProperty("jruby.thread.pooling", "true"); System.setProperty("jruby.native.enabled", "false"); - // System.setProperty("jruby.compat.version", "RUBY1_8"); // RUBY1_9 is the default in JRuby 1.7 + // System.setProperty("jruby.compat.version", "RUBY2_0"); // RUBY1_9 is the default in JRuby 1.7 System.setProperty("jruby.ir.passes", "LocalOptimizationPass,DeadCodeElimination"); System.setProperty("jruby.backtrace.style", "normal"); // normal raw full mri // Uncomment these to debug/profile Ruby source loading // System.setProperty("jruby.debug.loadService", "true"); @@ -303,10 +303,63 @@ return false; } } try { + ////////////////////////////////// + // + // Set jruby.home + // + + String jrubyHome = "file:" + apkName + "!/jruby.home"; + + // FIXME(uwe): Remove when we stop supporting RubotoCore 0.4.7 + Log.i("RUBOTO_CORE_VERSION_NAME: " + RUBOTO_CORE_VERSION_NAME); + if (RUBOTO_CORE_VERSION_NAME != null && + (RUBOTO_CORE_VERSION_NAME.equals("0.4.7") || RUBOTO_CORE_VERSION_NAME.equals("0.4.8"))) { + jrubyHome = "file:" + apkName + "!"; + } + // EMXIF + + Log.i("Setting JRUBY_HOME: " + jrubyHome); + // This needs to be set before the ScriptingContainer is initialized + System.setProperty("jruby.home", jrubyHome); + + ////////////////////////////////// + // + // Determine Output + // + + if (out != null) { + output = out; + } + + ////////////////////////////////// + // + // Disable rubygems + // + + Class rubyClass = Class.forName("org.jruby.Ruby", true, scriptingContainerClass.getClassLoader()); + Class rubyInstanceConfigClass = Class.forName("org.jruby.RubyInstanceConfig", true, scriptingContainerClass.getClassLoader()); + + Object config = rubyInstanceConfigClass.getConstructor().newInstance(); + rubyInstanceConfigClass.getMethod("setDisableGems", boolean.class).invoke(config, true); + rubyInstanceConfigClass.getMethod("setLoader", ClassLoader.class).invoke(config, classLoader); + + if (output != null) { + rubyInstanceConfigClass.getMethod("setOutput", PrintStream.class).invoke(config, output); + rubyInstanceConfigClass.getMethod("setError", PrintStream.class).invoke(config, output); + } + + // This will become the global runtime and be used by our ScriptingContainer + rubyClass.getMethod("newInstance", rubyInstanceConfigClass).invoke(null, config); + + ////////////////////////////////// + // + // Create the ScriptingContainer + // + Class scopeClass = Class.forName("org.jruby.embed.LocalContextScope", true, scriptingContainerClass.getClassLoader()); Class behaviorClass = Class.forName("org.jruby.embed.LocalVariableBehavior", true, scriptingContainerClass.getClassLoader()); ruby = scriptingContainerClass .getConstructor(scopeClass, behaviorClass) @@ -328,32 +381,12 @@ callScriptingContainerMethod(Void.class, "setCurrentDirectory", defaultCurrentDir); } else { Log.e("Unable to find app files dir!"); } - if (out != null) { - output = out; - setOutputStream(out); - } else if (output != null) { - setOutputStream(output); - } - - String jrubyHome = "file:" + apkName + "!/jruby.home"; - - // FIXME(uwe): Remove when we stop supporting RubotoCore 0.4.7 - Log.i("RUBOTO_CORE_VERSION_NAME: " + RUBOTO_CORE_VERSION_NAME); - if (RUBOTO_CORE_VERSION_NAME != null && - (RUBOTO_CORE_VERSION_NAME.equals("0.4.7") || RUBOTO_CORE_VERSION_NAME.equals("0.4.8"))) { - jrubyHome = "file:" + apkName + "!"; - } - // EMXIF - - Log.i("Setting JRUBY_HOME: " + jrubyHome); - System.setProperty("jruby.home", jrubyHome); - addLoadPath(scriptsDirName(appContext)); - put("$package_name", appContext.getPackageName()); + put("$package_name", appContext.getPackageName()); initialized = true; } catch (ClassNotFoundException e) { handleInitException(e); } catch (IllegalArgumentException e) { @@ -441,10 +474,11 @@ return ((String)get("RUBY_VERSION")).startsWith("1.8."); } // FIXME(uwe): Remove when we stop supporting Ruby 1.8 @Deprecated public static boolean isRubyOneNine() { - return ((String)get("RUBY_VERSION")).startsWith("1.9."); + String rv = ((String)get("RUBY_VERSION")); + return rv.startsWith("2.0.") || rv.startsWith("1.9."); } static void printStackTrace(Throwable t) { // TODO(uwe): Simplify this when Issue #144 is resolved // TODO(scott): printStackTrace is causing too many problems