Skip to content

Commit

Permalink
putting the jruby-classloader as context classloader means that all a…
Browse files Browse the repository at this point in the history
…ttached "jars" can be found via

the Thread.currentThread.contextClassLoader. running jruby from other environments like servlets just
leave the context classloader as is. so this was a commandline only feature.

finally it keeps the classloader semantic uniform wether executed from commandline or inside a j2ee container
or osgi framework or embedded jruby in a java application
  • Loading branch information
mkristian committed Apr 29, 2015
1 parent e937702 commit ff10216
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 120 deletions.
14 changes: 0 additions & 14 deletions core/src/main/java/org/jruby/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,6 @@ public void run() {
}

try {
doSetContextClassLoader(runtime);

if (in == null) {
// no script to run, return success
return new Status();
Expand Down Expand Up @@ -454,18 +452,6 @@ private boolean checkStreamSyntax(Ruby runtime, InputStream in, String filename)
}
}

private void doSetContextClassLoader(Ruby runtime) {
// set thread context JRuby classloader here, for the main thread
try {
Thread.currentThread().setContextClassLoader(runtime.getJRubyClassLoader());
} catch (SecurityException se) {
// can't set TC classloader
if (runtime.getInstanceConfig().isVerbose()) {
config.getError().println("WARNING: Security restrictions disallowed setting context classloader for main thread.");
}
}
}

private void doProcessArguments(InputStream in) {
config.processArguments(config.parseShebangOptions(in));
}
Expand Down
100 changes: 0 additions & 100 deletions lib/ruby/shared/ffi/platform/ppc64le-linux/types.conf

This file was deleted.

6 changes: 4 additions & 2 deletions spec/java_integration/reify/become_java_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ def blah_with_args(arg_one,arg_two)
class JRUBY5564; end
a_class = JRUBY5564.become_java!(false)

# load the java class from the classloader
cl = java.lang.Thread.current_thread.getContextClassLoader
# load the java class from the jruby-classloader
# this diverts from the original issue 5564 since
# JRuby can run without any context_class_loader involved
cl = JRuby.runtime.jruby_class_loader
cl.load_class(a_class.get_name).should == a_class
end

Expand Down
5 changes: 1 addition & 4 deletions test/jruby/test_context_classloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ def setup
end

def test_main_thread
# This launches externally because our test run doesn't call through Main,
# so the executing thread's context classloader is not set to JRuby's.
assert_equal("true\n",
jruby('-rjava -rjruby -e "p(JRuby.runtime.jruby_class_loader == java.lang.Thread.current_thread.context_class_loader)"'))
assert_equal(JRuby.runtime.jruby_class_loader.parent, java.lang.Thread.current_thread.context_class_loader)
end

def test_ruby_thread
Expand Down

1 comment on commit ff10216

@kares
Copy link
Member

@kares kares commented on ff10216 Apr 29, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise +1 for uniformity ... finally!

Please sign in to comment.