Ejemplo n.º 1
0
  private static void assertGemListEquals(
      final OSGiIsolatedScriptingContainer jruby, final String... expected) {
    String list = (String) jruby.runScriptlet("Gem.loaded_specs.keys.sort.join(', ')");

    Arrays.sort(expected);

    if (gemJOpenSSLPreRelease(jruby)) {
      ArrayList<String> tmp = new ArrayList<String>(Arrays.asList(expected));
      tmp.remove("jruby-openssl"); // pre-release gem not reported in loaded_keys

      for (String name : tmp.toArray(new String[0])) {
        assertThat(list, containsString(name));
      }
    } else {
      assertEquals(Arrays.toString(expected), '[' + list + ']');
    }
  }
Ejemplo n.º 2
0
  @Test
  public void testJRubyCreate() throws Exception {

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

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

    OSGiIsolatedScriptingContainer jruby = new OSGiIsolatedScriptingContainer();
    jruby.addBundleToLoadPath("org.jruby.osgi.scripts-bundle");
    jruby.addBundleToGemPath(FrameworkUtil.getBundle(Gems.class));

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

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

    String gemPath = (String) jruby.runScriptlet("Gem::Specification.dirs.inspect");
    gemPath = gemPath.replaceAll("bundle[^:]*://[^/]*", "bundle:/");
    assertEquals("[\"uri:bundle://specifications\"]", gemPath);

    // 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("[\"rake\"]", list);

    // ensure we have native working
    loaded = (Boolean) jruby.runScriptlet("JRuby.runtime.posix.is_native");
    assertEquals(true, loaded);

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

    jruby.runScriptlet("require 'jar-dependencies'");

    assertGemListEquals(jruby, "jar-dependencies", "jruby-openssl", "rake");

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

    assertGemListEquals(
        jruby,
        "axiom-types",
        "coercible",
        "descendants_tracker",
        "equalizer",
        "ice_nine",
        "jar-dependencies",
        "jruby-openssl",
        "rake",
        "thread_safe",
        "virtus");
  }
Ejemplo n.º 3
0
 private static boolean gemJOpenSSLPreRelease(final OSGiIsolatedScriptingContainer jruby) {
   String josslVersion =
       (String) jruby.runScriptlet("require 'jopenssl/version'; Jopenssl::Version::VERSION");
   return josslVersion.matches(".*?[a-zA-Z]");
 }