Skip to content

Commit b5d1bc6

Browse files
committed
Drop old compatibility code for misbehaving webservers
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]>
1 parent caaa965 commit b5d1bc6

File tree

2 files changed

+0
-156
lines changed

2 files changed

+0
-156
lines changed

src/main/ruby/jruby/rack/booter.rb

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ def logger; JRuby::Rack.logger; end
9090

9191
# Boot-up this booter, preparing the environment for the application.
9292
def boot!
93-
adjust_load_path
9493
adjust_gem_path
9594
ENV['RACK_ENV'] = rack_env
9695
export_global_settings
@@ -171,63 +170,6 @@ def change_working_directory
171170
end
172171
end
173172

174-
# Adjust the load path (mostly due some J2EE servers slightly misbehaving).
175-
# @note called during {#boot!}
176-
def adjust_load_path
177-
require 'jruby'
178-
# http://kenai.com/jira/browse/JRUBY_RACK-8 If some containers do
179-
# not allow proper detection of jruby.home, fall back to this
180-
tmpdir = ENV_JAVA['java.io.tmpdir']
181-
if JRuby.runtime.instance_config.jruby_home == tmpdir
182-
ruby_paths = # mirroring org.jruby.runtime.load.LoadService#init
183-
if JRUBY_VERSION >= '1.7.0'
184-
# 2.0 is 1.9 as well and uses the same setup as 1.9 currently ...
185-
%w{ site_ruby shared } << ( JRuby.runtime.is1_9 ? '1.9' : '1.8' )
186-
else # <= JRuby 1.6.8
187-
if JRuby.runtime.is1_9
188-
%w{ site_ruby/1.9 site_ruby/shared site_ruby/1.8 1.9 }
189-
else
190-
%w{ site_ruby/1.8 site_ruby/shared 1.8 }
191-
end
192-
end
193-
# NOTE: most servers end up with 'classpath:/...' entries :
194-
# JRuby.home: "classpath:/META-INF/jruby.home"
195-
# $LOAD_PATH (JRuby 1.6.8 --1.9):
196-
#
197-
# "classpath:/META-INF/jruby.home/lib/ruby/site_ruby/1.9"
198-
# "classpath:/META-INF/jruby.home/lib/ruby/site_ruby/shared"
199-
# "classpath:/META-INF/jruby.home/lib/ruby/site_ruby/1.8"
200-
# "classpath:/META-INF/jruby.home/lib/ruby/1.9"
201-
#
202-
# $LOAD_PATH (JRuby 1.7.0):
203-
#
204-
# classpath:/META-INF/jruby.home/lib/ruby/site_ruby (missing dir)
205-
# classpath:/META-INF/jruby.home/lib/ruby/shared
206-
# classpath:/META-INF/jruby.home/lib/ruby/1.9
207-
#
208-
# seems to be the case for JBoss/Tomcat/WebLogic - it's best to
209-
# emulate the same setup for containers such as WebSphere where the
210-
# JRuby bootstrap fails to detect a correct home and points to /tmp
211-
#
212-
# since JRuby 1.6.7 LoadService has better support for 'classpath:'
213-
# prefixed entries https://github.com/jruby/jruby-rack/issues/89
214-
#
215-
# also since JRuby 1.7.0 there's a fix for incorrect home detection
216-
# (avoids /tmp on IBM WAS) https://github.com/jruby/jruby/pull/123
217-
#
218-
ruby_paths.each do |path|
219-
# NOTE: even better replace everything starting with '/tmp' ?
220-
if index = $LOAD_PATH.index("#{tmpdir}/lib/ruby/#{path}")
221-
$LOAD_PATH[index] = "classpath:/META-INF/jruby.home/lib/ruby/#{path}"
222-
else
223-
# e.g. "classpath:/META-INF/jruby.home/lib/ruby/1.8"
224-
full_path = "classpath:/META-INF/jruby.home/lib/ruby/#{path}"
225-
$LOAD_PATH << full_path unless $LOAD_PATH.include?(full_path)
226-
end
227-
end
228-
end
229-
end
230-
231173
# Checks for *META-INF/init.rb* and *WEB-INF/init.rb* code and evals it.
232174
# These init files are assumed to contain user supplied initialization code
233175
# to be loaded and executed during {#boot!}.

src/spec/ruby/jruby/rack/booter_spec.rb

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,6 @@
144144
ENV['GEM_PATH'].should == "/home/gems#{File::PATH_SEPARATOR}/usr/local/gems"
145145
end
146146

147-
# it "keeps ENV['GEM_PATH'] when gem_path is nil" do
148-
# ENV['GEM_PATH'] = '/usr/local/gems'
149-
# booter.layout = layout = double('layout')
150-
# layout.stub(:app_path).and_return '.'
151-
# layout.stub(:public_path).and_return nil
152-
# layout.should_receive(:gem_path).and_return nil
153-
# booter.boot!
154-
# ENV['GEM_PATH'].should == "/usr/local/gems"
155-
# end
156-
157147
it "sets ENV['GEM_PATH'] to the value of gem_path if ENV['GEM_PATH'] is not present" do
158148
@rack_context.should_receive(:getInitParameter).with("jruby.rack.env.gem_path").and_return 'true'
159149
ENV.delete('GEM_PATH')
@@ -238,94 +228,6 @@
238228
booter.boot! # expect to_not raise_error
239229
end
240230

