• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java CompatVersion类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.jruby.CompatVersion的典型用法代码示例。如果您正苦于以下问题:Java CompatVersion类的具体用法?Java CompatVersion怎么用?Java CompatVersion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CompatVersion类属于org.jruby包,在下文中一共展示了CompatVersion类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: evaluate

import org.jruby.CompatVersion; //导入依赖的package包/类
public Object evaluate(final String expression, final Map<String, ?> values) throws ExpressionEvaluationException {
    LOG.debug("Evaluating JRuby expression: {1}", expression);
    try {
        final RubyInstanceConfig config = new RubyInstanceConfig();
        config.setCompatVersion(CompatVersion.RUBY1_9);
        final Ruby runtime = JavaEmbedUtils.initialize(new ArrayList<String>(), config);

        final StringBuilder localVars = new StringBuilder();
        for (final Entry<String, ?> entry : values.entrySet()) {
            runtime.getGlobalVariables().set("$" + entry.getKey(), JavaEmbedUtils.javaToRuby(runtime, entry.getValue()));
            localVars.append(entry.getKey()) //
                .append("=$") //
                .append(entry.getKey()) //
                .append("\n");
        }
        final IRubyObject result = runtime.evalScriptlet(localVars + expression);
        return JavaEmbedUtils.rubyToJava(runtime, result, Object.class);
    } catch (final RuntimeException ex) {
        throw new ExpressionEvaluationException("Evaluating JRuby expression failed: " + expression, ex);
    }
}
 
开发者ID:sebthom,项目名称:oval,代码行数:22,代码来源:ExpressionLanguageJRubyImpl.java


示例2: createConfig

import org.jruby.CompatVersion; //导入依赖的package包/类
private RubyInstanceConfig createConfig() {
    final RubyInstanceConfig config = new RubyInstanceConfig();
    final String gem_home = getGemHome();
    if (gem_home != null || ruby_version != null) {
        @SuppressWarnings("unchecked")
        final Map<Object, Object> environment = config.getEnvironment();
        final Hashtable<Object, Object> newEnvironment = new Hashtable<>(environment);
        if (gem_home != null) {
            newEnvironment.put("GEM_HOME", gem_home);
        }
        if (ruby_version != null) {
            config.setCompatVersion(CompatVersion.getVersionFromString(ruby_version));
            newEnvironment.put("RUBY_VERSION", ruby_version);
        }
        config.setEnvironment(Collections.unmodifiableMap(newEnvironment));
    }
    return config;
}
 
开发者ID:timezra,项目名称:jruby-maven-plugin,代码行数:19,代码来源:JRubyMojo.java


示例3: createOptimizedConfiguration

import org.jruby.CompatVersion; //导入依赖的package包/类
private static RubyInstanceConfig createOptimizedConfiguration() {
    RubyInstanceConfig config = new RubyInstanceConfig();
    config.setCompatVersion(CompatVersion.RUBY2_0);
    config.setCompileMode(CompileMode.OFF);

    return config;
}
 
开发者ID:asciidoctor,项目名称:asciidoctorj,代码行数:8,代码来源:JRubyAsciidoctor.java


示例4: to_s

import org.jruby.CompatVersion; //导入依赖的package包/类
@Override
@JRubyMethod(name = "to_s", compat = CompatVersion.RUBY1_8)
public IRubyObject to_s(ThreadContext context) {
    if (exception != null && exception.getMessage() != null)
        return context.getRuntime().newString(exception.getMessage());
    else
        return super.to_s(context);
}
 
开发者ID:gocd,项目名称:gocd,代码行数:9,代码来源:XmlSyntaxError.java


示例5: to_s19

import org.jruby.CompatVersion; //导入依赖的package包/类
@JRubyMethod(name = "to_s", compat = CompatVersion.RUBY1_9)
public IRubyObject to_s19(ThreadContext context) {
    if (exception != null && exception.getMessage() != null)
        return context.getRuntime().newString(exception.getMessage());
    else
        return super.to_s19(context);
}
 
开发者ID:gocd,项目名称:gocd,代码行数:8,代码来源:XmlSyntaxError.java


示例6: JRubyWrapper

import org.jruby.CompatVersion; //导入依赖的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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Producer类代码示例发布时间:2022-05-23
下一篇:
Java SwipeAdapterInterface类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap