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


Java JavaEmbedUtils类代码示例

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


JavaEmbedUtils类属于org.jruby.javasupport包,在下文中一共展示了JavaEmbedUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
        }
    };
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:25,代码来源:RubyScript.java

示例2: resultsCapturesJavaError

import org.jruby.javasupport.JavaEmbedUtils; //导入依赖的package包/类
@Test(enabled = false) public void resultsCapturesJavaError() throws Exception {
    RubyScript script = new RubyScript(out, err, converToCode(SCRIPT_CONTENTS_ERROR_FROM_JAVA),
            new File(System.getProperty(Constants.PROP_PROJECT_DIR), "dummyfile.rb").getAbsolutePath(), false, null,
            Constants.FRAMEWORK_SWING);
    script.setDriverURL("");
    Ruby interpreter = script.getInterpreter();
    assertTrue("Collector not defined", interpreter.isClassDefined("Collector"));
    RubyClass collectorClass = interpreter.getClass("Collector");
    IRubyObject presult = JavaEmbedUtils.javaToRuby(interpreter, result);
    IRubyObject collector = collectorClass.newInstance(interpreter.getCurrentContext(), new IRubyObject[0], new Block(null));
    IRubyObject rubyObject = interpreter.evalScriptlet("proc { my_function }");
    try {
        collector.callMethod(interpreter.getCurrentContext(), "callprotected", new IRubyObject[] { rubyObject, presult });
    } catch (Throwable t) {

    }
    assertEquals(1, result.failureCount());
    Failure[] failures = result.failures();
    assertTrue("Should end with TestRubyScript.java. but has " + failures[0].getTraceback()[0].fileName,
            failures[0].getTraceback()[0].fileName.endsWith("TestRubyScript.java"));
    assertEquals("throwError", failures[0].getTraceback()[0].functionName);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:23,代码来源:RubyScriptTest.java

示例3: 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);
    }
}
 
开发者ID:sebthom,项目名称:oval,代码行数:22,代码来源:ExpressionLanguageJRubyImpl.java

示例4: modifyContext

import org.jruby.javasupport.JavaEmbedUtils; //导入依赖的package包/类
public void modifyContext(CommandElement command, CommandContext context)
{
	IEditorPart editor = this.getActiveEditor();

	if (editor != null && command != null)
	{
		Ruby runtime = command.getRuntime();

		if (runtime != null)
		{
			IRubyObject rubyInstance = ScriptUtils.instantiateClass(runtime, ScriptUtils.RUBLE_MODULE,
					EDITOR_RUBY_CLASS, JavaEmbedUtils.javaToRuby(runtime, editor));

			context.put(EDITOR_PROPERTY_NAME, rubyInstance);
		}
		else
		{
			context.put(EDITOR_PROPERTY_NAME, null);
		}
	}
}
 
开发者ID:apicloudcom,项目名称:APICloud-Studio,代码行数:22,代码来源:EditorContextContributor.java

示例5: convert

import org.jruby.javasupport.JavaEmbedUtils; //导入依赖的package包/类
@JRubyMethod(required = 1, optional = 2)
public IRubyObject convert(ThreadContext context, IRubyObject[] args) {
    AbstractNode node = NodeConverter.createASTNode(args[0]);

    Object ret = null;
    if (args.length == 1) {
        ret = delegate.convert(
                node,
                null,
                Collections.emptyMap());
    } else if (args.length == 2) {
        ret = delegate.convert(
                node,
                (String) JavaEmbedUtils.rubyToJava(getRuntime(), args[1], String.class),
                Collections.emptyMap());//RubyString.objAsString(context, args[1]).asJavaString());
    } else if (args.length == 3) {
        ret = delegate.convert(
                node,
                (String) JavaEmbedUtils.rubyToJava(getRuntime(), args[1], String.class),
                (Map) JavaEmbedUtils.rubyToJava(getRuntime(), args[2], Map.class));
    }
    return JavaEmbedUtils.javaToRuby(getRuntime(), ret);
}
 
开发者ID:asciidoctor,项目名称:asciidoctorj,代码行数:24,代码来源:ConverterProxy.java

示例6: createInline

import org.jruby.javasupport.JavaEmbedUtils; //导入依赖的package包/类
public Inline createInline(AbstractBlock parent, String context, String text, Map<String, Object> attributes, Map<String, Object> options) {
    
    options.put(Options.ATTRIBUTES, attributes);
    
    IRubyObject rubyClass = rubyRuntime.evalScriptlet("Asciidoctor::Inline");
    RubyHash convertedOptions = RubyHashUtil.convertMapToRubyHashWithSymbols(rubyRuntime, options);
    // FIXME hack to ensure we have the underlying Ruby instance
    try {
        parent = parent.delegate();
    } catch (Exception e) {}

    Object[] parameters = {
            parent,
            RubyUtils.toSymbol(rubyRuntime, context),
            text,
            convertedOptions };
    return (Inline) JavaEmbedUtils.invokeMethod(rubyRuntime, rubyClass,
            "new", parameters, Inline.class);
}
 
开发者ID:asciidoctor,项目名称:asciidoctorj,代码行数:20,代码来源:Processor.java

示例7: createBlock

