Package org.jruby.embed

Examples of org.jruby.embed.IsolatedScriptingContainer


        System.err.println();
        System.err.println();

        // System.setProperty( "jruby.debug.loadService", "true" );
        IsolatedScriptingContainer jruby = new IsolatedScriptingContainer();

        // run a script from LOAD_PATH
        String hello = (String) jruby.runScriptlet( "require 'hello'; Hello.say" );
        assertEquals( hello, "world" );

        System.err.println();
        System.err.println();

        // ensure we can load rake from the default gems
        boolean loaded = (Boolean) jruby.runScriptlet( "require 'rake'" );
        assertEquals(true, loaded);

        String list = (String) jruby.runScriptlet( "Gem.loaded_specs.keys.inspect" );
        assertEquals(list, "[\"rake\"]");

        // ensure we can load openssl (with its bouncy-castle jars)
        loaded = (Boolean) jruby.runScriptlet( "require 'openssl'" );
        assertEquals(true, loaded);

        // ensure we can load ffi
        loaded = (Boolean) jruby.runScriptlet( "require 'ffi'" );
  // false is good enough, i.e. it is already loaded
        assertEquals(false, loaded);

        String gemPath = (String) jruby.runScriptlet( "Gem::Specification.dirs.inspect" );
        gemPath = gemPath.replaceAll( "bundle[^:]*://[^/]*", "bundle:/" );
        assertEquals( gemPath, "[\"uri:bundle://specifications\", \"uri:bundle://META-INF/jruby.home/lib/ruby/gems/shared/specifications\"]" );

  jruby.runScriptlet( "require 'jar-dependencies'; require 'krypt'" );
        list = (String) jruby.runScriptlet( "Gem.loaded_specs.keys.inspect" );
        assertEquals(list, "[\"rake\", \"jruby-openssl\", \"jar-dependencies\", \"ffi\", \"krypt-provider-jdk\", \"krypt-core\", \"krypt\"]");

        // ensure we can load can load embedded gems
        loaded = (Boolean) jruby.runScriptlet( "require 'virtus'" );
        assertEquals(true, loaded);

  list = (String) jruby.runScriptlet( "Gem.loaded_specs.keys.inspect" );
        assertEquals(list, "[\"rake\", \"jruby-openssl\", \"jar-dependencies\", \"ffi\", \"krypt-provider-jdk\", \"krypt-core\", \"krypt\", \"thread_safe\", \"descendants_tracker\", \"equalizer\", \"coercible\", \"ice_nine\", \"axiom-types\", \"virtus\"]");
    }
View Full Code Here


public class SimpleTest {

    @Test
    public void test() throws Exception {
        IsolatedScriptingContainer container = new IsolatedScriptingContainer();
  String output = (String) container.runScriptlet("require 'hello';Hello.new( :name => 'world' ).say");

        assertTrue( output, output.contains( "hello world" ) );
        assertTrue( output, output.contains( "zip file name: world" ) );
    }
View Full Code Here

        System.err.println();

  // System.setProperty( "jruby.debug.loadService", "true" );
  System.setProperty( "jruby.native.verbose", "true" );

  IsolatedScriptingContainer jruby = new IsolatedScriptingContainer();
  jruby.addLoadPath( Scripts.class.getClassLoader() );
  jruby.addGemPath( Gems.class.getClassLoader() );
 
        // run a script from LOAD_PATH
        String hello = (String) jruby.runScriptlet( "require 'hello'; Hello.say" );
        assertEquals( hello, "world" );

        System.err.println();
        System.err.println();

        String gemPath = (String) jruby.runScriptlet( "Gem::Specification.dirs.inspect" );
        gemPath = gemPath.replaceAll( "bundle[^:]*://[^/]*", "bundle:/" );
        assertEquals( gemPath, "[\"uri:bundle://specifications\", \"uri:bundle://specifications\", \"uri:bundle://META-INF/jruby.home/lib/ruby/gems/shared/specifications\"]" );

        // ensure we can load rake from the default gems
        boolean loaded = (Boolean) jruby.runScriptlet( "require 'rake'" );
        assertEquals(true, loaded);

        String list = (String) jruby.runScriptlet( "Gem.loaded_specs.keys.inspect" );
        assertEquals(list, "[\"rake\"]");

        // ensure we can load ffi
        loaded = (Boolean) jruby.runScriptlet( "require 'ffi'" );
        //assertEquals(true, loaded);
        list = (String) jruby.runScriptlet( "Gem.loaded_specs.keys.inspect" );
        assertEquals(list, "[\"rake\"]");

        // ensure we can load openssl (with its bouncy-castle jars)
        loaded = (Boolean) jruby.runScriptlet( "require 'openssl'" );
        assertEquals(true, loaded);

  jruby.runScriptlet( "require 'jar-dependencies'; require 'krypt'" );
        list = (String) jruby.runScriptlet( "Gem.loaded_specs.keys.inspect" );
        assertEquals(list, "[\"rake\", \"jruby-openssl\", \"jar-dependencies\", \"ffi\", \"krypt-provider-jdk\", \"krypt-core\", \"krypt\"]");

        // ensure we can load can load embedded gems
        loaded = (Boolean) jruby.runScriptlet( "require 'virtus'" );
        assertEquals(true, loaded);

  list = (String) jruby.runScriptlet( "Gem.loaded_specs.keys.inspect" );
        assertEquals(list, "[\"rake\", \"jruby-openssl\", \"jar-dependencies\", \"ffi\", \"krypt-provider-jdk\", \"krypt-core\", \"krypt\", \"thread_safe\", \"descendants_tracker\", \"equalizer\", \"coercible\", \"ice_nine\", \"axiom-types\", \"virtus\"]");
    }
View Full Code Here

TOP

Related Classes of org.jruby.embed.IsolatedScriptingContainer

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.