本文整理汇总了Java中org.jruby.embed.ScriptingContainer.runScriptlet方法的典型用法代码示例。如果您正苦于以下问题:Java ScriptingContainer.runScriptlet方法的具体用法?Java ScriptingContainer.runScriptlet怎么用?Java ScriptingContainer.runScriptlet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jruby.embed.ScriptingContainer
的用法示例。
在下文中一共展示了ScriptingContainer.runScriptlet方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: JRubyJwtInstalled
import org.jruby.embed.ScriptingContainer; //导入方法依赖的package包/类
public JRubyJwtInstalled() {
if (!setupOkSet) {
setupOk = false;
setupOkSet = true;
try {
String script =
"require \"rubygems\"\n" +
"require \"jwt\"\n" +
"require \"bouncy-castle-java\"\n" +
"require \"openssl\"";
ScriptingContainer container = new ScriptingContainer();
container.runScriptlet(script);
setupOk = true;
}
catch (Exception e) {
System.out.println("jruby.home not set or JWT gem not available. JWT ruby integration tests will be skipped" + e.getMessage());
}
}
}
示例2: initializeJRubyRuntime
import org.jruby.embed.ScriptingContainer; //导入方法依赖的package包/类
private void initializeJRubyRuntime() {
container = new ScriptingContainer(org.jruby.embed.LocalContextScope.SINGLETHREAD);
if (jobConf != null) {
container.getLoadPaths().add(jobConf.get(CONF_JRB_LOAD_PATH));
}
if (rbScriptParam.startsWith(MODE_METHOD_MARK)) {
mode = MODE.METHOD;
evaluateMethod = rbScriptParam.substring(1);
container.setAttribute(AttributeName.SHARING_VARIABLES, false);
receiver = container.runScriptlet(rbEnvScript);
} else {
mode = MODE.EVAL;
evalUnit = container.parse(rbScriptParam);
}
LOG.info("initialized JRuby runtime (" +
container.getCompatVersion() + ", " +
container.getCompileMode()
+ ")");
}
示例3: getInitializedScriptingContainer
import org.jruby.embed.ScriptingContainer; //导入方法依赖的package包/类
public synchronized ScriptingContainer getInitializedScriptingContainer()
{
ScriptingContainer sc = getScriptingContainer();
if (!initialized)
{
sc.runScriptlet("require 'ruble'"); //$NON-NLS-1$
initialized = true;
}
return sc;
}
示例4: rubyCanDecodeHmacSignedToken
import org.jruby.embed.ScriptingContainer; //导入方法依赖的package包/类
@Test
public void rubyCanDecodeHmacSignedToken() throws Exception {
Jwt jwt = JwtHelper.encode(TEST_CLAIMS, hmac);
ScriptingContainer container = new ScriptingContainer();
container.put("@token", jwt.getEncoded());
container.put("@claims", "");
String script =
"require \"rubygems\"\n" +
"require \"jwt\"\n" +
"@claims = JWT.decode(@token, \"secret\", \"HS256\").to_json\n" +
"puts @claims";
container.runScriptlet(script);
assertEquals(TEST_CLAIMS, container.get("@claims"));
}
示例5: canDecodeRubyHmacSignedToken
import org.jruby.embed.ScriptingContainer; //导入方法依赖的package包/类
@Test
public void canDecodeRubyHmacSignedToken() throws Exception {
ScriptingContainer container = new ScriptingContainer();
container.put("@token", "xxx");
String script =
"require \"rubygems\"\n" +
"require \"jwt\"\n" +
"@token = JWT.encode({\"some\" => \"payload\"}, \"secret\", \"HS256\")\n" +
"puts @token";
container.runScriptlet(script);
String token = (String) container.get("@token");
Jwt jwt = JwtHelper.decodeAndVerify(token, hmac);
assertEquals(TEST_CLAIMS, jwt.getClaims());
container.terminate();
}
示例6: initializeJRubyRuntime
import org.jruby.embed.ScriptingContainer; //导入方法依赖的package包/类
private void initializeJRubyRuntime() {
container = new ScriptingContainer(org.jruby.embed.LocalContextScope.SINGLETHREAD);
if (jobConf != null) {
container.getLoadPaths().add(jobConf.get(RubyScriptingUtils.CONF_JRB_LOAD_PATH));
}
container.setAttribute(AttributeName.SHARING_VARIABLES, false);
receiver = container.runScriptlet(rbEnvScript);
LOG.info("initialized JRuby runtime (" +
container.getCompatVersion() + ", " +
container.getCompileMode()
+ ")");
}
示例7: createCache
import org.jruby.embed.ScriptingContainer; //导入方法依赖的package包/类
private Properties createCache(File configFile, File cacheFile) {
ScriptingContainer container = new ScriptingContainer(LocalVariableBehavior.PERSISTENT);
container.runScriptlet(PathType.ABSOLUTE, configFile.getAbsolutePath());
@SuppressWarnings("unchecked")
BiVariableMap<String, Object> varMap = container.getVarMap();
@SuppressWarnings("unchecked")
Set<Map.Entry<String, Object>> entrySet = varMap.entrySet();
Properties props = new Properties();
for (Map.Entry<String, Object> en : entrySet) {
if (en.getValue() instanceof String) {
props.setProperty(en.getKey(), (String) en.getValue());
}
}
//save
FileOutputStream outputStream = null;
try {
outputStream = new FileOutputStream(cacheFile);
props.store(outputStream, "Compass config cache");
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
IOUtils.closeQuietly(outputStream);
}
return props;
}
示例8: jruby
import org.jruby.embed.ScriptingContainer; //导入方法依赖的package包/类
public JRubyContainerAndReceiver jruby(String file) {
ScriptingContainer container = new ScriptingContainer();
String filename = "snippets/jruby/" + file + ".rb";
return new JRubyContainerAndReceiver(container,
container.runScriptlet(CodeLoader.class.getResourceAsStream("/" + filename), filename));
}
示例9: JRubyWrapper
import org.jruby.embed.ScriptingContainer; //导入方法依赖的package包/类
/**
* Create a new JRuby wrapper.
* @param profile whether or not profiling is enabled
*/
public JRubyWrapper(boolean profile) {
rb = new ScriptingContainer(LocalContextScope.THREADSAFE);
rb.setCompatVersion(CompatVersion.RUBY1_9);
rb.setCurrentDirectory(Paths.get("").toAbsolutePath().toString()); // set working directory of scripts to working directory of application
@SuppressWarnings("unchecked")
Map<String, String> env = new HashMap<>(rb.getEnvironment());
env.put("GEM_PATH", Paths.get("lib/gems").toAbsolutePath().toString());
MewtwoMain.mewtwoLogger.info("Setting GEM_PATH of container to " + env.get("GEM_PATH"));
rb.setEnvironment(env);
ArrayList<String> loadPaths = new ArrayList<>();
File gemsFile = Paths.get("lib/gems").toFile();
File[] files = gemsFile.listFiles();
for(File child : files != null ? files : new File[0]) {
String subPath = Paths.get(child.getAbsolutePath()).resolve("lib").toString();
MewtwoMain.mewtwoLogger.info("Adding '" + subPath + "' to loadPaths");
loadPaths.add(subPath);
}
rb.setLoadPaths(loadPaths);
swOut = new StringWriter();
swErr = new StringWriter();
PrintWriter pwOut = new PrintWriter(swOut);
PrintWriter pwErr = new PrintWriter(swErr);
rb.setOutput(pwOut);
rb.setError(pwErr);
if(profile) {
rb.setProfile(RubyInstanceConfig.ProfilingMode.GRAPH);
try {
rb.setProfileOutput(new ProfileOutput(new File("profile.txt")));
} catch(IOException e) {
MewtwoMain.mewtwoLogger.error("Could not initialize JRuby profiler! Disabling profiling.");
}
}
long time = System.currentTimeMillis();
MewtwoMain.mewtwoLogger.info("Initializing ScriptingContainer - this might take a few seconds!");
rb.runScriptlet("require 'java'; Java::Meew0Mewtwo::MewtwoMain.mewtwoLogger.info('Hello world! This is JRuby')");
MewtwoMain.mewtwoLogger.info("ScriptingContainer successfully initialized in " +
(System.currentTimeMillis() - time) + " ms");
}
示例10: setUp
import org.jruby.embed.ScriptingContainer; //导入方法依赖的package包/类
@Before public void setUp() {
scriptingContainer = new ScriptingContainer();
scriptingContainer.runScriptlet(PathType.CLASSPATH, "enumerable_with_close.rb");
}