@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"); }
@BeforeClass public static void setUpBeforeClass() throws Exception { // Start mini cluster TEST_UTIL.getConfiguration().setInt("hbase.regionserver.msginterval", 100); TEST_UTIL.getConfiguration().setInt("hbase.client.pause", 250); TEST_UTIL.getConfiguration().setBoolean("hbase.quota.enabled", true); TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 6); TEST_UTIL.getConfiguration().setBoolean(CoprocessorHost.ABORT_ON_ERROR_KEY, false); TEST_UTIL.getConfiguration().setInt("hfile.format.version", 3); // Below settings are necessary for task monitor test. TEST_UTIL.getConfiguration().setInt(HConstants.MASTER_INFO_PORT, 0); TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_INFO_PORT, 0); TEST_UTIL.getConfiguration().setBoolean(HConstants.REGIONSERVER_INFO_PORT_AUTO, true); // Security setup configuration SecureTestUtil.enableSecurity(TEST_UTIL.getConfiguration()); VisibilityTestUtil.enableVisiblityLabels(TEST_UTIL.getConfiguration()); TEST_UTIL.startMiniCluster(); // Configure jruby runtime 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"); }
@BeforeClass public static void setUpBeforeClass() throws Exception { basePath = System.getProperty("basedir"); // Start mini cluster TEST_UTIL.getConfiguration().setInt("hbase.regionserver.msginterval", 100); TEST_UTIL.getConfiguration().setInt("hbase.client.pause", 250); TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 6); TEST_UTIL.getConfiguration().setBoolean(CoprocessorHost.ABORT_ON_ERROR_KEY, false); TEST_UTIL.getConfiguration().setInt("hfile.format.version", 3); // Security setup configuration SecureTestUtil.enableSecurity(TEST_UTIL.getConfiguration()); VisibilityTestUtil.enableVisiblityLabels(TEST_UTIL.getConfiguration()); //Setup RegionServer Groups TEST_UTIL.getConfiguration().set( HConstants.HBASE_MASTER_LOADBALANCER_CLASS, RSGroupBasedLoadBalancer.class.getName()); TEST_UTIL.getConfiguration().set( CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, RSGroupAdminEndpoint.class.getName()); TEST_UTIL.startMiniCluster(4); // Configure jruby runtime List<String> loadPaths = new ArrayList<>(2); loadPaths.add(basePath+"/src/main/ruby"); loadPaths.add(basePath+"/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"); }
@Override public void execute() throws BuildException { container.put("$project", getProject()); // set project so jruby ant lib gets it }
@Override public void execute() throws BuildException { container.put("$project", getProject()); // set project so jruby ant lib gets it }
@Override public void execute() throws BuildException { container.put("$project", getProject()); // set project so jruby ant lib gets it }
@Override public void execute() throws BuildException { container.put("$project", getProject()); // set project so jruby ant lib gets it }
@Override public Object run(Map<String, Object> variables) { container.clear(); if (variables != null) { for (Entry<String, Object> entry : variables.entrySet()) { container.put(entry.getKey(), entry.getValue()); } } return unit.run(); } }
@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 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); } }
ScriptingContainer container = new ScriptingContainer(); container.put("x", 12345); container.runScriptlet("puts x.to_s(2)");
import org.jruby.embed.ScriptingContainer; public class RubyScript { private RubyScript() { int add = 5; //initializes Ruby Environment ScriptingContainer container = new ScriptingContainer(); //Sets Ruby var 'ans' as java.lang.Integer: add container.put("ans",add); container.runScriptlet("puts ans"); System.out.println(add + add); } public static void main(String[] args) { new RubyScript(); } }
@Override public Object apply(String file, int line, int col, Object funcBody, Vector paramNames, Vector args) { ThreadContext context = container.getProvider().getRuntime().getCurrentContext(); try { if (paramNames != null && args != null) { for (int i = 0; i < paramNames.size(); i++) { Object o = paramNames.get(i); if (o instanceof String) { String name = (String) o; container.put(name, args.get(i)); } } } return run(file, line, funcBody); } catch (StackOverflowError soe) { throw context.runtime.newSystemStackError("stack level too deep", soe); } }
@Override public Object apply(String file, int line, int col, Object funcBody, Vector paramNames, Vector args) { ThreadContext context = container.getProvider().getRuntime().getCurrentContext(); try { if (paramNames != null && args != null) { for (int i = 0; i < paramNames.size(); i++) { Object o = paramNames.get(i); if (o instanceof String) { String name = (String) o; container.put(name, args.get(i)); } } } return run(file, line, funcBody); } catch (StackOverflowError soe) { throw context.runtime.newSystemStackError("stack level too deep", soe); } }
@Override public Object apply(String file, int line, int col, Object funcBody, Vector paramNames, Vector args) { ThreadContext context = container.getProvider().getRuntime().getCurrentContext(); try { if (paramNames != null && args != null) { for (int i = 0; i < paramNames.size(); i++) { Object o = paramNames.get(i); if (o instanceof String) { String name = (String) o; container.put(name, args.get(i)); } } } return run(file, line, funcBody); } catch (StackOverflowError soe) { throw context.runtime.newSystemStackError("stack level too deep", soe); } }
@Override public Object apply(String file, int line, int col, Object funcBody, Vector paramNames, Vector args) { ThreadContext context = container.getProvider().getRuntime().getCurrentContext(); try { if (paramNames != null && args != null) { for (int i = 0; i < paramNames.size(); i++) { Object o = paramNames.get(i); if (o instanceof String) { String name = (String) o; container.put(name, args.get(i)); } } } return run(file, line, funcBody); } catch (StackOverflowError soe) { throw context.runtime.newSystemStackError("stack level too deep", soe); } }
@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"); }
@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"); }
@Override public final String transform(HttpServletRewrite event, String input) { ScriptingContainer container = getContainer(event.getServletContext()); try { Object result = null; // 'input' will be the string to transform container.put("input", input); // execute the script returned by the implementation result = runScript(container); // the result must be a string return result != null ? result.toString() : null; } finally { if (container != null) container.clear(); } }
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(); }