Package org.jruby.embed

Examples of org.jruby.embed.ScriptingContainer


        JubileeVerticleFactory.vertx = vertx;
        JubileeVerticleFactory.container = container;
        ClassLoader old = Thread.currentThread().getContextClassLoader();
        try {
            Thread.currentThread().setContextClassLoader(cl);
            this.scontainer = new ScriptingContainer(LocalContextScope.SINGLETHREAD);
            scontainer.setCompatVersion(CompatVersion.RUBY1_9);
            //Prevent JRuby from logging errors to stderr - we want to log ourselves
            scontainer.setErrorWriter(new NullWriter());
        } finally {
            Thread.currentThread().setContextClassLoader(old);
View Full Code Here


    private boolean initialized;
    private File configLocation;

    public void compile() {
        initialize();
        new ScriptingContainer().runScriptlet(buildCompileScript());
    }
View Full Code Here

        new ScriptingContainer().runScriptlet(buildCompileScript());
    }

    private void initialize() {
        if (!initialized) {
            new ScriptingContainer().runScriptlet(buildInitializationScript());
            initialized = true;
        }
    }
View Full Code Here

        // TODO: move to a better location in the code?  remove?
        if (config.getJrubyHome() != null) {
            System.setProperty("jruby.home", config.getJrubyHome());
        }
       
        final ScriptingContainer container = new ScriptingContainer(config.getScope());
       
        container.setCompileMode(config.getCompileMode());
        if (config.getJrubyHome() != null) {
            container.setHomeDirectory(config.getJrubyHome());
        }
        container.setCompatVersion(config.getCompatVersion());
        container.setCurrentDirectory(config.getAppRoot());
        // don't propagate ENV to global JVM level
        container.getProvider().getRubyInstanceConfig().setUpdateNativeENVEnabled(false);
       
        logger.info("new ScriptingContainer scope={} compileMode={} jrubyHome={} compatVersion={}, pwd={}",
                    new Object[] {
                        config.getScope(),
                        config.getCompileMode(),
View Full Code Here

        if (!file.exists()) {
            throw new InvalidPluginException(new FileNotFoundException(String.format("%s does not exist", file.getPath())));
        }

        // create a scripting container for every plugin to encapsulate it
        ScriptingContainer runtime = setupScriptingContainer(file);
        try {
            // run init script
            runResourceScript(runtime, initScript);

            final EmbedEvalUnit eval = runtime.parse(PathType.RELATIVE, file.getPath());
            /*IRubyObject res =*/ eval.run();

            // create plugin description
            final PluginDescriptionFile description = getDescriptionFile(runtime);
            if (description == null)
View Full Code Here

    /**
     * create and setup ScriptingContainer
     */
    private ScriptingContainer setupScriptingContainer(File file) {
        ScriptingContainer runtime = new ScriptingContainer(LocalContextScope.SINGLETHREAD);

        runtime.setCompileMode(CompileMode.JIT);

        runtime.setClassLoader(RubyPluginLoader.class.getClassLoader());

        // Setup load paths, the "file:" thing is for internal stuff like rubygems
        String[] loadPaths = new String[] {
            file.getAbsoluteFile().getParent(),
            RubyBukkit.thisJar.getAbsolutePath(),
            "file:" + RubyBukkit.jrubyJar.getAbsoluteFile() + "!/META_INF/jruby.home/lib/ruby/site_ruby/" + RubyBukkit.rubyVersion,
            "file:" + RubyBukkit.jrubyJar.getAbsoluteFile() + "!/META_INF/jruby.home/lib/ruby/site_ruby/shared",
            "file:" + RubyBukkit.jrubyJar.getAbsoluteFile() + "!/META_INF/jruby.home/lib/ruby/" + RubyBukkit.rubyVersion,
        };
        runtime.setLoadPaths(Arrays.asList(loadPaths));

        if (RubyBukkit.rubyVersion.equals("1.9"))
            runtime.setCompatVersion(CompatVersion.RUBY1_9);

        return runtime;
    }
View Full Code Here

        Validate.notNull(file, "File cannot be null");
        if (!file.exists()) {
            throw new InvalidDescriptionException(new FileNotFoundException(String.format("%s does not exist", file.getPath())));
        }

        ScriptingContainer runtime = setupScriptingContainer(file);
        try {
            // run init script
            runResourceScript(runtime, initScript);

            final EmbedEvalUnit eval = runtime.parse(PathType.RELATIVE, file.getPath());
            /*IRubyObject res =*/ eval.run();

            return getDescriptionFile(runtime);

        } catch (IOException e) {
View Full Code Here

import org.jruby.embed.ScriptingContainer;

public class JavaSassMain {

    public static void main(String[] args) {
        ScriptingContainer container = new ScriptingContainer();
        container.runScriptlet("require 'rubygems'; require 'sass';");

        String sass = ".test\n\tcolor: red";
        container.put("str", sass);

        String css = (String)container.runScriptlet("Sass::Engine.new(str).render");

        System.out.println(css);
    }
View Full Code Here

public class JavaSassTest {

    @Test
    public void testJavaSass() throws Exception {
        ScriptingContainer container = new ScriptingContainer();
        container.runScriptlet("require 'rubygems'; require 'sass';");

        String sass = ".test\n\tcolor: red";
        container.put("str", sass);
       
        String css = (String)container.runScriptlet("Sass::Engine.new(str).render");

        assertEquals(".test {\n  color: red; }\n", css);
    }
View Full Code Here

import static org.junit.Assert.assertEquals;

public class GemsIT {
    @Test
    public void correctSassIsPackaged() {
        assertEquals("3.4.4", new ScriptingContainer().runScriptlet("require 'sass';Sass.version[:number]"));
    }
View Full Code Here

TOP

Related Classes of org.jruby.embed.ScriptingContainer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.