assets/src/org/ruboto/JRubyAdapter.java in ruboto-1.0.3 vs assets/src/org/ruboto/JRubyAdapter.java in ruboto-1.1.0
- old
+ new
@@ -9,10 +9,11 @@
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
+import android.os.Build;
import android.os.Environment;
import dalvik.system.PathClassLoader;
public class JRubyAdapter {
private static Object ruby;
@@ -133,11 +134,11 @@
setDebugBuild(appContext);
Log.d("Setting up JRuby runtime (" + (isDebugBuild ? "DEBUG" : "RELEASE") + ")");
System.setProperty("jruby.backtrace.style", "normal"); // normal raw full mri
System.setProperty("jruby.bytecode.version", "1.6");
// BEGIN Ruboto RubyVersion
- // System.setProperty("jruby.compat.version", "RUBY1_9"); // 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
// END Ruboto RubyVersion
// System.setProperty("jruby.compile.backend", "DALVIK");
System.setProperty("jruby.compile.mode", "OFF"); // OFF OFFIR JITIR? FORCE FORCEIR
System.setProperty("jruby.interfaces.useProxy", "true");
System.setProperty("jruby.ir.passes", "LocalOptimizationPass,DeadCodeElimination");
@@ -155,10 +156,22 @@
// Used to enable JRuby to generate proxy classes
System.setProperty("jruby.ji.proxyClassFactory", "org.ruboto.DalvikProxyClassFactory");
System.setProperty("jruby.ji.upper.case.package.name.allowed", "true");
System.setProperty("jruby.class.cache.path", appContext.getDir("dex", 0).getAbsolutePath());
+ // FIXME(uwe): Simplify when we stop supporting android-15
+ if (Build.VERSION.SDK_INT >= 16) {
+ DexDex.debug = true;
+ DexDex.validateClassPath(appContext);
+ while (DexDex.dexOptRequired) {
+ System.out.println("Waiting for class loader setup...");
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException ie) {}
+ }
+ }
+
ClassLoader classLoader;
Class<?> scriptingContainerClass;
String apkName = null;
try {
@@ -238,10 +251,13 @@
if (output != null) {
rubyInstanceConfigClass.getMethod("setOutput", PrintStream.class).invoke(config, output);
rubyInstanceConfigClass.getMethod("setError", PrintStream.class).invoke(config, output);
}
+ System.out.println("Ruby version: " + rubyInstanceConfigClass
+ .getMethod("getCompatVersion").invoke(config));
+
// This will become the global runtime and be used by our ScriptingContainer
rubyClass.getMethod("newInstance", rubyInstanceConfigClass).invoke(null, config);
//////////////////////////////////
//
@@ -263,23 +279,31 @@
Method setClassLoaderMethod = ruby.getClass().getMethod("setClassLoader", ClassLoader.class);
setClassLoaderMethod.invoke(ruby, classLoader);
Thread.currentThread().setContextClassLoader(classLoader);
+ String scriptsDir = scriptsDirName(appContext);
+ addLoadPath(scriptsDir);
if (appContext.getFilesDir() != null) {
String defaultCurrentDir = appContext.getFilesDir().getPath();
Log.d("Setting JRuby current directory to " + defaultCurrentDir);
callScriptingContainerMethod(Void.class, "setCurrentDirectory", defaultCurrentDir);
} else {
Log.e("Unable to find app files dir!");
+ if (new File(scriptsDir).exists()) {
+ Log.d("Changing JRuby current directory to " + scriptsDir);
+ callScriptingContainerMethod(Void.class, "setCurrentDirectory", scriptsDir);
+ }
}
- addLoadPath(scriptsDirName(appContext));
put("$package_name", appContext.getPackageName());
runScriptlet("::RUBOTO_JAVA_PROXIES = {}");
+ System.out.println("JRuby version: " + Class.forName("org.jruby.runtime.Constants", true, scriptingContainerClass.getClassLoader())
+ .getDeclaredField("VERSION").get(String.class));
+
initialized = true;
} catch (ClassNotFoundException e) {
handleInitException(e);
} catch (IllegalArgumentException e) {
handleInitException(e);
@@ -291,10 +315,12 @@
handleInitException(e);
} catch (InvocationTargetException e) {
handleInitException(e);
} catch (NoSuchMethodException e) {
handleInitException(e);
+ } catch (NoSuchFieldException e) {
+ handleInitException(e);
}
}
return initialized;
}
@@ -309,11 +335,9 @@
public static Boolean addLoadPath(String scriptsDir) {
if (new File(scriptsDir).exists()) {
Log.i("Added directory to load path: " + scriptsDir);
Script.addDir(scriptsDir);
runScriptlet("$:.unshift '" + scriptsDir + "' ; $:.uniq!");
- Log.d("Changing JRuby current directory to " + scriptsDir);
- callScriptingContainerMethod(Void.class, "setCurrentDirectory", scriptsDir);
return true;
} else {
Log.i("Extra scripts dir not present: " + scriptsDir);
return false;
}