Refine search
@Test public void testRunShellTests() throws IOException { System.setProperty("shell.test.include", "quotas_test.rb"); // Start all ruby tests jruby.runScriptlet(PathType.ABSOLUTE, "src/test/ruby/tests_runner.rb"); } }
public void execute(final ExecuteContext context) throws Exception { jruby.callMethod(script, "call", context); }
@BeforeClass public static void setUpBeforeClass() throws Exception { // no cluster List<String> loadPaths = new ArrayList<>(2); loadPaths.add("src/main/ruby"); loadPaths.add("src/test/ruby"); jruby.setLoadPaths(loadPaths); jruby.put("$TEST_CLUSTER", TEST_UTIL); System.setProperty("jruby.jit.logging.verbose", "true"); System.setProperty("jruby.jit.logging", "true"); System.setProperty("jruby.native.verbose", "true"); }
ScriptingContainer sc = new ScriptingContainer(); sc.setLoadPaths(Arrays.asList("folder1", "folder2")); File server = new File("server.rb"); sc.runScriptlet(new FileReader(server), server.getName());
public class Main { public static void main(String[] args){ ScriptingContainer container = new ScriptingContainer(); container.put("a", 1234); Object v = container.runScriptlet("a += 10; a"); System.out.println(v); } }
@Override public void initialize(BSFManager manager, String language, Vector someDeclaredBeans) throws BSFException { super.initialize(manager, language, someDeclaredBeans); LocalContextScope scope = SystemPropertyCatcher.getScope(LocalContextScope.SINGLETON); LocalVariableBehavior behavior = LocalVariableBehavior.BSF; container = new ScriptingContainer(scope, behavior); SystemPropertyCatcher.setConfiguration(container); //container.getProvider().setLoadPaths(getClassPath(manager)); if (!SystemPropertyCatcher.isRuby19(language)) { container.getProvider().getRubyInstanceConfig().setCompatVersion(CompatVersion.RUBY1_8); } Ruby runtime = container.getProvider().getRuntime(); if (someDeclaredBeans != null && someDeclaredBeans.size() > 0) { for (int i = 0; i < someDeclaredBeans.size(); i++) { BSFDeclaredBean bean = (BSFDeclaredBean) someDeclaredBeans.get(i); setVariable(bean); } } runtime.getGlobalVariables().defineReadonly("$bsf", new FunctionsGlobalVariable(runtime, new BSFFunctions(manager, this)), GlobalVariable.Scope.GLOBAL); }
private IRubyObject createApplication() { // There's a lot you could do here; for now, we just read a rackup file from the classpath, // then build a Rack application based on it. ScriptingContainer container = new ScriptingContainer(); container.put("builder_script", readResource("config.ru")); return container.parse("require 'rack'; Rack::Builder.new_from_string(builder_script)").run(); }
public Object eval(Reader reader, ScriptContext context) throws ScriptException { if (reader == null || context == null) { throw new NullPointerException("either reader or context is null"); } String filename = Utils.getFilename(context); try { if (Utils.isClearVariablesOn(context)) { container.clear(); } Utils.preEval(container, context); EmbedEvalUnit unit = container.parse(reader, filename, Utils.getLineNumber(context)); IRubyObject ret = unit.run(); return JavaEmbedUtils.rubyToJava(ret); } catch (Exception e) { throw wrapException(e); } finally { Utils.postEval(container, context); boolean termination = Utils.isTerminationOn(context); if (termination) { container.terminate(); } } }
public JRubyFacet() { // TODO: is this too early? Shall we allow registrations later? languages.addAll(Facet.discoverExtensions(RubyTemplateLanguage.class, Thread.currentThread().getContextClassLoader(), getClass().getClassLoader())); container = new ScriptingContainer(LocalContextScope.SINGLETHREAD); // we don't want any funny multiplexing from ScriptingContainer. container.runScriptlet("require 'org/kohsuke/stapler/jelly/jruby/JRubyJellyScriptImpl'"); navigator = new RubyKlassNavigator(container.getProvider().getRuntime(), getClass().getClassLoader()); for (RubyTemplateLanguage l : languages) { templateContainers.put(l.getScriptExtension(),l.createContainer(container)); tearOffTypes.add(l.getTearOffClass()); } }
public Object eval(String script, ScriptContext context) throws ScriptException { if (script == null || context == null) { throw new NullPointerException("either script or context is null"); } container.setScriptFilename(Utils.getFilename(context)); try { if (Utils.isClearVariablesOn(context)) { container.clear(); } Utils.preEval(container, context); EmbedEvalUnit unit = container.parse(script, Utils.getLineNumber(context)); IRubyObject ret = unit.run(); return JavaEmbedUtils.rubyToJava(ret); } catch (Exception e) { throw wrapException(e); } finally { Utils.postEval(container, context); boolean termination = Utils.isTerminationOn(context); if (termination) { container.terminate(); } } }
import org.jruby.embed.ScriptingContainer; public class Main { public static void main(String[] args) { ScriptingContainer container = new ScriptingContainer(); container.runScriptlet("require './core.jar'"); container.runScriptlet("require 'core/lib/gui'"); } }
private void setVariable(BSFDeclaredBean bean) { String name = bean.name; if ("$bsf".equals(name)) { return; } if (!name.startsWith("$")) { name = "$".concat(name); } RubyObject receiver = (RubyObject)container.getProvider().getRuntime().getTopSelf(); BiVariable v = VariableInterceptor.getVariableInstance(LocalVariableBehavior.BSF,receiver, name, bean.bean, bean.type); container.getVarMap().setVariable(receiver, v); }
@Override public void setup(OperatorContext context) { sc = new ScriptingContainer(LocalVariableBehavior.PERSISTENT); for (String s : setupScripts) { EvalUnit unit = sc.parse(s); unit.run(); } if (type == Type.EVAL) { unit = sc.parse(script); } }
public static void main(String[] args) { final StringBuilder b = new StringBuilder(); for (int i = 0; i < 3; i++) { final ScriptingContainer container = new ScriptingContainer(LocalContextScope.CONCURRENT, LocalVariableBehavior.PERSISTENT); final PrintStream printStream = PrintStreams.printer(Printers.stringBuilder(b), LineEnding.CR, Charset.defaultCharset()); container.setOutput(printStream); container.setError(printStream); // yes same as out, still works. container.runScriptlet("puts \"hello" + i + "\"\n"); printStream.flush(); System.out.println(b.toString()); // container.resetWriter(); <-- blows up // container.resetErrorWriter(); container.terminate(); } }
/** * Sets JRuby home if it is given by a JRUBY_HOME environment variable, * jruby.home system property, or jury.home in jruby-complete.jar * * @param container ScriptingContainer to be set jruby home. */ @Deprecated public static void setJRubyHome(ScriptingContainer container) { String jrubyhome = findJRubyHome(container); if (jrubyhome != null) { container.getProvider().getRubyInstanceConfig().setJRubyHome(jrubyhome); } }
@Override protected RubyTemplateContainer createContainer(ScriptingContainer jruby) { jruby.put("gem_path", getClass().getResource("/gem").getPath()); return new RubyTemplateContainer( (RubyClass)jruby.runScriptlet("ENV['GEM_PATH'] = gem_path\n" + "require 'rubygems'\n" + "require 'org/kohsuke/stapler/jelly/jruby/JRubyJellyScriptImpl'\n"+ "require 'org/kohsuke/stapler/jelly/jruby/haml/JRubyJellyHamlScript'\n"+ "JRubyJellyScriptImpl::JRubyJellyHamlScript" ), this, jruby); } }
public Object eval(ScriptContext context) throws ScriptException { try { if (Utils.isClearVariablesOn(context)) { container.clear(); } Utils.preEval(container, context); IRubyObject ret = unit.run(); if (!(ret instanceof RubyNil)) { return JavaEmbedUtils.rubyToJava(ret); } return null; } catch (Exception e) { throw wrapException(e); } finally { Utils.postEval(container, context); boolean termination = Utils.isTerminationOn(context); if (termination) { container.terminate(); } } }
ScriptingContainer container = new ScriptingContainer(); try { Reader reader = new FileReader(myEngine); // rest of your code here... } finally { container.terminate(); }
/** * create a new ruby object of the bundler command */ private static Object newScript(final ScriptingContainer scriptingContainer) { IRubyObject runnerClass = scriptingContainer.parse(PathType.CLASSPATH, "nexus/bundle_runner.rb").run(); return scriptingContainer.callMethod(runnerClass, "new", IRubyObject.class); }