public void start() throws IOException { config = new RubyInstanceConfig(parentRuntime.getInstanceConfig()); config.setCurrentDirectory(pwd.toString()); config.setEnvironment(environmentMap(env)); if (pipedStreams) { config.setInput(new PipedInputStream(processInput)); config.setOutput(new PrintStream(new PipedOutputStream(processOutput))); config.setError(new PrintStream(new PipedOutputStream(processError))); } String procName = "piped"; if (argArray.length > 0) { procName = argArray[0]; } processThread = new Thread(this, "ScriptThreadProcess: " + procName); processThread.setDaemon(true); processThread.start(); }
JRubyMain(String bundleDisableSharedGems, String currentDirectory, String jrubyHome, RubyInstanceConfig config) { super(config); // TODO have property to disable hard exit - see warbler config.setHardExit(true); config.setCurrentDirectory(currentDirectory + "/"); config.setJRubyHome(jrubyHome); // for jruby 1.7.x add the current directory explicitly to LOAD_PATH config.setLoadPaths(Arrays.asList(currentDirectory + "/")); Map<String, String> env = new HashMap<String, String>(System.getenv()); // we assume the embedded jars are placed in jars directory env.put("JARS_HOME", currentDirectory + "/jars"); // we assume the embedded gems are placed at the root of the "archive" env.put("GEM_PATH", currentDirectory + "/"); // make sure we do not inherit it from outside // NOTE: setting it to GEM_PATH will break the extractingMain cases env.put("GEM_HOME", jrubyHome + "/lib/ruby/gems/shared"); if (bundleDisableSharedGems != null) { // for spawning jruby we need bundler to tell to // NOT clean up the load Path env.put("BUNDLE_DISABLE_SHARED_GEMS", bundleDisableSharedGems); } config.setEnvironment(env); // older jruby-1.7.x does need this config.setLoader(JRubyMain.class.getClassLoader()); }
public String getEnvironment() { return ruby.get().getInstanceConfig().getEnvironment().toString(); }
private static RubyInstanceConfig createOptimizedConfiguration() { RubyInstanceConfig config = new RubyInstanceConfig(); config.setCompatVersion(CompatVersion.RUBY1_9); config.setCompileMode(CompileMode.OFF); return config; }
/** * Generate a class cache. This will end up setting max cache size per JRuby preferences * (e.g. jruby.jit.max). * * @param loader use the provided classloader to create the cache * @return */ public static ClassCache createClassCache(ClassLoader loader) { return new ClassCache(loader, new RubyInstanceConfig().getJitMax()); }
private Main(boolean hardExit) { // used only from main(String[]), so we process dotfile here processDotfile(); this.config = new RubyInstanceConfig(); config.setHardExit(hardExit); }
config.setRecordSeparator("\u0000"); } else if (temp.equals("0")) { config.setRecordSeparator("\n\n"); } else if (temp.equals("777")) { config.setRecordSeparator("\uffff"); // Specify something that can't separate } else { try { int val = Integer.parseInt(temp, 8); config.setRecordSeparator("" + (char) val); } catch (Exception e) { MainExitException mee = new MainExitException(1, getArgumentError(" -0 must be followed by either 0, 777, or a valid octal value")); config.setSplit(true); break; case 'c': config.setShouldCheckSyntax(true); break; case 'C': try { String saved = grabValue(getArgumentError(" -C must be followed by a directory expression")); File base = new File(config.getCurrentDirectory()); File newDir = new File(saved); if (newDir.isAbsolute()) { config.setCurrentDirectory(newDir.getCanonicalPath()); } else { config.setCurrentDirectory(new File(base, newDir.getPath()).getCanonicalPath()); if (!(new File(config.getCurrentDirectory()).isDirectory())) { MainExitException mee = new MainExitException(1, "jruby: Can't chdir to " + saved + " (fatal)");
protected RubyInstanceConfig initRuntimeConfig(final RubyInstanceConfig config) { final RackConfig rackConfig = rackContext.getConfig(); config.setLoader(Thread.currentThread().getContextClassLoader()); final Map<String, String> env = config.getEnvironment(); if ( env != null && env.containsKey("RUBYOPT") ) { newEnv.put( "RUBYOPT", env.get("RUBYOPT") ); config.setEnvironment(newEnv); config.processArguments(rackConfig.getRuntimeArguments()); config.setCompatVersion(rackConfig.getCompatVersion()); final URL resource = Ruby.class.getResource("/META-INF/jruby.home"); if ( resource != null && "jar".equals( resource.getProtocol() ) ) { String home = config.getJRubyHome(); // uri: protocol only since 9k : if ( home == null || ! home.startsWith("uri:classloader:") ) { try { if ( home.charAt(last) == '/' ) home = home.substring(0, last); config.setJRubyHome(home);
static RubyInstanceConfig getGlobalRuntimeConfigOrNew() { return Ruby.isGlobalRuntimeReady() ? Ruby.getGlobalRuntime().getInstanceConfig() : new RubyInstanceConfig(); }
private RubyInstanceConfig createRuntimeConfig() { RubyInstanceConfig config = new RubyInstanceConfig(); config.setCompatVersion(CompatVersion.RUBY1_8); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader == null) { classLoader = ClassLoader.getSystemClassLoader(); } config.setClassCache(JavaEmbedUtils.createClassCache(classLoader)); URL resource = RubyInstanceConfig.class.getResource("/META-INF/jruby.home"); if (resource != null && resource.getProtocol().equals("jar")) { try { // http://weblogs.java.net/blog/2007/04/25/how-convert-javaneturl-javaiofile config.setJRubyHome(resource.toURI().getSchemeSpecificPart()); } catch (URISyntaxException e) { config.setJRubyHome(resource.getPath()); } } return config; }
public int run(NGContext context) { context.assertLoopbackClient(); RubyInstanceConfig config = new RubyInstanceConfig(); Main main = new Main(config); config.setCurrentDirectory(context.getWorkingDirectory()); config.setEnvironment(context.getEnv()); // reuse one cache of compiled bodies config.setClassCache(classCache); return main.run(context.getArgs()).getStatus(); } }
private RubyInstanceConfig createRuntimeConfig() { RubyInstanceConfig config = new RubyInstanceConfig(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader == null) { classLoader = ClassLoader.getSystemClassLoader(); } config.setClassCache(JavaEmbedUtils.createClassCache(classLoader)); URL resource = RubyInstanceConfig.class.getResource("/META-INF/jruby.home"); if (resource != null && resource.getProtocol().equals("jar")) { try { // http://weblogs.java.net/blog/2007/04/25/how-convert-javaneturl-javaiofile config.setJRubyHome(resource.toURI().getSchemeSpecificPart()); } catch (URISyntaxException e) { config.setJRubyHome(resource.getPath()); } } return config; }
/** * Returns a new instance of the JRuby runtime configured with defaults. * * @return the JRuby runtime * @see org.jruby.RubyInstanceConfig */ public static Ruby newInstance() { return newInstance(new RubyInstanceConfig()); }
public int run(NGContext context) { context.assertLoopbackClient(); RubyInstanceConfig config = new RubyInstanceConfig(); Main main = new Main(config); config.setCurrentDirectory(context.getWorkingDirectory()); config.setEnvironment(OSEnvironment.propertiesToStringMap(context.getEnv())); return main.run(context.getArgs()).getStatus(); } }
public void setJRubyHome(String home) { config.setJRubyHome(home); }
@JRubyMethod(meta = true) // for RubyGems' JRuby defaults public static IRubyObject classpath_launcher(ThreadContext context, IRubyObject recv) { final Ruby runtime = context.runtime; String launcher = runtime.getInstanceConfig().getEnvironment().get("RUBY"); if ( launcher == null ) launcher = ClasspathLauncher.jrubyCommand(runtime); return runtime.newString(launcher); }
private void initConfig() throws URISyntaxException, UnsupportedEncodingException { List<String> paths = SystemPropertyCatcher.findLoadPaths(); provider.getRubyInstanceConfig().setLoadPaths(paths); String home = SystemPropertyCatcher.findJRubyHome(this); if (home != null) { provider.getRubyInstanceConfig().setJRubyHome(home); } provider.getRubyInstanceConfig().setScriptFileName("<script>"); }
/** * Get an instance of a JRuby runtime. Provide any loadpaths you want used at startup. * * @param loadPaths to specify where to look for Ruby modules. * @param classCache to use as a common repository for cached classes * @return an instance */ public static Ruby initialize(List loadPaths, ClassCache classCache) { RubyInstanceConfig config = new RubyInstanceConfig(); if (classCache != null) { config.setClassCache(classCache); } return initialize(loadPaths, config); }
private void initEnvironment() { try { setEnvironment(System.getenv()); } catch (SecurityException se) { /* ignore missing getenv permission */ } }
/** * Returns the environment as a hash of Ruby strings. * * @param runtime */ public static Map<RubyString, RubyString> environmentVariableMap(Ruby runtime) { @SuppressWarnings("unchecked") Map<String, String> env = runtime.getInstanceConfig().getEnvironment(); if ( env != null ) return asMapOfRubyStrings(runtime, env); if ( Ruby.isSecurityRestricted() ) return Collections.emptyMap(); return asMapOfRubyStrings(runtime, System.getenv()); }