本文整理汇总了Java中org.jruby.embed.ScriptingContainer.put方法的典型用法代码示例。如果您正苦于以下问题:Java ScriptingContainer.put方法的具体用法?Java ScriptingContainer.put怎么用?Java ScriptingContainer.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jruby.embed.ScriptingContainer
的用法示例。
在下文中一共展示了ScriptingContainer.put方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.jruby.embed.ScriptingContainer; //导入方法依赖的package包/类
@Override
public ScriptExecutionResult execute(GameScript<EmbedEvalUnit> s, ScriptBindings bindings,
boolean returnResult) throws Exception {
PerThreadGameScript<EmbedEvalUnit> script = (PerThreadGameScript<EmbedEvalUnit>) s;
ScriptingContainer scriptingContainer = executorPool.getLocalScriptingContainer();
for (String variableName : bindings.keySet()) {
scriptingContainer.put(variableName, bindings.get(variableName));
}
if (!script.hasLocalScript()) {
script.putLocalScript(scriptingContainer.parse(script.getContent()));
}
try {
EmbedEvalUnit embedEvalUnit = script.getScript();
embedEvalUnit.run();
} catch (Exception e) {
if(e.getCause() instanceof ScriptSkippedException) {
throw new ScriptSkippedException();
} else {
throw e;
}
}
if (!returnResult) {
scriptingContainer.clear();
return null;
}
ScriptExecutionResult executionResult = new ScriptExecutionResult(scriptingContainer.getVarMap().getMap());
scriptingContainer.clear();
return executionResult;
}
示例2: 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"));
}
示例3: 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();
}
示例4: createApplication
import org.jruby.embed.ScriptingContainer; //导入方法依赖的package包/类
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();
}
示例5: getScript
import org.jruby.embed.ScriptingContainer; //导入方法依赖的package包/类
public JavaEmbedUtils.EvalUnit getScript() throws FileNotFoundException {
if (this.unit == null) {
if (!this.configFile.exists()) {
throw new FileNotFoundException("Configuration file does not exist");
}
ScriptingContainer scriptingContainer = new ScriptingContainer(
LocalContextScope.THREADSAFE,
LocalVariableBehavior.PERSISTENT);
scriptingContainer.setOutput(new PrintStream(new NullOutputStream()));
StringBuilder script = new StringBuilder()
.append("require 'compass'\n")
.append("require 'compass/sass_compiler'\n")
.append("Compass.reset_configuration!\n")
.append("Compass.add_project_configuration configLocation\n")
// remove color codes since they cannot be proceeded correctly by IDE consoles
.append("Compass.configuration.color_output = false\n")
.append("Compass.configure_sass_plugin!\n")
.append("Compass.configuration.on_stylesheet_saved { |filename| callback_logger.onStylesheetSaved(filename) }\n")
.append("Compass.configuration.on_stylesheet_error { |filename, message| callback_logger.onStylesheetError(filename, message) }\n")
.append("Compass.configuration.on_sprite_saved { |filename| callback_logger.onSpriteSaved(filename) }\n")
.append("Dir.chdir(File.dirname(configLocation)) do\n")
.append(" Compass.sass_compiler.compile!\n")
.append("end\n");
scriptingContainer.put("configLocation", this.configFile.getAbsolutePath().replaceAll("\\\\", "/"));
scriptingContainer.put("callback_logger", callbackLogger);
this.unit = scriptingContainer.parse(script.toString());
}
return this.unit;
}
示例6: prepareInterpreter
import org.jruby.embed.ScriptingContainer; //导入方法依赖的package包/类
@Override
protected void prepareInterpreter() {
container = new ScriptingContainer(LocalContextScope.SINGLETHREAD, LocalVariableBehavior.PERSISTENT);
setLoadPaths(getEngineOperations() != null ? getEngineOperations().getEngine() : null);
addSpecific();
PROCESSOR_CLASSES.forEach((interfaceClass, scriptClass) -> addImport(scriptClass, interfaceClass.getSimpleName()));
addImport(JRubyPlugin.class, Plugin.class.getSimpleName());
getStandardImportClasses().forEach(cls -> addImport(cls));
addImport(RubyUtils.class);
container.put(createVariableName(KnowledgeBaseConstants.VAR_ENGINE_OPERATIONS), getEngineOperations());
container.setErrorWriter(new JRubyLogErrorWriter());
}