示例#1
0
  public static ScriptingContainer makeContainer(RubyConfig config) {
    // Required global setting for when JRuby fakes up Kernel.system('ruby')
    // calls.
    // Since this is global, other JRuby servlets in this servlet container
    // are affected...
    //
    // TODO: move to a better location in the code?  remove?
    if (config.getJrubyHome() != null) {
      System.setProperty("jruby.home", config.getJrubyHome());
    }

    final ScriptingContainer container = new ScriptingContainer(config.getScope());

    container.setCompileMode(config.getCompileMode());
    if (config.getJrubyHome() != null) {
      container.setHomeDirectory(config.getJrubyHome());
    }
    container.setCompatVersion(config.getCompatVersion());
    container.setCurrentDirectory(config.getAppRoot());
    // don't propagate ENV to global JVM level
    container.getProvider().getRubyInstanceConfig().setUpdateNativeENVEnabled(false);

    logger.info(
        "new ScriptingContainer scope={} compileMode={} jrubyHome={} compatVersion={}, pwd={}",
        new Object[] {
          config.getScope(),
          config.getCompileMode(),
          config.getJrubyHome(),
          config.getCompatVersion(),
          config.getAppRoot()
        });

    return container;
  }
示例#2
0
  private void setupJRuby(Activity startActivity) {
    System.setProperty("jruby.bytecode.version", "1.5");

    // enable proxy classes
    System.setProperty(
        "jruby.ji.proxyClassFactory", "com.rickbutton.rubydroid.DalvikProxyClassFactory");
    System.setProperty("jruby.ji.upper.case.package.name.allowed", "true");
    System.setProperty("jruby.class.cache.path", appContext.getDir("dex", 0).getAbsolutePath());

    // setup jruby home
    String apkName = getApkName();
    String jrubyHome = "file:" + apkName + "!/jruby.home";
    System.setProperty("jruby.home", jrubyHome);

    // configure jruby
    System.setProperty("jruby.compile.mode", "OFF"); // OFF OFFIR JITIR? FORCE FORCEIR
    // System.setProperty("jruby.compile.backend", "DALVIK");
    System.setProperty("jruby.bytecode.version", "1.6");
    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.ir.passes", "LocalOptimizationPass,DeadCodeElimination");
    System.setProperty("jruby.backtrace.style", "normal"); // normal raw full mri

    ClassLoader loader = new PathClassLoader(apkName, RubySystem.class.getClassLoader());

    // disable gems
    RubyInstanceConfig config = new RubyInstanceConfig();
    config.setDisableGems(true);
    config.setLoader(loader);
    Ruby.newInstance(config);

    container =
        new ScriptingContainer(LocalContextScope.SINGLETON, LocalVariableBehavior.PERSISTENT);
    container.setClassLoader(loader);

    Thread.currentThread().setContextClassLoader(loader);

    if (appContext.getFilesDir() != null) {
      container.setCurrentDirectory(appContext.getFilesDir().getPath());
    }

    container.put("$package_name", appContext.getPackageName());

    container.put("app_context", appContext);
    container.put("system", this);
    rubyContext = container.runScriptlet(PathType.CLASSPATH, "ruby/droid/init.rb");

    Object mainActivity = container.get("MainActivity");
    container.callMethod(rubyContext, "start_ruby_activity", mainActivity, startActivity);
  }