import org.jruby.javasupport.JavaEmbedUtils; //导入依赖的package包/类
private Block createBlock(AbstractBlock parent, String context,
        Map<Object, Object> options) {
    IRubyObject rubyClass = rubyRuntime.evalScriptlet("Asciidoctor::Block");
    RubyHash convertMapToRubyHashWithSymbols = RubyHashUtil.convertMapToRubyHashWithSymbolsIfNecessary(rubyRuntime,
            options);
    // FIXME hack to ensure we have the underlying Ruby instance
    try {
        parent = parent.delegate();
    } catch (Exception e) {}

    Object[] parameters = {
            parent,
            RubyUtils.toSymbol(rubyRuntime, context),
            convertMapToRubyHashWithSymbols };
    return (Block) JavaEmbedUtils.invokeMethod(rubyRuntime, rubyClass,
            "new", parameters, Block.class);
}
 
开发者ID:asciidoctor,项目名称:asciidoctorj,代码行数:18,代码来源:Processor.java

示例8: toRubyObject

import org.jruby.javasupport.JavaEmbedUtils; //导入依赖的package包/类
private static IRubyObject toRubyObject(Ruby rubyRuntime, Object value) {

        if (value instanceof List) {
            return toRubyArray(rubyRuntime, (List<Object>) value);
        } else {

            if (isNotARubySymbol(value)) {
                String stringValue = ((String) value);

                if (stringValue.startsWith(":")) {
                    return RubyUtils.toSymbol(rubyRuntime, stringValue.substring(1));
                }
            }

            IRubyObject iRubyObject = JavaEmbedUtils.javaToRuby(rubyRuntime, value);
            return iRubyObject;
        }
    }
 
开发者ID:asciidoctor,项目名称:asciidoctorj,代码行数:19,代码来源:RubyHashUtil.java

示例9: getProperty

import org.jruby.javasupport.JavaEmbedUtils; //导入依赖的package包/类
@Override public String getProperty(String name) {
    Ruby runtime = o.getRuntime();
    o = marathon.callMethod(runtime.getCurrentContext(), "refresh_if_stale", o);
    marathon.callMethod(runtime.getCurrentContext(), "setContext", o);
    if ("tag_name".equals(name) || "tagName".equals(name)) {
        return o.callMethod(runtime.getCurrentContext(), "tag_name").toString().toUpperCase();
    }
    return o.callMethod(runtime.getCurrentContext(), "attribute", JavaEmbedUtils.javaToRuby(runtime, name)).toString();
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:10,代码来源:MarathonRuby.java

示例10: defineVariable

import org.jruby.javasupport.JavaEmbedUtils; //导入依赖的package包/类
private void defineVariable(String variable, Object value) {
    try {
        GlobalVariable v = new GlobalVariable(interpreter, "$" + variable, JavaEmbedUtils.javaToRuby(interpreter, value));
        interpreter.defineVariable(v, Scope.GLOBAL);
    } catch (Throwable t) {
        throw new ScriptException("Failed to define variable " + variable + " value = " + value + ":" + t.getMessage(), t);
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:9,代码来源:RubyScript.java

示例11: findAssertionProviderMethods

import org.jruby.javasupport.JavaEmbedUtils; //导入依赖的package包/类
private void findAssertionProviderMethods() {
    IRubyObject ro = interpreter.evalScriptlet("Object.private_instance_methods");
    String[] methods = (String[]) JavaEmbedUtils.rubyToJava(interpreter, ro, String[].class);
    assertionProviderList = new ArrayList<String>();
    for (Object method : methods) {
        if (method.toString().startsWith("marathon_assert_")) {
            assertionProviderList.add(method.toString());
        }
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:11,代码来源:RubyScript.java

示例12: convertToRuby

import org.jruby.javasupport.JavaEmbedUtils; //导入依赖的package包/类
private IRubyObject[] convertToRuby(Object[] javaArgs) {
	if (javaArgs == null || javaArgs.length == 0) {
		return new IRubyObject[0];
	}
	IRubyObject[] rubyArgs = new IRubyObject[javaArgs.length];
	for (int i = 0; i < javaArgs.length; ++i) {
		rubyArgs[i] = JavaEmbedUtils.javaToRuby(this.ruby, javaArgs[i]);
	}
	return rubyArgs;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:JRubyScriptUtils.java

示例13: convertFromRuby

import org.jruby.javasupport.JavaEmbedUtils; //导入依赖的package包/类
private Object convertFromRuby(IRubyObject rubyResult, Class<?> returnType) {
	Object result = JavaEmbedUtils.rubyToJava(this.ruby, rubyResult, returnType);
	if (result instanceof RubyArray && returnType.isArray()) {
		result = convertFromRubyArray(((RubyArray) result).toJavaArray(), returnType);
	}
	return result;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:JRubyScriptUtils.java

示例14: invokeMethod

import org.jruby.javasupport.JavaEmbedUtils; //导入依赖的package包/类
@Override
public Object invokeMethod(Object target, String name, Object... args) {
    try {
        IRubyObject rubyObject = JavaEmbedUtils.javaToRuby(container.getProvider().getRuntime(), target);
        return container.callMethod(rubyObject, name, args);
    } catch (Throwable e) {
        throw SpongeUtils.wrapException(target + "." + name, e);
    }
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:10,代码来源:JRubyKnowledgeBaseInterpreter.java

示例15: 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());
}
 
开发者ID:wu191287278,项目名称:sc-generator,代码行数:8,代码来源:DocumentController.java


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