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


Java RubyInstanceConfig类代码示例

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


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

示例1: getInitRuby

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

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

示例3: initRuntimeConfig

import org.jruby.RubyInstanceConfig; //导入依赖的package包/类
protected RubyInstanceConfig initRuntimeConfig(final RubyInstanceConfig config) {
	final RackConfig rackConfig = rackServletContext.getConfig();
	config.setLoader(Thread.currentThread().getContextClassLoader());
	final Map<String, String> newEnv = rackConfig.getRuntimeEnvironment();
	if (newEnv != null) {
		config.setEnvironment(newEnv);
	}
	config.processArguments(rackConfig.getRuntimeArguments());
	if (rackConfig.getCompatVersion() != null) {
		config.setCompatVersion(rackConfig.getCompatVersion());
	}
	String home = getEnvVariable("JRUBY_HOME");
	logger.info("stokesdrift.env JRUBY_HOME=" + home);
	try {
		if (home != null) {
			config.setJRubyHome(home);
		}
	} catch (Exception e) {
		rackServletContext.log(RackLogger.DEBUG, "won't set-up jruby.home from jar", e);
	}
	return config;
}
 
开发者ID:stokesdrift,项目名称:stokesdrift,代码行数:23,代码来源:DriftRackApplicationFactory.java

示例4: createRuntime

import org.jruby.RubyInstanceConfig; //导入依赖的package包/类
protected Ruby createRuntime(String root) {
    Ruby runtime;
    if (Ruby.isGlobalRuntimeReady()) {
        runtime = Ruby.getGlobalRuntime();
    } else {
        RubyInstanceConfig instanceConfig = new RubyInstanceConfig();
        String jrubyHome = WunderBoss.options().get("jruby-home", "").toString();
        if (!jrubyHome.isEmpty()) {
            instanceConfig.setJRubyHome(jrubyHome);
        }
        String[] argv = (String[]) WunderBoss.options().get("argv", new String[]{});
        instanceConfig.setArgv(argv);
        instanceConfig.setLoader(this.getClass().getClassLoader());
        runtime = Ruby.newInstance(instanceConfig);
    }
    runtime.getLoadService().addPaths(root);
    return runtime;
}
 
开发者ID:projectodd,项目名称:wunderboss,代码行数:19,代码来源:RubyLanguage.java

示例5: createConfig

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

示例6: RubyConsole

import org.jruby.RubyInstanceConfig; //导入依赖的package包/类
public RubyConsole() {
    tar = new TextAreaReadline(this);

    runtime = Ruby.newInstance(new RubyInstanceConfig() {
        {
            setInput(tar.getInputStream());
            setOutput(new PrintStream(tar.getOutputStream()));
            setError(new PrintStream(tar.getOutputStream()));
            setObjectSpaceEnabled(true); // useful for code completion inside the IRB
        }
    });

    runtime.getGlobalVariables().defineReadonly("$$", new ValueAccessor(runtime.newFixnum(System.identityHashCode(runtime))));
    runtime.getLoadService().init(new ArrayList());

    tar.hookIntoRuntime(runtime);

    setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_RUBY);
    setAnimateBracketMatching(false);
    setAntiAliasingEnabled(true);
    setCodeFoldingEnabled(true);
}
 
开发者ID:IvyBits,项目名称:Amber-IDE,代码行数:23,代码来源:RubyConsole.java

示例7: createComponent

