Skip to content

Commit

Permalink
Drop old compatibility code for misbehaving webservers
Browse files Browse the repository at this point in the history
The code and tests related to hacking load paths for old J2EE webservers which cannot detect
jruby.home correctly hasn't worked for a long time due to incorrect load path assumptions,
and the tests currently fail. Let's move forward and remove these old hacks.

Signed-off-by: Chad Wilson <[email protected]>
  • Loading branch information
chadlwilson committed Jun 28, 2024
1 parent 697ae98 commit 064b57c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 156 deletions.
58 changes: 0 additions & 58 deletions src/main/ruby/jruby/rack/booter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def logger; JRuby::Rack.logger; end

# Boot-up this booter, preparing the environment for the application.
def boot!
adjust_load_path
adjust_gem_path
ENV['RACK_ENV'] = rack_env
export_global_settings
Expand Down Expand Up @@ -171,63 +170,6 @@ def change_working_directory
end
end

# Adjust the load path (mostly due some J2EE servers slightly misbehaving).
# @note called during {#boot!}
def adjust_load_path
require 'jruby'
# http://kenai.com/jira/browse/JRUBY_RACK-8 If some containers do
# not allow proper detection of jruby.home, fall back to this
tmpdir = ENV_JAVA['java.io.tmpdir']
if JRuby.runtime.instance_config.jruby_home == tmpdir
ruby_paths = # mirroring org.jruby.runtime.load.LoadService#init
if JRUBY_VERSION >= '1.7.0'
# 2.0 is 1.9 as well and uses the same setup as 1.9 currently ...
%w{ site_ruby shared } << ( JRuby.runtime.is1_9 ? '1.9' : '1.8' )
else # <= JRuby 1.6.8
if JRuby.runtime.is1_9
%w{ site_ruby/1.9 site_ruby/shared site_ruby/1.8 1.9 }
else
%w{ site_ruby/1.8 site_ruby/shared 1.8 }
end
end
# NOTE: most servers end up with 'classpath:/...' entries :
# JRuby.home: "classpath:/META-INF/jruby.home"
# $LOAD_PATH (JRuby 1.6.8 --1.9):
#
# "classpath:/META-INF/jruby.home/lib/ruby/site_ruby/1.9"
# "classpath:/META-INF/jruby.home/lib/ruby/site_ruby/shared"
# "classpath:/META-INF/jruby.home/lib/ruby/site_ruby/1.8"
# "classpath:/META-INF/jruby.home/lib/ruby/1.9"
#
# $LOAD_PATH (JRuby 1.7.0):
#
# classpath:/META-INF/jruby.home/lib/ruby/site_ruby (missing dir)
# classpath:/META-INF/jruby.home/lib/ruby/shared
# classpath:/META-INF/jruby.home/lib/ruby/1.9
#
# seems to be the case for JBoss/Tomcat/WebLogic - it's best to
# emulate the same setup for containers such as WebSphere where the
# JRuby bootstrap fails to detect a correct home and points to /tmp
#
# since JRuby 1.6.7 LoadService has better support for 'classpath:'
# prefixed entries https://github.com/jruby/jruby-rack/issues/89
#
# also since JRuby 1.7.0 there's a fix for incorrect home detection
# (avoids /tmp on IBM WAS) https://github.com/jruby/jruby/pull/123
#
ruby_paths.each do |path|
# NOTE: even better replace everything starting with '/tmp' ?
if index = $LOAD_PATH.index("#{tmpdir}/lib/ruby/#{path}")
$LOAD_PATH[index] = "classpath:/META-INF/jruby.home/lib/ruby/#{path}"
else
# e.g. "classpath:/META-INF/jruby.home/lib/ruby/1.8"
full_path = "classpath:/META-INF/jruby.home/lib/ruby/#{path}"
$LOAD_PATH << full_path unless $LOAD_PATH.include?(full_path)
end
end
end
end

# Checks for *META-INF/init.rb* and *WEB-INF/init.rb* code and evals it.
# These init files are assumed to contain user supplied initialization code
# to be loaded and executed during {#boot!}.
Expand Down
98 changes: 0 additions & 98 deletions src/spec/ruby/jruby/rack/booter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,6 @@
ENV['GEM_PATH'].should == "/home/gems#{File::PATH_SEPARATOR}/usr/local/gems"
end

# it "keeps ENV['GEM_PATH'] when gem_path is nil" do
# ENV['GEM_PATH'] = '/usr/local/gems'
# booter.layout = layout = double('layout')
# layout.stub(:app_path).and_return '.'
# layout.stub(:public_path).and_return nil
# layout.should_receive(:gem_path).and_return nil
# booter.boot!
# ENV['GEM_PATH'].should == "/usr/local/gems"
# end

