From 50075d8e83d764ac31fd0b1c2020a2ca16fdacee Mon Sep 17 00:00:00 2001
From: David Calavera <david.calavera@gmail.com>
Date: Mon, 7 Sep 2009 11:22:01 +0200
Subject: [PATCH] fixes JRUBY-3286: Java extension (JAR) not required if using an absolute path

---
 build.xml                                   |    4 ++++
 src/org/jruby/runtime/load/LoadService.java |   15 ++++++++++++---
 test/my_app_ext.jar                         |  Bin 0 -> 724 bytes
 test/org/jruby/test/TestLoadService.java    |    4 ++++
 4 files changed, 20 insertions(+), 3 deletions(-)
 create mode 100644 test/my_app_ext.jar

diff --git a/build.xml b/build.xml
index 991dec0..c3b2101 100644
--- a/build.xml
+++ b/build.xml
@@ -554,6 +554,10 @@
     <copy todir="${test.classes.dir}">
       <fileset dir="${test.dir}" includes="org/**/*.rb"/>
     </copy>
+
+    <copy todir="${test.classes.dir}">
+      <fileset dir="${test.dir}" includes="my_app_ext.jar"/>
+    </copy>
   </target>
 
   <target name="install-gems">
diff --git a/src/org/jruby/runtime/load/LoadService.java b/src/org/jruby/runtime/load/LoadService.java
index ec9dad4..ad4f48c 100644
--- a/src/org/jruby/runtime/load/LoadService.java
+++ b/src/org/jruby/runtime/load/LoadService.java
@@ -255,7 +255,7 @@ public class LoadService {
     public SearchState findFileForLoad(String file) throws AlreadyLoaded {
         SearchState state = new SearchState(file);
         state.prepareRequireSearch(file);
-
+  
         for (LoadSearcher searcher : searchers) {
             if (searcher.shouldTrySearch(state)) {
                 searcher.trySearch(state);
@@ -466,8 +466,17 @@ public class LoadService {
                 }
 
                 // quietly try to load the class
-                Class theClass = runtime.getJavaSupport().loadJavaClassQuiet(className);
-                state.library = new ClassExtensionLibrary(theClass);
+                Class theClass = null;
+                try {
+                    theClass = runtime.getJavaSupport().loadJavaClassQuiet(className);
+                    state.library = new ClassExtensionLibrary(theClass);
+                } catch (Exception e) {
+                    String[] classNameWithoutPackage = className.split("\\.");
+                    className = classNameWithoutPackage[classNameWithoutPackage.length - 1];
+
+                    theClass = runtime.getJavaSupport().loadJavaClassQuiet(className);
+                    state.library = new ClassExtensionLibrary(theClass);
+                }
             } catch (Exception ee) {
                 state.library = null;
                 runtime.getGlobalVariables().set("$!", runtime.getNil());
diff --git a/test/my_app_ext.jar b/test/my_app_ext.jar
new file mode 100644
index 0000000000000000000000000000000000000000..727189323062020bd09639fa1bd420a1d61242f8
GIT binary patch
literal 724
zcmWIWW@Zs#-~dAID0OQFB*4kQ!r<!~;;8HC=cfPf6axb@Lx49s2S^1IR9OH{%_2Y*
zaLvAsex7cw!6ACSZl8V6oc8h7)w{^+t*dqJ%=yhh23L$9JT21m^40P5y;!=6g>%MB
z$s^LUG%{GGKhyk?rY8PWJX~!0l4oMt70*;(XMQUBSi}f+NV$x$qdU+V5JotJ3C$Ox
zAcs^s78JNvlmw?1m1QQU>LuqS78l3*AM`uqAW$2;KwFe`vAQt-y@ux56;~&$xEOrV
zrH4I#cdGL?P2I?7r~fCp)rI(L8st;wFm-ZH|6Z1UZ;$!s&%gJw74%MKFqPqy;oib(
z#q$5!GBbIBth@KD7yg^j%ezqa))gD^;M_a2FL8#?imJV(apua5f?K@C<`Xw+muSXI
z=2gkJBuo+2GxFayX+H1i-8bJ9PVDcQefvbr(X4e*83)oo@0D8^T$;M*QfJM@jh#hK
z|LqToX67w-Q<KqqZ=N0Tc8YfS=N&D_!#{qiS#<o2W=~VS_?aVjUaWWUt`p#s_?tU%
zV`qZ8ZTdH@=3m$6`5DONt%<G&MWBJk*OOm?q2j>^3O7b35eC%whea+Z{!sxuLP4nk
zT`O{QfMOp3Y=KO;R;09mYyv3SkR1k!HUu~ZWMYlP0B=?{kTPZ<JOHHs0sX|l004Y~
B(5(Of

literal 0
HcmV?d00001

diff --git a/test/org/jruby/test/TestLoadService.java b/test/org/jruby/test/TestLoadService.java
index db430b0..6708593 100644
--- a/test/org/jruby/test/TestLoadService.java
+++ b/test/org/jruby/test/TestLoadService.java
@@ -94,4 +94,8 @@ public class TestLoadService extends TestRubyBase {
             // ok
         }
     }
+
+    public void testRequestJRubyExtension() {
+        assertEquals(true, loadService.require("build/classes/test/my_app_ext"));
+    }
 }
-- 
1.6.0.4


