Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: fe1ff12a3e75
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0190ec89021b
Choose a head ref
  • 4 commits
  • 2 files changed
  • 2 contributors

Commits on Jun 11, 2017

  1. __dir__ won't work with embed paths such as uri:classloader: (#4611)

    ... if getAbsolutePath is used - which seems like its not necessary
    and we can pretty much just do what MRI does File.dirname(__FILE__)
    kares committed Jun 11, 2017
    Copy the full SHA
    ba50586 View commit details
  2. Copy the full SHA
    2609812 View commit details
  3. Copy the full SHA
    1460f59 View commit details

Commits on Jun 12, 2017

  1. Merge pull request #4658 from kares/test-dir-in-jar

    __dir__ won't work with embed paths such as uri:classloader: (#4611)
    kares authored Jun 12, 2017
    Copy the full SHA
    0190ec8 View commit details
Showing with 40 additions and 1 deletion.
  1. +3 −1 core/src/main/java/org/jruby/RubyKernel.java
  2. +37 −0 test/jruby/test_jar_complete.rb
4 changes: 3 additions & 1 deletion core/src/main/java/org/jruby/RubyKernel.java
Original file line number Diff line number Diff line change
@@ -1781,7 +1781,9 @@ public static IRubyObject __method__(ThreadContext context, IRubyObject recv) {

@JRubyMethod(name = "__dir__", module = true, visibility = PRIVATE, reads = FILENAME)
public static IRubyObject __dir__(ThreadContext context, IRubyObject recv) {
String dir = RubyFile.dirname(context, new File(context.gatherCallerBacktrace()[1].getFileName()).getAbsolutePath());
// NOTE: not using __FILE__ = context.getFile() since it won't work with JIT
final String __FILE__ = context.gatherCallerBacktrace()[1].getFileName();
String dir = RubyFile.dirname(context, __FILE__);
return RubyString.newString(context.runtime, dir);
}

37 changes: 37 additions & 0 deletions test/jruby/test_jar_complete.rb
Original file line number Diff line number Diff line change
@@ -113,6 +113,43 @@ def test_script_with__FILE__constant_in_jar_with_spaces
assert_match /uri:classloader\:\/_file_constant_\.rb/, output
end

def test_globing_with__dir__in_jar # GH-4611
mkdir_p tmp = File.join(TMP_DIR, __method__.to_s)
complete_jar = File.expand_path(File.join(tmp, 'jruby-complete.jar'))
cp COMPLETE_JAR, complete_jar

File.open(sample = File.join(TMP_DIR, 'sample.rb'), 'wb') do |f|
f.puts 'puts "sample " + __dir__'
end
File.open(_init_ = File.join(TMP_DIR, '_init_.rb'), 'wb') do |f|
f.puts 'puts __FILE__'
f.puts 'puts File.dirname(__FILE__)'
f.puts 'puts __dir__'
f.puts 'Dir[ "#{__dir__}/*.rb" ].each { |f| require f }'
end
File.open(_jruby = File.join(TMP_DIR, '.jrubydir'), 'wb') do |f|
f.puts '.'
f.puts '_init_.rb'
f.puts 'sample.rb'
f.puts ''
end

Dir.chdir(File.dirname(_init_)) do
files = [sample, _init_, _jruby].map { |f| File.basename(f) }
system %{jar uf "#{complete_jar}" #{files.join(' ')}}
end
output = jruby_complete(complete_jar, %{-e "require '_init_'"}).chomp

puts output.inspect if $VERBOSE

output = output.split("\n")

assert_equal 'uri:classloader:/_init_.rb', output[0] # __FILE
assert_equal 'uri:classloader:/', output[1] # File.dirname(__FILE__)
assert_equal 'uri:classloader:/', output[2] # __dir__
assert_equal 'sample uri:classloader:/', output[3] # sample: ...
end

def test_binscripts_can_be_run_from_classpath
output = `java -cp \"#{COMPLETE_JAR}:test/jruby/dir with spaces/testgem.jar\" org.jruby.Main -S testgem`