当前位置: 首页>>代码示例>>Java>>正文


Java ScriptingContainer.put方法代码示例

本文整理汇总了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;
}
 
开发者ID:mini2Dx,项目名称:miniscript,代码行数:34,代码来源:RubyScriptExecutor.java

示例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"));
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:15,代码来源:RubyJwtIntegrationTests.java

示例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();
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:16,代码来源:RubyJwtIntegrationTests.java

示例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();
}
 
开发者ID:square,项目名称:rack-servlet,代码行数:8,代码来源:ExampleService.java

示例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;
}
 
开发者ID:ricardjp,项目名称:jcompass,代码行数:37,代码来源:CompassCompiler.java

示例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());
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:19,代码来源:JRubyKnowledgeBaseInterpreter.java


注:本文中的org.jruby.embed.ScriptingContainer.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。