Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Globbed jar contents with expand path failing in RubyGems #6060

Closed
headius opened this issue Feb 14, 2020 · 0 comments
Closed

Globbed jar contents with expand path failing in RubyGems #6060

headius opened this issue Feb 14, 2020 · 0 comments

Comments

@headius
Copy link
Member

@headius headius commented Feb 14, 2020

In #5996 we discovered that a RubyGems update seems to break our ability to use a jar file as a GEM_PATH.

The failures look like this:

TestJarredGemsWithSpacesInDirectory: 
  test_jarred_gem_on_gem_path:					E
================================================================================
org/jruby/RubyKernel.java:1187:in `catch'
org/jruby/RubyKernel.java:1192:in `catch'
org/jruby/RubyKernel.java:1187:in `catch'
org/jruby/RubyKernel.java:1192:in `catch'
     26:     Gem.clear_paths
     27:     old = ENV['GEM_PATH']
     28:     ENV['GEM_PATH'] = File.expand_path('../gem.jar', __FILE__)
  => 29:     assert require('mygem')
     30:   ensure
     31:     ENV['GEM_PATH'] = old
     32:     Gem.clear_paths
/home/travis/build/jruby/jruby/test/jruby/test_jarred_gems.rb:29:in `test_jarred_gem_on_gem_path'
/home/travis/build/jruby/jruby/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:54:in `require'
org/jruby/RubyKernel.java:977:in `require'
Error: test_jarred_gem_on_gem_path(TestJarredGemsWithSpacesInDirectory): LoadError: no such file to load -- mygem
================================================================================
: (0.018789)
  test_list_gem_from_jar_with_spaces_in_directory:		F
================================================================================
org/jruby/RubyKernel.java:1187:in `catch'
org/jruby/RubyKernel.java:1192:in `catch'
org/jruby/RubyKernel.java:1187:in `catch'
org/jruby/RubyKernel.java:1192:in `catch'
      6: 
      7:   def test_list_gem_from_jar_with_spaces_in_directory
      8:     out = jruby(%q{-r"./test/jruby/dir with spaces/testgem.jar" -S jgem list})
  =>  9:     assert(out =~ /testgem/)
     10: 
     11:     cp = ENV['CLASSPATH']
     12:     begin
/home/travis/build/jruby/jruby/test/jruby/test_jarred_gems.rb:9:in `test_list_gem_from_jar_with_spaces_in_directory'
Failure: test_list_gem_from_jar_with_spaces_in_directory(TestJarredGemsWithSpacesInDirectory): <nil> is not true.
================================================================================

These failures are due to a change in rubygems/rubygems@28c1f22 that modifies how gem paths are globbed to find gems and gemspecs.

The failure happens when doing one of two things and then trying to load a jarred gem:

  • Requiring a jar that contains a "GEM_PATH" style layout
  • Setting GEM_PATH to a jar that contains the appropriate layout

In each case, the "2.5" section in util.rb is the cause, and disabling that branch makes the jarred gem work correctly again.

A reduced script demonstrating the problem outside of RubyGems is here (using the test/jruby/gem.jar file in our repository:

glob = "*.gemspec"
base_path = "file:/Users/headius/projects/jruby/test/jruby/gem.jar!/specifications"

p Dir.glob(glob, base: base_path).map! {|f| File.expand_path(f, base_path) }
p Dir.glob(File.expand_path(glob, base_path))

The first glob is the one that fails, producing an empty array.

@headius headius added this to the JRuby 9.3.0.0 milestone Feb 14, 2020
headius added a commit to headius/jruby that referenced this issue Feb 14, 2020
headius added a commit to headius/jruby that referenced this issue Feb 19, 2020
Dir.glob was treating any passed-in `base` path as a normal file
path, which cause it to treat URIs as a relative path. The logic
then proceeded to prepend the cwd to this URI, producing a
nonsense path.

This patch uses File.expand_path logic to acquire the base path,
which keeps it a URI and allows the rest of glob to handle it
as if the glob and base were expanded before calling Dir.glob.

The change means that the two following Dir.glob calls work the
same, fixing the issues discovered in jruby#6060. It will very likely
also fix the issues reported in jruby#6082 and jruby#6083.

Fixes jruby#6060
Fixes jruby#6082
Fixes jruby#6083
headius added a commit to headius/jruby that referenced this issue Feb 19, 2020
This reverts commit e22bb98.
headius added a commit to headius/jruby that referenced this issue Feb 19, 2020
This relates to the changes in jruby#6060. We could think of no valid
reason for File.expand_path not to return strings encoded the
same as system file paths are encoded, but it's not clear if this
semantic change would cause any incompatibility.
@headius headius modified the milestones: JRuby 9.3.0.0, JRuby 9.2.11.0 Mar 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

1 participant
You can’t perform that action at this time.