Skip to content

Commit d3ee8f0

Browse files
committed
better to keep ENV['GEM_PATH'] updates by default - keeps Bundler is more happy ...
seems current Bundler (1.6) does not pick up `Gem.path` directly from rubygems - re-invented **jruby.rack.env.gem_path** param instead of **jruby.rack.gem_path**
1 parent f5ce32b commit d3ee8f0

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

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

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -105,48 +105,55 @@ def boot!
105105

106106
def adjust_gem_path
107107
gem_path = self.gem_path
108-
case gem_path?
109-
when false then # org.jruby.rack.RackLogger::DEBUG
110-
if gem_path && ! gem_path.empty? &&
111-
( ! defined?(Gem.path) || ! Gem.path.include?(gem_path) )
112-
@rack_context.log("Gem.path won't be updated although seems configured: #{gem_path}")
113-
end
114-
return false
108+
case set_gem_path = env_gem_path
115109
when true then
116-
if env_gem_path = ENV['GEM_PATH']
110+
if env_path = ENV['GEM_PATH']
117111
if gem_path.nil? || gem_path.empty?
118112
return # keep ENV['GEM_PATH'] as is
119-
elsif env_gem_path != gem_path
113+
elsif env_path != gem_path
120114
separator = File::PATH_SEPARATOR
121-
unless env_gem_path.split(separator).include?(gem_path)
122-
ENV['GEM_PATH'] = "#{gem_path}#{separator}#{env_gem_path}"
115+
unless env_path.split(separator).include?(gem_path)
116+
ENV['GEM_PATH'] = "#{gem_path}#{separator}#{env_path}"
123117
end
124118
end
125119
else
126120
ENV['GEM_PATH'] = gem_path
127121
end
128-
else # nil (default)
122+
when false then
129123
begin
130124
require 'rubygems' unless defined? Gem.path
131125
rescue LoadError
132126
else
133127
return if gem_path.nil? || gem_path.empty?
134128
Gem.path.unshift(gem_path) unless Gem.path.include?(gem_path)
135129
end
130+
return false
131+
when nil then # org.jruby.rack.RackLogger::DEBUG
132+
if gem_path && ! gem_path.empty? &&
133+
( ! defined?(Gem.path) || ! Gem.path.include?(gem_path) )
134+
@rack_context.log("Gem.path won't be updated although seems configured: #{gem_path}")
135+
end
136+
return nil
137+
else # 'jruby.rack.env.gem_path' "forced" to an explicit value
138+
ENV['GEM_PATH'] = set_gem_path
136139
end
137140
end
138141

139142
# @return whether to update Gem.path and/or the environment GEM_PATH
140-
# - true/'env' forces ENV['GEM_PATH'] to be updated
141-
# - false disabled Gem.path mangling for good (leaves all as is)
143+
# - true (default) forces ENV['GEM_PATH'] to be updated due compatibility
144+
# Bundler 1.6 fails to revolve gems correctly when Gem.path is updated
145+
# instead of the ENV['GEM_PATH'] environment variable
146+
# - false disables ENV['GEM_PATH'] mangling for good (updates Gem.path)
147+
#
142148
# - if not specified Gem.path will be updated based on setting
143-
def gem_path?
144-
return @_gem_path if defined? @_gem_path
145-
gem_path = @rack_context.getInitParameter('jruby.rack.gem_path')
146-
return @_gem_path = nil if gem_path.nil?
147-
return @_gem_path = false if gem_path.empty? || gem_path == 'false'
148-
@_gem_path = true # true / 'env'
149+
def env_gem_path
150+
gem_path = @rack_context.getInitParameter('jruby.rack.env.gem_path')
151+
return true if gem_path.nil? || gem_path.to_s == 'true'
152+
return false if gem_path.to_s == 'false'
153+
return nil if gem_path.empty? # set to an empty disables mangling
154+
gem_path
149155
end
156+
private :env_gem_path
150157

151158
# @note called during {#boot!}
152159
def export_global_settings

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@
8787
booter.rack_env.should == 'production'
8888
end
8989

90-
it "prepends gem_path to Gem.path" do
90+
it "prepends gem_path to Gem.path (when configured to not mangle with ENV)" do
91+
@rack_context.should_receive(:getInitParameter).with("jruby.rack.env.gem_path").and_return 'false'
9192
Gem.path.replace [ '/opt/gems' ]
9293
booter.gem_path = "wsjar:file:/opt/deploy/sample.war!/WEB-INF/gems"
9394
booter.boot!
@@ -111,8 +112,8 @@
111112
expect( Gem.path ).to eql [ '/opt/gems' ]
112113
end
113114

114-
it "prepends gem_path to ENV['GEM_PATH'] if jruby.rack.gem_path set to env" do
115-
@rack_context.should_receive(:getInitParameter).with("jruby.rack.gem_path").and_return "env"
115+
it "prepends gem_path to ENV['GEM_PATH'] if jruby.rack.gem_path set to true" do
116+
@rack_context.should_receive(:getInitParameter).with("jruby.rack.env.gem_path").and_return 'true'
116117
ENV['GEM_PATH'] = '/opt/gems'
117118
@rack_context.should_receive(:getRealPath).with("/WEB-INF").and_return "/opt/deploy/sample.war!/WEB-INF"
118119
@rack_context.should_receive(:getRealPath).with("/WEB-INF/gems").and_return "/opt/deploy/sample.war!/WEB-INF/gems"
@@ -123,6 +124,7 @@
123124
end
124125

125126
it "does not prepend gem_path to ENV['GEM_PATH'] if jruby.rack.gem_path set not set" do
127+
@rack_context.should_receive(:getInitParameter).with("jruby.rack.env.gem_path").and_return ''
126128
ENV['GEM_PATH'] = '/opt/gems'
127129
@rack_context.should_receive(:getRealPath).with("/WEB-INF").and_return "/opt/deploy/sample.war!/WEB-INF"
128130
@rack_context.should_receive(:getRealPath).with("/WEB-INF/gems").and_return "/opt/deploy/sample.war!/WEB-INF/gems"
@@ -133,7 +135,6 @@
133135
end
134136

135137
it "prepends gem_path to ENV['GEM_PATH'] if not already present" do
136-
@rack_context.should_receive(:getInitParameter).with("jruby.rack.gem_path").and_return "env"
137138
ENV['GEM_PATH'] = "/home/gems#{File::PATH_SEPARATOR}/usr/local/gems"
138139
booter.gem_path = '/usr/local/gems'
139140
booter.boot!
@@ -152,7 +153,7 @@
152153
# end
153154

154155
it "sets ENV['GEM_PATH'] to the value of gem_path if ENV['GEM_PATH'] is not present" do
155-
@rack_context.should_receive(:getInitParameter).with("jruby.rack.gem_path").and_return 'true'
156+
@rack_context.should_receive(:getInitParameter).with("jruby.rack.env.gem_path").and_return 'true'
156157
ENV.delete('GEM_PATH')
157158
@rack_context.should_receive(:getRealPath).with("/WEB-INF").and_return "/blah"
158159
@rack_context.should_receive(:getRealPath).with("/WEB-INF/gems").and_return "/blah/gems"

0 commit comments

Comments
 (0)