import org.jruby.RubyInstanceConfig; //导入依赖的package包/类
public JComponent createComponent() {
    JPanel panel = new JPanel();
    JPanel console = new JPanel();
    panel.setLayout(new BorderLayout());

    final JEditorPane text = new JTextPane();

    text.setMargin(new Insets(8, 8, 8, 8));
    text.setCaretColor(new Color(0xa4, 0x00, 0x00));
    text.setBackground(new Color(0xf2, 0xf2, 0xf2));
    text.setForeground(new Color(0xa4, 0x00, 0x00));
    Font font = findFont("Monospaced", Font.PLAIN, 14, new String[]{
            "Monaco", "Andale Mono"});

    text.setFont(font);
    JScrollPane pane = new JScrollPane();
    pane.setViewportView(text);
    pane.setBorder(BorderFactory.createLineBorder(Color.darkGray));
    panel.add(pane, BorderLayout.CENTER);
    console.validate();

    final TextAreaReadline tar = new TextAreaReadline(text,
            getString("Wellcom") + " \n\n");

    RubyInstanceConfig config = new RubyInstanceConfig() {
        {
            //setInput(tar.getInputStream());
            //setOutput(new PrintStream(tar.getOutputStream()));
            //setError(new PrintStream(tar.getOutputStream()));
            setObjectSpaceEnabled(false);
        }
    };
    Ruby runtime = Ruby.newInstance(config);
    tar.hookIntoRuntimeWithStreams(runtime);

    run(runtime);
    return panel;
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:39,代码来源:RubyConsole.java

示例8: asciidoctor

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

示例9: RSpecTestRunner

import org.jruby.RubyInstanceConfig; //导入依赖的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");
}
 
开发者ID:haplo-org,项目名称:haplo-safe-view-templates,代码行数:13,代码来源:RSpecTestRunner.java

示例10: JRubyAdapter

import org.jruby.RubyInstanceConfig; //导入依赖的package包/类
/**
 * Constructor.
 * 
 * @throws LanguageAdapterException
 *         In case of an initialization error
 */
public JRubyAdapter() throws LanguageAdapterException
{
	super( "JRuby", Constants.VERSION, "Ruby", Constants.RUBY_VERSION, Arrays.asList( "rb" ), "rb", Arrays.asList( "ruby", "rb", "jruby" ), "jruby" );

	RubyInstanceConfig config = new RubyInstanceConfig();
	config.setClassCache( getRubyClassCache() );
	config.setCompileMode( CompileMode.OFF );
	compilerRuntime = Ruby.newInstance( config );
}
 
开发者ID:tliron,项目名称:scripturian,代码行数:16,代码来源:JRubyAdapter.java

示例11: loadConfiguration

import org.jruby.RubyInstanceConfig; //导入依赖的package包/类
/**
 * Load the Haml viewer configuration for the view.
 *
 * @param configuration The configuration object
 */
public void loadConfiguration(Configuration configuration)
        throws ConfigurationException {

    List<String> loadPaths = new ArrayList<String>();
    // SINGLETHREAD is not threadsafe: http://www.ruby-forum.com/topic/206056#new
    container = new ScriptingContainer(LocalContextScope.THREADSAFE);
    scriptingContainerConfiguration = configuration;

    RubyInstanceConfig config = container.getProvider().getRubyInstanceConfig();

    if (scriptingContainerConfiguration != null) {

        jrubyhome = scriptingContainerConfiguration.getChildValue("jruby_home");

        if (jrubyhome != null) {
            config.setJRubyHome(jrubyhome);
            loadPaths.add(jrubyhome);
        }

        String userHamlScript = scriptingContainerConfiguration.getChildValue("haml");
        if (userHamlScript != null) {
            haml_rb = userHamlScript; //just a bit of inversion of control
        }
    }

    haml_rb_unit = container.parse(haml_rb);

    log.info("haml enabled ... have fun!");
}
 
开发者ID:florinpatrascu,项目名称:jpublish,代码行数:35,代码来源:HamlViewRenderer.java

示例12: LoadService

import org.jruby.RubyInstanceConfig; //导入依赖的package包/类
public LoadService(Ruby runtime) {
    this.runtime = runtime;
    if (RubyInstanceConfig.DEBUG_LOAD_TIMINGS) {
        loadTimer = new TracingLoadTimer();
    } else {
        loadTimer = new LoadTimer();
    }
}
 
开发者ID:rholder,项目名称:jfss,代码行数:9,代码来源:LoadService.java

示例13: debugLogFound

