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


Java ScriptingContainer.runScriptlet方法代码示例

本文整理汇总了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());
		}
	}
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:20,代码来源:RubyJwtIntegrationTests.java

示例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()
            + ")");
}
 
开发者ID:gree,项目名称:hive-ruby-scripting,代码行数:23,代码来源:GenericUDFRubyExec.java

示例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;
}
 
开发者ID:apicloudcom,项目名称:APICloud-Studio,代码行数:11,代码来源:ScriptingEngine.java

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

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

示例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()
            + ")");
}
 
开发者ID:gree,项目名称:hive-ruby-scripting,代码行数:15,代码来源:GenericUDAFRubyInject.java

示例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;
}
 
开发者ID:opoo,项目名称:opoopress,代码行数:30,代码来源:CompassBuilder.java

示例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));
}
 
开发者ID:golo-lang,项目名称:golo-jmh-benchmarks,代码行数:7,代码来源:CodeLoader.java

示例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");
}
 
开发者ID:meew0,项目名称:Mewtwo,代码行数:58,代码来源:JRubyWrapper.java

示例10: setUp

import org.jruby.embed.ScriptingContainer; //导入方法依赖的package包/类
@Before public void setUp() {
  scriptingContainer = new ScriptingContainer();
  scriptingContainer.runScriptlet(PathType.CLASSPATH, "enumerable_with_close.rb");
}
 
开发者ID:square,项目名称:rack-servlet,代码行数:5,代码来源:JRubyRackBodyIteratorTest.java


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