it "sets ENV['GEM_PATH'] to the value of gem_path if ENV['GEM_PATH'] is not present" do
@rack_context.should_receive(:getInitParameter).with("jruby.rack.env.gem_path").and_return 'true'
ENV.delete('GEM_PATH')
Expand Down Expand Up @@ -238,94 +228,6 @@
booter.boot! # expect to_not raise_error
end

require 'jruby'

if JRUBY_VERSION >= '1.7.0'
it "adjusts load path when runtime.jruby_home == /tmp" do
tmpdir = java.lang.System.getProperty('java.io.tmpdir')
jruby_home = JRuby.runtime.instance_config.getJRubyHome
load_path = $LOAD_PATH.dup
begin # emulating a "bare" load path :
$LOAD_PATH.clear
$LOAD_PATH << "#{tmpdir}/lib/ruby/site_ruby"
$LOAD_PATH << "#{tmpdir}/lib/ruby/shared"
$LOAD_PATH << (JRuby.runtime.is1_9 ? "#{tmpdir}/lib/ruby/1.9" : "#{tmpdir}/lib/ruby/1.8")
$LOAD_PATH << "." if RUBY_VERSION.index('1.8')
# "stub" runtime.jruby_home :
JRuby.runtime.instance_config.setJRubyHome(tmpdir)

#booter.stub(:require)
booter.boot!

expected = []
if JRuby.runtime.is1_9
expected << "classpath:/META-INF/jruby.home/lib/ruby/site_ruby"
expected << "classpath:/META-INF/jruby.home/lib/ruby/shared"
expected << "classpath:/META-INF/jruby.home/lib/ruby/1.9"
else
expected << "classpath:/META-INF/jruby.home/lib/ruby/site_ruby"
expected << "classpath:/META-INF/jruby.home/lib/ruby/shared"
expected << "classpath:/META-INF/jruby.home/lib/ruby/1.8"
expected << "."
end
$LOAD_PATH.should == expected
ensure # restore all runtime modifications :
$LOAD_PATH.clear
$LOAD_PATH.replace load_path
JRuby.runtime.instance_config.setJRubyHome(jruby_home)
end
end
else
it "adjusts load path when runtime.jruby_home == /tmp" do
tmpdir = java.lang.System.getProperty('java.io.tmpdir')
jruby_home = JRuby.runtime.instance_config.getJRubyHome
load_path = $LOAD_PATH.dup
begin # emulating a "bare" load path :
$LOAD_PATH.clear
if JRuby.runtime.is1_9
# a-realistic setup would be having those commented - but
# to test the branched code there's artificial noise :
$LOAD_PATH << "#{tmpdir}/lib/ruby/site_ruby/1.9"
#$LOAD_PATH << "#{tmpdir}/lib/ruby/site_ruby/shared"
$LOAD_PATH << "classpath:/META-INF/jruby.home/lib/ruby/site_ruby/shared"
$LOAD_PATH << "#{tmpdir}/lib/ruby/site_ruby/1.8"
#$LOAD_PATH << "#{tmpdir}/lib/ruby/1.9"
else
$LOAD_PATH << "#{tmpdir}/lib/ruby/site_ruby/1.8"
#$LOAD_PATH << "#{tmpdir}/lib/ruby/site_ruby/shared"
$LOAD_PATH << "classpath:/META-INF/jruby.home/lib/ruby/site_ruby/shared"
#$LOAD_PATH << "#{tmpdir}/lib/ruby/1.8"
end
$LOAD_PATH << "."
# "stub" runtime.jruby_home :
JRuby.runtime.instance_config.setJRubyHome(tmpdir)

booter.boot!

expected = []
if JRuby.runtime.is1_9
expected << "classpath:/META-INF/jruby.home/lib/ruby/site_ruby/1.9"
expected << "classpath:/META-INF/jruby.home/lib/ruby/site_ruby/shared"
expected << "classpath:/META-INF/jruby.home/lib/ruby/site_ruby/1.8"
#expected << "classpath:/META-INF/jruby.home/lib/ruby/1.9"
expected << "."
expected << "classpath:/META-INF/jruby.home/lib/ruby/1.9"
else
expected << "classpath:/META-INF/jruby.home/lib/ruby/site_ruby/1.8"
expected << "classpath:/META-INF/jruby.home/lib/ruby/site_ruby/shared"
#expected << "classpath:/META-INF/jruby.home/lib/ruby/1.8"
expected << "."
expected << "classpath:/META-INF/jruby.home/lib/ruby/1.8"
end
$LOAD_PATH.should == expected
ensure # restore all runtime modifications :
$LOAD_PATH.clear
$LOAD_PATH.replace load_path
JRuby.runtime.instance_config.setJRubyHome(jruby_home)
end
end
end

context "within a runtime" do

describe "rack env" do
Expand Down

0 comments on commit 064b57c

Please sign in to comment.