本文整理汇总了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;未经允许,请勿转载。 |
请发表评论