import org.jruby.RubyInstanceConfig; //导入依赖的package包/类
protected void debugLogFound( LoadServiceResource resource ) {
    if (RubyInstanceConfig.DEBUG_LOAD_SERVICE) {
        String resourceUrl;
        try {
            resourceUrl = resource.getURL().toString();
        } catch (IOException e) {
            resourceUrl = e.getMessage();
        }
        LOG.info( "found: " + resourceUrl );
    }
}
 
开发者ID:rholder,项目名称:jfss,代码行数:12,代码来源:LoadService.java

示例14: tryResourceFromLoadPath

import org.jruby.RubyInstanceConfig; //导入依赖的package包/类
protected LoadServiceResource tryResourceFromLoadPath( String namePlusSuffix,String loadPathEntry) throws RaiseException {
    LoadServiceResource foundResource = null;

    try {
        if (!Ruby.isSecurityRestricted()) {
            String reportedPath = loadPathEntry + "/" + namePlusSuffix;
            boolean absolute = true;
            // we check length == 0 for 'load', which does not use load path
            if (!new File(reportedPath).isAbsolute()) {
                absolute = false;
                // prepend ./ if . is not already there, since we're loading based on CWD
                if (reportedPath.charAt(0) != '.') {
                    reportedPath = "./" + reportedPath;
                }
                loadPathEntry = JRubyFile.create(runtime.getCurrentDirectory(), loadPathEntry).getAbsolutePath();
            }
            JRubyFile actualPath = JRubyFile.create(loadPathEntry, RubyFile.expandUserPath(runtime.getCurrentContext(), namePlusSuffix));
            if (RubyInstanceConfig.DEBUG_LOAD_SERVICE) {
                debugLogTry("resourceFromLoadPath", "'" + actualPath.toString() + "' " + actualPath.isFile() + " " + actualPath.canRead());
            }
            if (actualPath.canRead()) {
                foundResource = new LoadServiceResource(actualPath, reportedPath, absolute);
                debugLogFound(foundResource);
            }
        }
    } catch (SecurityException secEx) {
    }

    return foundResource;
}
 
开发者ID:rholder,项目名称:jfss,代码行数:31,代码来源:LoadService.java

示例15: testLoadPaths

import org.jruby.RubyInstanceConfig; //导入依赖的package包/类
@Test
public void testLoadPaths() throws Exception {		
	DriftRackApplicationFactory factory = new DriftRackApplicationFactory();
	ServletContext servletContext = PowerMockito.mock(ServletContext.class);
	ServletRackConfig config = new ServletRackConfig(servletContext);
	ServletRackContext context = new DefaultServletRackContext(config);

	// Shouldn't add since the gems direction doesn't exist
	URL configRuFile = this.getClass().getClassLoader().getResource("examples/config.ru");
	File file = new File(configRuFile.toURI());
	String jrubyHome = file.getParent();
	
	URI libUri = Ruby.class.getProtectionDomain().getCodeSource().getLocation().toURI();
	File libDirectory = new File(libUri);
	
	System.setProperty("STOKESDRIFT_LIB_DIR",libDirectory.getParent());
	System.setProperty("JRUBY_HOME",jrubyHome);
    System.setProperty("GEM_PATH","test/home/gem_path");
    
	factory.init(context);
	Ruby runtime = factory.newRuntime();
	Assert.assertNotNull(runtime);
			
	RubyInstanceConfig rackConfig = factory.getRuntimeConfig();
	List<String> loadPaths = rackConfig.getLoadPaths();
	Assert.assertTrue(loadPaths.size() > 0);
	Assert.assertTrue(loadPaths.contains("test/home/gem_path"));
	Assert.assertEquals(jrubyHome, rackConfig.getJRubyHome());
	
	
	configRuFile = this.getClass().getClassLoader().getResource("examples/test_paths.rb");
	byte[] scriptBytes = Files.readAllBytes(Paths.get(configRuFile.toURI()));
	IRubyObject rubyObject = runtime.executeScript(new String(scriptBytes), "test_paths.rb");
	Assert.assertEquals("horray",rubyObject.asString().toString());
	
}
 
开发者ID:stokesdrift,项目名称:stokesdrift,代码行数:37,代码来源:DriftRackApplicationFactoryTest.java


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