本文整理汇总了Java中org.jruby.javasupport.JavaEmbedUtils.initialize方法的典型用法代码示例。如果您正苦于以下问题:Java JavaEmbedUtils.initialize方法的具体用法?Java JavaEmbedUtils.initialize怎么用?Java JavaEmbedUtils.initialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jruby.javasupport.JavaEmbedUtils
的用法示例。
在下文中一共展示了JavaEmbedUtils.initialize方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInitRuby
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
protected Callable<Ruby> getInitRuby(final Writer out, final Writer err) {
return new Callable<Ruby>() {
@Override public Ruby call() throws Exception {
RubyInstanceConfig config = new RubyInstanceConfig();
config.setCompileMode(CompileMode.OFF);
List<String> loadPaths = new ArrayList<String>();
setModule(loadPaths);
String appRubyPath = System.getProperty(PROP_APPLICATION_RUBYPATH);
if (appRubyPath != null) {
StringTokenizer tok = new StringTokenizer(appRubyPath, ";");
while (tok.hasMoreTokens()) {
loadPaths.add(tok.nextToken().replace('/', File.separatorChar));
}
}
config.setOutput(new PrintStream(new WriterOutputStream(out)));
config.setError(new PrintStream(new WriterOutputStream(err)));
Ruby interpreter = JavaEmbedUtils.initialize(loadPaths, config);
interpreter.evalScriptlet("require 'selenium/webdriver'");
interpreter.evalScriptlet("require 'marathon/results'");
interpreter.evalScriptlet("require 'marathon/playback-" + framework + "'");
return interpreter;
}
};
}
示例2: evaluate
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的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);
}
}
示例3: asciidoctor
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
@Bean
public Asciidoctor asciidoctor() {
RubyInstanceConfig rubyInstanceConfig = new RubyInstanceConfig();
rubyInstanceConfig.setLoader(this.getClass().getClassLoader());
JavaEmbedUtils.initialize(Arrays.asList("META-INF/jruby.home/lib/ruby/2.0", "classpath:/gems/asciidoctor-1.5.4/lib"), rubyInstanceConfig);
return create(this.getClass().getClassLoader());
}
示例4: doCompile
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
public JRubyCompiledScript doCompile(Script script) throws ScriptCompilationException {
Ruby runtime = JavaEmbedUtils.initialize(new ArrayList());
IRubyObject rubyScript = JavaEmbedUtils.javaToRuby(runtime, script.getScriptAsString());
try {
Node node = runtime.parse(rubyScript.asSymbol(), "<unknown>", null, 0);
return new JRubyCompiledScript(runtime, node);
} catch (Exception e) {
throw new ScriptExecutionException("Failed to execute script [" + script.getName() + "]", e);
}
}
示例5: RSpecTestRunner
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
public RSpecTestRunner(Class<?> testClass) throws InitializationError {
super(testClass);
rubyConfig = new RubyInstanceConfig();
Map<String, String> environment = new HashMap<>(System.getenv());
environment.put("GEM_HOME", GEM_HOME.toString());
environment.put("GEM_PATH", GEM_HOME.toString());
rubyConfig.setEnvironment(environment);
runtime = JavaEmbedUtils.initialize(singletonList("src/test/ruby"), rubyConfig);
invokeFunction(null, "require", "test_runner");
}
示例6: initializeRuntime
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
/**
* Initializes an instance of the {@link org.jruby.Ruby} runtime.
*/
private static Ruby initializeRuntime() {
return JavaEmbedUtils.initialize(Collections.EMPTY_LIST);
}
示例7: initializeRuntime
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
/**
* Initializes an instance of the {@link org.jruby.Ruby} runtime.
*/
@SuppressWarnings("unchecked")
private static Ruby initializeRuntime() {
return JavaEmbedUtils.initialize(Collections.EMPTY_LIST);
}
示例8: createJRubyAsciidoctorInstance
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
private static Asciidoctor createJRubyAsciidoctorInstance(Map<String, Object> environmentVars) {
RubyInstanceConfig config = createOptimizedConfiguration();
injectEnvironmentVariables(config, environmentVars);
Ruby rubyRuntime = JavaEmbedUtils.initialize(Collections.EMPTY_LIST, config);
JRubyRuntimeContext.set(rubyRuntime);
JRubyAsciidoctorModuleFactory jRubyAsciidoctorModuleFactory = new JRubyAsciidoctorModuleFactory(rubyRuntime);
AsciidoctorModule asciidoctorModule = jRubyAsciidoctorModuleFactory.createAsciidoctorModule();
JRubyAsciidoctor jRubyAsciidoctor = new JRubyAsciidoctor(asciidoctorModule, rubyRuntime);
return jRubyAsciidoctor;
}