diff --git a/src/main/ruby/jruby/rack/booter.rb b/src/main/ruby/jruby/rack/booter.rb index c7e0411f..92da6881 100644 --- a/src/main/ruby/jruby/rack/booter.rb +++ b/src/main/ruby/jruby/rack/booter.rb @@ -105,27 +105,21 @@ def boot! def adjust_gem_path gem_path = self.gem_path - case gem_path? - when false then # org.jruby.rack.RackLogger::DEBUG - if gem_path && ! gem_path.empty? && - ( ! defined?(Gem.path) || ! Gem.path.include?(gem_path) ) - @rack_context.log("Gem.path won't be updated although seems configured: #{gem_path}") - end - return false + case set_gem_path = env_gem_path when true then - if env_gem_path = ENV['GEM_PATH'] + if env_path = ENV['GEM_PATH'] if gem_path.nil? || gem_path.empty? return # keep ENV['GEM_PATH'] as is - elsif env_gem_path != gem_path + elsif env_path != gem_path separator = File::PATH_SEPARATOR - unless env_gem_path.split(separator).include?(gem_path) - ENV['GEM_PATH'] = "#{gem_path}#{separator}#{env_gem_path}" + unless env_path.split(separator).include?(gem_path) + ENV['GEM_PATH'] = "#{gem_path}#{separator}#{env_path}" end end else ENV['GEM_PATH'] = gem_path end - else # nil (default) + when false then begin require 'rubygems' unless defined? Gem.path rescue LoadError @@ -133,20 +127,33 @@ def adjust_gem_path return if gem_path.nil? || gem_path.empty? Gem.path.unshift(gem_path) unless Gem.path.include?(gem_path) end + return false + when nil then # org.jruby.rack.RackLogger::DEBUG + if gem_path && ! gem_path.empty? && + ( ! defined?(Gem.path) || ! Gem.path.include?(gem_path) ) + @rack_context.log("Gem.path won't be updated although seems configured: #{gem_path}") + end + return nil + else # 'jruby.rack.env.gem_path' "forced" to an explicit value + ENV['GEM_PATH'] = set_gem_path end end # @return whether to update Gem.path and/or the environment GEM_PATH - # - true/'env' forces ENV['GEM_PATH'] to be updated - # - false disabled Gem.path mangling for good (leaves all as is) + # - true (default) forces ENV['GEM_PATH'] to be updated due compatibility + # Bundler 1.6 fails to revolve gems correctly when Gem.path is updated + # instead of the ENV['GEM_PATH'] environment variable + # - false disables ENV['GEM_PATH'] mangling for good (updates Gem.path) + # # - if not specified Gem.path will be updated based on setting - def gem_path? - return @_gem_path if defined? @_gem_path - gem_path = @rack_context.getInitParameter('jruby.rack.gem_path') - return @_gem_path = nil if gem_path.nil? - return @_gem_path = false if gem_path.empty? || gem_path == 'false' - @_gem_path = true # true / 'env' + def env_gem_path + gem_path = @rack_context.getInitParameter('jruby.rack.env.gem_path') + return true if gem_path.nil? || gem_path.to_s == 'true' + return false if gem_path.to_s == 'false' + return nil if gem_path.empty? # set to an empty disables mangling + gem_path end + private :env_gem_path # @note called during {#boot!} def export_global_settings diff --git a/src/spec/ruby/jruby/rack/booter_spec.rb b/src/spec/ruby/jruby/rack/booter_spec.rb index 3217dec2..919f5aaf 100644 --- a/src/spec/ruby/jruby/rack/booter_spec.rb +++ b/src/spec/ruby/jruby/rack/booter_spec.rb @@ -87,7 +87,8 @@ booter.rack_env.should == 'production' end - it "prepends gem_path to Gem.path" do + it "prepends gem_path to Gem.path (when configured to not mangle with ENV)" do + @rack_context.should_receive(:getInitParameter).with("jruby.rack.env.gem_path").and_return 'false' Gem.path.replace [ '/opt/gems' ] booter.gem_path = "wsjar:file:/opt/deploy/sample.war!/WEB-INF/gems" booter.boot! @@ -111,8 +112,8 @@ expect( Gem.path ).to eql [ '/opt/gems' ] end - it "prepends gem_path to ENV['GEM_PATH'] if jruby.rack.gem_path set to env" do - @rack_context.should_receive(:getInitParameter).with("jruby.rack.gem_path").and_return "env" + it "prepends gem_path to ENV['GEM_PATH'] if jruby.rack.gem_path set to true" do + @rack_context.should_receive(:getInitParameter).with("jruby.rack.env.gem_path").and_return 'true' ENV['GEM_PATH'] = '/opt/gems' @rack_context.should_receive(:getRealPath).with("/WEB-INF").and_return "/opt/deploy/sample.war!/WEB-INF" @rack_context.should_receive(:getRealPath).with("/WEB-INF/gems").and_return "/opt/deploy/sample.war!/WEB-INF/gems" @@ -123,6 +124,7 @@ end it "does not prepend gem_path to ENV['GEM_PATH'] if jruby.rack.gem_path set not set" do + @rack_context.should_receive(:getInitParameter).with("jruby.rack.env.gem_path").and_return '' ENV['GEM_PATH'] = '/opt/gems' @rack_context.should_receive(:getRealPath).with("/WEB-INF").and_return "/opt/deploy/sample.war!/WEB-INF" @rack_context.should_receive(:getRealPath).with("/WEB-INF/gems").and_return "/opt/deploy/sample.war!/WEB-INF/gems" @@ -133,7 +135,6 @@ end it "prepends gem_path to ENV['GEM_PATH'] if not already present" do - @rack_context.should_receive(:getInitParameter).with("jruby.rack.gem_path").and_return "env" ENV['GEM_PATH'] = "/home/gems#{File::PATH_SEPARATOR}/usr/local/gems" booter.gem_path = '/usr/local/gems' booter.boot! @@ -152,7 +153,7 @@ # 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.gem_path").and_return 'true' + @rack_context.should_receive(:getInitParameter).with("jruby.rack.env.gem_path").and_return 'true' ENV.delete('GEM_PATH') @rack_context.should_receive(:getRealPath).with("/WEB-INF").and_return "/blah" @rack_context.should_receive(:getRealPath).with("/WEB-INF/gems").and_return "/blah/gems"