241-
require 'jruby'
242-
243-
if JRUBY_VERSION >= '1.7.0'
244-
it "adjusts load path when runtime.jruby_home == /tmp" do
245-
tmpdir = java.lang.System.getProperty('java.io.tmpdir')
246-
jruby_home = JRuby.runtime.instance_config.getJRubyHome
247-
load_path = $LOAD_PATH.dup
248-
begin # emulating a "bare" load path :
249-
$LOAD_PATH.clear
250-
$LOAD_PATH << "#{tmpdir}/lib/ruby/site_ruby"
251-
$LOAD_PATH << "#{tmpdir}/lib/ruby/shared"
252-
$LOAD_PATH << (JRuby.runtime.is1_9 ? "#{tmpdir}/lib/ruby/1.9" : "#{tmpdir}/lib/ruby/1.8")
253-
$LOAD_PATH << "." if RUBY_VERSION.index('1.8')
254-
# "stub" runtime.jruby_home :
255-
JRuby.runtime.instance_config.setJRubyHome(tmpdir)
256-
257-
#booter.stub(:require)
258-
booter.boot!
259-
260-
expected = []
261-
if JRuby.runtime.is1_9
262-
expected << "classpath:/META-INF/jruby.home/lib/ruby/site_ruby"
263-
expected << "classpath:/META-INF/jruby.home/lib/ruby/shared"
264-
expected << "classpath:/META-INF/jruby.home/lib/ruby/1.9"
265-
else
266-
expected << "classpath:/META-INF/jruby.home/lib/ruby/site_ruby"
267-
expected << "classpath:/META-INF/jruby.home/lib/ruby/shared"
268-
expected << "classpath:/META-INF/jruby.home/lib/ruby/1.8"
269-
expected << "."
270-
end
271-
$LOAD_PATH.should == expected
272-
ensure # restore all runtime modifications :
273-
$LOAD_PATH.clear
274-
$LOAD_PATH.replace load_path
275-
JRuby.runtime.instance_config.setJRubyHome(jruby_home)
276-
end
277-
end
278-
else
279-
it "adjusts load path when runtime.jruby_home == /tmp" do
280-
tmpdir = java.lang.System.getProperty('java.io.tmpdir')
281-
jruby_home = JRuby.runtime.instance_config.getJRubyHome
282-
load_path = $LOAD_PATH.dup
283-
begin # emulating a "bare" load path :
284-
$LOAD_PATH.clear
285-
if JRuby.runtime.is1_9
286-
# a-realistic setup would be having those commented - but
287-
# to test the branched code there's artificial noise :
288-
$LOAD_PATH << "#{tmpdir}/lib/ruby/site_ruby/1.9"
289-
#$LOAD_PATH << "#{tmpdir}/lib/ruby/site_ruby/shared"
290-
$LOAD_PATH << "classpath:/META-INF/jruby.home/lib/ruby/site_ruby/shared"
291-
$LOAD_PATH << "#{tmpdir}/lib/ruby/site_ruby/1.8"
292-
#$LOAD_PATH << "#{tmpdir}/lib/ruby/1.9"
293-
else
294-
$LOAD_PATH << "#{tmpdir}/lib/ruby/site_ruby/1.8"
295-
#$LOAD_PATH << "#{tmpdir}/lib/ruby/site_ruby/shared"
296-
$LOAD_PATH << "classpath:/META-INF/jruby.home/lib/ruby/site_ruby/shared"
297-
#$LOAD_PATH << "#{tmpdir}/lib/ruby/1.8"
298-
end
299-
$LOAD_PATH << "."
300-
# "stub" runtime.jruby_home :
301-
JRuby.runtime.instance_config.setJRubyHome(tmpdir)
302-
303-
booter.boot!
304-
305-
expected = []
306-
if JRuby.runtime.is1_9
307-
expected << "classpath:/META-INF/jruby.home/lib/ruby/site_ruby/1.9"
308-
expected << "classpath:/META-INF/jruby.home/lib/ruby/site_ruby/shared"
309-
expected << "classpath:/META-INF/jruby.home/lib/ruby/site_ruby/1.8"
310-
#expected << "classpath:/META-INF/jruby.home/lib/ruby/1.9"
311-
expected << "."
312-
expected << "classpath:/META-INF/jruby.home/lib/ruby/1.9"
313-
else
314-
expected << "classpath:/META-INF/jruby.home/lib/ruby/site_ruby/1.8"
315-
expected << "classpath:/META-INF/jruby.home/lib/ruby/site_ruby/shared"
316-
#expected << "classpath:/META-INF/jruby.home/lib/ruby/1.8"
317-
expected << "."
318-
expected << "classpath:/META-INF/jruby.home/lib/ruby/1.8"
319-
end
320-
$LOAD_PATH.should == expected
321-
ensure # restore all runtime modifications :
322-
$LOAD_PATH.clear
323-
$LOAD_PATH.replace load_path
324-
JRuby.runtime.instance_config.setJRubyHome(jruby_home)
325-
end
326-
end
327-
end
328-
329231
context "within a runtime" do
330232

331233
describe "rack env" do

0 commit comments

Comments
 (0)