arton / rjb

Ruby Java Bridge
https://www.artonx.org/collabo/backyard/?RubyJavaBridge
GNU Lesser General Public License v2.1
117 stars 34 forks source link

Patched `rjb/extension` method `require` doesn't work with absolute paths #101

Closed uvlad7 closed 7 months ago

uvlad7 commented 7 months ago

In JRuby I can load jars like this

require File.join(Dir.home, '.m2', 'repository', 'com', 'squareup', 'okio', 'okio', '1.15.0', 'okio-1.15.0.jar')
require File.join(Dir.home, '.m2', 'repository', 'com', 'squareup', 'okhttp3', 'okhttp', '3.12.12', 'okhttp-3.12.12.jar')

but it doesn't work in rjb after require 'rjb/extension' because of the following check

found_path = $LOAD_PATH.reverse.find{|p| File.exist?(File.join(p,path))}

so I had to do this

$LOAD_PATH << File.join(Dir.home, '.m2', 'repository')
require File.join('com', 'squareup', 'okio', 'okio', '1.15.0', 'okio-1.15.0.jar')
require File.join('com', 'squareup', 'okhttp3', 'okhttp', '3.12.12', 'okhttp-3.12.12.jar')

probably this check should be omitted for absolute paths.

Note: c ruby itself requires absolute path just fine

require File.join(Dir.home, 'rjb/lib/rjb/extension')

I believe it's possible to reuse Ruby's own logic used to resolve load path?

Additionally patch require_relative would be nice too

arton commented 7 months ago

@uvlad7 Thank you for your report. rjb-1.7.1.gem skips load path test if an absolute path was given.