JRuby

Compiled Ruby classes cannot resolve their location inside a Jar file

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: JRuby 1.1.4
  • Fix Version/s: JRuby 1.1.5
  • Component/s: Compiler
  • Labels:
    None
  • Testcase included:
    yes
  • Number of attachments :
    0

Description

Here's the breakdown:
Compiled and uncompiled Ruby classes from the command line work fine
Compiled and uncompiled Ruby classes in the root of a jar do not properly resolve File.expand_path(File.dirname(_FILE_))
Compiled Ruby classes in a sub-directory of a jar do not properly resolve File.expand_path(File.dirname(_FILE_))
Uncompiled Ruby classes in a sub-directory of a jar DO properly resolve File.expand_path(File.dirname(_FILE_))

#=== file_test.rb ===

puts "__FILE__: #{__FILE__}"
puts "File.dirname(__FILE__): #{File.dirname(__FILE__)}"
puts "File.expand_path(File.dirname(__FILE__)): #{File.expand_path(File.dirname(__FILE__))}"

#=== bootstrap1.rb === (used to test uncompiled Ruby files in a jar)
require 'file_test'

#=== bootstrap2.rb === (used to test uncompiled Ruby files in a jar)
require 'src/file_test'

# GIVES CORRECT OUTPUT
#=== Running the file_test.rb file unmodified using MRI and JRuby ===
ruby file_test.rb 
__FILE__: file_test.rb
File.dirname(__FILE__): .
File.expand_path(File.dirname(__FILE__)): /Users/david/dev/projects/general/jruby_test

jruby file_test.rb 
__FILE__: file_test.rb
File.dirname(__FILE__): .
File.expand_path(File.dirname(__FILE__)): /Users/david/dev/projects/general/jruby_test

# GIVES CORRECT OUTPUT
# === Compile the file_test.rb file (jrubyc file_test.rb) ===
java -cp ~/dev/libs/jruby/lib/jruby.jar:. file_test
__FILE__: file_test.rb
File.dirname(__FILE__): .
File.expand_path(File.dirname(__FILE__)): /Users/david/dev/projects/general/jruby_test

# GIVES INCORRECT OUTPUT
# === Jarring the file_test.rb (jar -cvf file_test.jar file_test.rb bootstrap1.class) and placing jar file in /jar sub-directory ===
# Adding in compiled bootstrap1 class so java has something to launch
java -cp ~/dev/libs/jruby/lib/jruby-complete.jar:file_test.jar bootstrap1 #<-- no output, internally an exception?

# GIVES INCORRECT OUTPUT
# === Jarring the file_test.class (jar -cvf file_test.jar file_test.class) (also placing in /jar sub-directory) ===
# Moved file_test.jar into /jar subdirectory to prevent accidentally pulling in .class file
java -cp ~/dev/libs/jruby/lib/jruby-complete.jar:file_test.jar file_test
__FILE__: file_test.rb
File.dirname(__FILE__): .
File.expand_path(File.dirname(__FILE__)): /Users/david/dev/projects/general/jruby_test/jar #<-- should have /file_test.jar! on the end

GIVES CORRECT OUTPUT
# === Uncompiled Ruby file in /src directory in jar file ===
# Use bootstrap2 file to require file in 'src/test_file'
java -cp ~/dev/libs/jruby/lib/jruby-complete.jar:file_test.jar bootstrap2
__FILE__: file:/Users/david/dev/projects/general/jruby_test/jar/file_test.jar!/src/file_test.rb
File.dirname(__FILE__): file:/Users/david/dev/projects/general/jruby_test/jar/file_test.jar!/src
File.expand_path(File.dirname(__FILE__)): file:/Users/david/dev/projects/general/jruby_test/jar/file_test.jar!/src #<-- We get the jar file and the sub-dir, yay!

