Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ensure relative paths do NOT load unless "." is on $LOAD_PATH
Browse files Browse the repository at this point in the history
there is an extra search on "." necessary otherwise the relative path
will be found via the classloader. the regular mri spec does not fail
since current directory in java is independent from the current directory
in ruby
mkristian committed Feb 19, 2015
1 parent 38f3892 commit 1b65f62
Showing 5 changed files with 12 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -148,9 +148,15 @@ private FoundLibrary findResourceLibrary(String baseName, String suffix) {
// if (library != null) return library;
// }

// ruby does not load a relative path unless the current working directory is in $LOAD_PATH
FoundLibrary library = findFileResourceWithLoadPath(baseName, suffix, ".");
// we did not find the file on the $LOAD_PATH but in current directory so we need to treat it
// as not found (the classloader search below will find it otherwise)
if (library != null) return null;

// load the jruby kernel and all resource added to $CLASSPATH
if (!runtime.getInstanceConfig().isLegacyLoadServiceEnabled()) {
FoundLibrary library = findFileResourceWithLoadPath(baseName, suffix, URLResource.URI_CLASSLOADER);
library = findFileResourceWithLoadPath(baseName, suffix, URLResource.URI_CLASSLOADER);
if (library != null) return library;
}

1 change: 1 addition & 0 deletions rakelib/test.rake
Original file line number Diff line number Diff line change
@@ -101,6 +101,7 @@ namespace :test do
end
t.test_files = files
t.verbose = true
t.ruby_opts << '-I.'
t.ruby_opts << '-J-ea'
t.ruby_opts << '-J-cp test:test/target/test-classes:core/target/test-classes'
end
14 changes: 2 additions & 12 deletions test/jruby/test_dir_with_plusses.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
require 'test/unit'
require 'test/jruby/test_helper'

class TestDirWithPlusses < Test::Unit::TestCase
include TestHelper

def prefix
if JRuby.runtime.instance_config.legacy_load_service_enabled? || IS_JAR_EXECUTION
File.dirname(File.expand_path(__FILE__))
else
'uri:classloader:/test/jruby'
end
end

def test_loaded_FILE_in_dir_with_plusses
begin
load 'test/jruby/dir_with_plusses_+++/required.rb'
assert_equal(
File.join(prefix, 'dir_with_plusses_+++', 'required.rb'),
File.join(File.dirname(File.expand_path(__FILE__)), 'dir_with_plusses_+++', 'required.rb'),
$dir_with_plusses_FILE
)
ensure
@@ -29,7 +19,7 @@ def test_required_FILE_in_dir_with_plusses
begin
require 'test/jruby/dir_with_plusses_+++/required.rb'
assert_equal(
File.join(prefix, 'dir_with_plusses_+++', 'required.rb'),
File.join(File.dirname(File.expand_path(__FILE__)), 'dir_with_plusses_+++', 'required.rb'),
$dir_with_plusses_FILE
)
ensure
2 changes: 1 addition & 1 deletion test/jruby/test_jarred_gems_with_spaces_in_directory.rb
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ class TestJarredGemsWithSpacesInDirectory < Test::Unit::TestCase
include TestHelper

def test_list_gem_from_jar_with_spaces_in_directory
out = jruby(%q{-r"test/jruby/dir with spaces/testgem.jar" -S jgem list})
out = jruby(%q{-r"./test/jruby/dir with spaces/testgem.jar" -S jgem list})
assert(out =~ /testgem/)

cp = ENV['CLASSPATH']
10 changes: 1 addition & 9 deletions test/jruby/test_load.rb
Original file line number Diff line number Diff line change
@@ -198,15 +198,7 @@ def require(file)

res = File.expand_path($loading_behavior_result)

assert_equal File.join(prefix, 'test_loading_behavior.rb'), res
end

def prefix
if JRuby.runtime.instance_config.legacy_load_service_enabled? || IS_JAR_EXECUTION
File.expand_path('test/jruby')
else
'uri:classloader:/test/jruby'
end
assert_equal File.join(File.expand_path('test/jruby'), 'test_loading_behavior.rb'), res
end

# JRUBY-3894

0 comments on commit 1b65f62

Please sign in to comment.