Skip to content

Commit

Permalink
make IsolatedScriptingContainer work on felix-4.2.1 and probably on o…
Browse files Browse the repository at this point in the history
…ther osgi frameworks outside the pax test cases
  • Loading branch information
mkristian committed Oct 20, 2014
1 parent 692bf65 commit 9d71d19
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jruby.embed;

import java.net.URL;
import java.util.Arrays;

/**
* the IsolatedScriptingContainer detects the whether it is used with
Expand Down Expand Up @@ -66,14 +67,14 @@ public IsolatedScriptingContainer( LocalContextScope scope,
if (cl == null) cl = Thread.currentThread().getContextClassLoader();
setClassLoader( cl );

setLoadPaths( Arrays.asList( "uri:classloader:" ) );

// set the right jruby home
setHomeDirectory( "uri:classloader:" + JRUBY_HOME );

// clean up LOAD_PATH
runScriptlet( "$LOAD_PATH.delete_if{|p| p =~ /jar$/ }" );

// setup the isolated GEM_PATH, i.e. without $HOME/.gem/**
runScriptlet("Gem::Specification.reset;"
runScriptlet("require 'rubygems/defaults/jruby';"
+ "Gem::Specification.reset;"
+ "Gem::Specification.add_dir 'uri:classloader:" + JRUBY_HOME + "/lib/ruby/gems/shared';"
+ "Gem::Specification.add_dir 'uri:classloader:';");
}
Expand Down Expand Up @@ -112,4 +113,4 @@ public void addGemPath( ClassLoader cl, String ref ) {
runScriptlet( "Gem::Specification.add_dir '" + uri + "' unless Gem::Specification.dirs.member?( '" + uri + "' )" );
}

}
}
15 changes: 10 additions & 5 deletions core/src/main/java/org/jruby/runtime/load/LoadService.java
Original file line number Diff line number Diff line change
Expand Up @@ -1003,12 +1003,17 @@ private Library findLibraryBySearchState(SearchState state) {
return state.library;
}

// TODO(ratnikov): Remove the special classpath case by introducing a classpath file resource
Library library = findLibraryWithClassloaders(state, state.searchFile, state.suffixType);
if (library != null) {
state.library = library;
// this test is needed to avoid an in org.jruby.runtime.load.LoadService.findFileInClasspath
// running inside felix-4.2.1 osgi framework
if (!loadPath.first().asJavaString().equals("uri:classloader:")) {
// TODO(ratnikov): Remove the special classpath case by introducing a classpath file resource
Library library = findLibraryWithClassloaders(state, state.searchFile, state.suffixType);
if (library != null) {
state.library = library;
}
return library;
}
return library;
return null;
}

@Deprecated
Expand Down

0 comments on commit 9d71d19

Please sign in to comment.