GIVES INCORRECT OUTPUT
# === Compiled Ruby file in /src directory in jar file ===
# As above but with compiled Ruby file, same bootstrap2 file
java -cp ~/dev/libs/jruby/lib/jruby-complete.jar:file_test.jar bootstrap2
__FILE__: file_test.rb
File.dirname(__FILE__): .
File.expand_path(File.dirname(__FILE__)): /Users/david/dev/projects/general/jruby_test/jar #<-- missing /file_test.jar!/src

Issue Links

Activity

Hide
David Koontz added a comment -

Um, sorry about the formatting there, I'm not sure where the 1. 2. etc came from, those were unintended. Also, I don't know why the one line has strikethrough.

Show
David Koontz added a comment - Um, sorry about the formatting there, I'm not sure where the 1. 2. etc came from, those were unintended. Also, I don't know why the one line has strikethrough.
Hide
Charles Oliver Nutter added a comment -

This bug needs parser/AST changes to go forward; because in the AST there's nothing to distinguish a _FILE_ node, there's no way to make it more dynamic for compiled code. Also, since the _FILE_ line gets converted into a StrNode by the parser, that's probably the place to start hunting for issues when loading a .rb file out of a jar. So I think this is probably easier for Tom to look into. Assigning to Tom.

Show
Charles Oliver Nutter added a comment - This bug needs parser/AST changes to go forward; because in the AST there's nothing to distinguish a _FILE_ node, there's no way to make it more dynamic for compiled code. Also, since the _FILE_ line gets converted into a StrNode by the parser, that's probably the place to start hunting for issues when loading a .rb file out of a jar. So I think this is probably easier for Tom to look into. Assigning to Tom.
Hide
Charles Oliver Nutter added a comment -

I committed a change that at least gets _FILE_ working from within a .class file, but I believe there's still work to be done to get jar URLs into the filename as well. A normal test/unit testcase for this would probably make it go quicker, otherwise I'll have to come up with that myself too based on the cases provided in the description.

Show
Charles Oliver Nutter added a comment - I committed a change that at least gets _FILE_ working from within a .class file, but I believe there's still work to be done to get jar URLs into the filename as well. A normal test/unit testcase for this would probably make it go quicker, otherwise I'll have to come up with that myself too based on the cases provided in the description.
Hide
Charles Oliver Nutter added a comment -

Actually I just managed to test loading a class from a .jar file and the URL appears to be there and working. So now I really need those test cases for the expectations in this bug:

foo.rb just has "puts _FILE_", and is compiled into foo.class and jarred into foo.jar

~/projects/jruby &#10132; jruby -d -rfoo.jar -e "require 'foo.rb'"
file:/Users/headius/projects/jruby/foo.jar!/foo.class
Show
Charles Oliver Nutter added a comment - Actually I just managed to test loading a class from a .jar file and the URL appears to be there and working. So now I really need those test cases for the expectations in this bug: foo.rb just has "puts _FILE_", and is compiled into foo.class and jarred into foo.jar
~/projects/jruby &#10132; jruby -d -rfoo.jar -e "require 'foo.rb'"
file:/Users/headius/projects/jruby/foo.jar!/foo.class
Hide
Charles Oliver Nutter added a comment -

Well, I'm going to proactively close this. David has confirmed things look great in all cases, so even though we don't have tests we do have an active (and busy) user who would see this break. Since we put in the work to fix it, I'm hoping David or someone from Happy Campers will contribute a set of test cases ASAP. Given that we're less than two weeks away from RubyConf, I'm not expecting anyone has time to do test cases like this, so we'll call it an IOU for now.

Show
Charles Oliver Nutter added a comment - Well, I'm going to proactively close this. David has confirmed things look great in all cases, so even though we don't have tests we do have an active (and busy) user who would see this break. Since we put in the work to fix it, I'm hoping David or someone from Happy Campers will contribute a set of test cases ASAP. Given that we're less than two weeks away from RubyConf, I'm not expecting anyone has time to do test cases like this, so we'll call it an IOU for now.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: