[jruby~main:646afeaa] Fix for JRUBY-4663: LoadService error in getClassPathResource when file l

  • From: nicksieger@kenai.com
  • To: commits@jruby.kenai.com
  • Subject: [jruby~main:646afeaa] Fix for JRUBY-4663: LoadService error in getClassPathResource when file l
  • Date: Fri, 19 Mar 2010 04:04:07 +0000

Project:    jruby
Repository: main
Revision:   646afeaa5739ba1e84ef94a8002e2e6bb5044693
Author:     nicksieger
Date:       2010-03-19 04:02:46 UTC
Link:       

Log Message:
------------
Port the Delegator class to Java to improve its performance and avoid the 
nasty 1.8 .rb implementation. JRUBY-4658
Fix for JRUBY-4663: LoadService error in getClassPathResource when file 
location contains '+'
Patch by Garrett Conaty


Revisions:
----------
d9f7f815efb36418bc7249d3e840a57cf2ac5688
646afeaa5739ba1e84ef94a8002e2e6bb5044693


Modified Paths:
---------------
lib/ruby/1.8/delegate.rb
src/org/jruby/Ruby.java
src/org/jruby/ext/WeakRef.java
src/org/jruby/runtime/load/ExternalScript.java
src/org/jruby/runtime/load/LoadService.java


Added Paths:
------------
src/org/jruby/ext/DelegateLibrary.java


Diffs:
------
diff --git a/lib/ruby/1.8/delegate.rb b/lib/ruby/1.8/delegate.rb
index bd2b5e4..c786b90 100644
--- a/lib/ruby/1.8/delegate.rb
+++ b/lib/ruby/1.8/delegate.rb
@@ -114,6 +114,13 @@
 # subclasses.  Subclasses should redefine \_\_getobj\_\_.  For a concrete
 # implementation, see SimpleDelegator.
 #
+require 'jruby'
+require 'java'
+
+# we use a pure-Java Delegator to avoid the nastiness of the code below, and 
to
+# boost performance a bit
+require 'delegate_internal'
+=begin
 class Delegator
   IgnoreBacktracePat = %r"\A#{Regexp.quote(__FILE__)}:\d+:in `"
 
@@ -186,7 +193,7 @@ class Delegator
     __setobj__(obj)
   end
 end
-
+=end
 #
 # A concrete implementation of Delegator, this class provides the means to
 # delegate all supported method calls to the object passed into the 
constructor
diff --git a/src/org/jruby/Ruby.java b/src/org/jruby/Ruby.java
index 0744070..05ea002 100644
--- a/src/org/jruby/Ruby.java
+++ b/src/org/jruby/Ruby.java
@@ -1397,6 +1397,7 @@ public final class Ruby {
         addLazyBuiltin("io/wait.jar", "io/wait", 
"org.jruby.libraries.IOWaitLibrary");
         addLazyBuiltin("etc.jar", "etc", "org.jruby.libraries.EtcLibrary");
         addLazyBuiltin("weakref.rb", "weakref", 
"org.jruby.ext.WeakRef$WeakRefLibrary");
+        addLazyBuiltin("delegate_internal.jar", "delegate_internal", 
"org.jruby.ext.DelegateLibrary");
         addLazyBuiltin("timeout.rb", "timeout", "org.jruby.ext.Timeout");
         addLazyBuiltin("socket.jar", "socket", 
"org.jruby.ext.socket.RubySocket$Service");
         addLazyBuiltin("rbconfig.rb", "rbconfig", 
"org.jruby.libraries.RbConfigLibrary");
diff --git a/src/org/jruby/ext/DelegateLibrary.java 
b/src/org/jruby/ext/DelegateLibrary.java
new file mode 100644
index 0000000..9200140
--- /dev/null
+++ b/src/org/jruby/ext/DelegateLibrary.java
@@ -0,0 +1,90 @@
+package org.jruby.ext;
+
+import org.jruby.Ruby;
+import org.jruby.RubyClass;
+import org.jruby.RubyMethod;
+import org.jruby.RubyModule;
+import org.jruby.RubyObject;
+import org.jruby.anno.JRubyMethod;
+import org.jruby.internal.runtime.methods.DynamicMethod;
+import org.jruby.internal.runtime.methods.JavaMethod.JavaMethodNBlock;
+import org.jruby.runtime.Block;
+import org.jruby.runtime.ThreadContext;
+import org.jruby.runtime.Visibility;
+import org.jruby.runtime.builtin.IRubyObject;
+import org.jruby.runtime.load.Library;
+
+public class DelegateLibrary implements Library{
+    public void load(Ruby runtime, boolean wrap) {
+        RubyClass delegateClass = runtime.defineClass("Delegator", 
runtime.getObject(), runtime.getObject().getAllocator());
+        delegateClass.defineAnnotatedMethods(Delegator.class);
+
+        delegateClass.undefineMethod("==");
+    }
+
+    public static class Delegator {
+        @JRubyMethod(visibility = Visibility.PRIVATE)
+        public static IRubyObject initialize(ThreadContext context, 
IRubyObject self, IRubyObject obj) {
+            return context.getRuntime().getNil();
+        }
+
+        @JRubyMethod(rest = true)
+        public static IRubyObject method_missing(ThreadContext context, 
IRubyObject self, IRubyObject[] args, Block block) {
+            IRubyObject[] newArgs;
+            if (args.length == 0) {
+                newArgs = IRubyObject.NULL_ARRAY;
+            } else {
+                newArgs = new IRubyObject[args.length - 1];
+                System.arraycopy(args, 1, newArgs, 0, newArgs.length);
+            }
+            String methodName = args[0].asJavaString();
+            IRubyObject object = self.callMethod(context, "__getobj__");
+            DynamicMethod method = 
((RubyObject)object).getMetaClass().searchMethod(methodName);
+            if (method.getVisibility().isPrivate()) {
+                throw context.getRuntime().newNoMethodError("method `" + 
methodName + "' is private", methodName, context.getRuntime().getNil());
+            }
+            return method.call(context, object, object.getMetaClass(), 
methodName, newArgs, block);
+        }
+
+        @JRubyMethod(rest = true)
+        public static IRubyObject send(ThreadContext context, IRubyObject 
self, IRubyObject[] args, Block block) {
+            return ((RubyObject)self.callMethod(context, 
"__getobj__")).send(context, args, block);
+        }
+
+        @JRubyMethod
+        public static IRubyObject method(ThreadContext context, IRubyObject 
self, IRubyObject name) {
+            final String methodName = name.asJavaString();
+            final IRubyObject object = self.callMethod(context, 
"__getobj__");
+            final RubyMethod method = 
(RubyMethod)((RubyObject)object).method(name);
+            return RubyMethod.newMethod(self.getMetaClass(), methodName, 
self.getMetaClass(), methodName, new JavaMethodNBlock(self.getMetaClass(), 
Visibility.PUBLIC) {
+                @Override
+                public IRubyObject call(ThreadContext context, IRubyObject 
self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
+                    if (self.callMethod(context, "__getobj__") != object) {
+                        throw context.getRuntime().newNameError("object 
changed", "object changed");
+                    }
+                    return method.call(context, args, block);
+                }
+            }, self);
+        }
+
+        @JRubyMethod(name = "respond_to?")
+        public static IRubyObject repond_to_p(ThreadContext context, 
IRubyObject self, IRubyObject name) {
+            return ((RubyObject)self.callMethod(context, 
"__getobj__")).callMethod(context, "respond_to?", name);
+        }
+
+        @JRubyMethod
+        public static IRubyObject __getobj__(ThreadContext context, 
IRubyObject self) {
+            throw context.getRuntime().newNotImplementedError("need to 
define `__getobj__'");
+        }
+
+        @JRubyMethod
+        public static IRubyObject marshal_dump(ThreadContext context, 
IRubyObject self) {
+            return ((RubyObject)self.callMethod(context, "__getobj__"));
+        }
+
+        @JRubyMethod
+        public static IRubyObject marshal_load(ThreadContext context, 
IRubyObject self, IRubyObject obj) {
+            return self.callMethod(context, "__setobj__", obj);
+        }
+    }
+}
diff --git a/src/org/jruby/ext/WeakRef.java b/src/org/jruby/ext/WeakRef.java
index 1158a67..6595da3 100644
--- a/src/org/jruby/ext/WeakRef.java
+++ b/src/org/jruby/ext/WeakRef.java
@@ -68,6 +68,11 @@ public class WeakRef extends RubyObject {
         
         return obj;
     }
+
+    @JRubyMethod(name = "__setobj__")
+    public IRubyObject setobj(IRubyObject obj) {
+        return getRuntime().getNil();
+    }
     
     @JRubyMethod(name = "new", required = 1, meta = true)
     public static IRubyObject newInstance(IRubyObject clazz, IRubyObject 
arg) {
diff --git a/src/org/jruby/runtime/load/ExternalScript.java 
b/src/org/jruby/runtime/load/ExternalScript.java
index 46a509c..3e20bdd 100644
--- a/src/org/jruby/runtime/load/ExternalScript.java
+++ b/src/org/jruby/runtime/load/ExternalScript.java
@@ -48,10 +48,6 @@ public class ExternalScript implements Library {
         try {
             in = resource.getInputStream();
             String name = normalizeSeps(resource.getName());
-            try {
-                // TODO: Fix charset use for JRUBY-4553
-                name = java.net.URLDecoder.decode(name, "ISO-8859-1");
-            } catch(Exception ignored) {}
 
             if 
(runtime.getInstanceConfig().getCompileMode().shouldPrecompileAll()) {
                 runtime.compileAndLoadFile(name, in, wrap);
diff --git a/src/org/jruby/runtime/load/LoadService.java 
b/src/org/jruby/runtime/load/LoadService.java
index 5b8b06e..21b51db 100644
--- a/src/org/jruby/runtime/load/LoadService.java
+++ b/src/org/jruby/runtime/load/LoadService.java
@@ -1229,7 +1229,15 @@ public class LoadService {
             // the classpath scheme explicitly
             if (!isClasspathScheme && loc.toString().startsWith("jar:file:") 
&& isRequireable(loc)) {
                 // Make sure this is not a directory or unavailable in some 
way
-                path = loc.getPath();
+                try {
+                    path = loc.toURI().getSchemeSpecificPart();
+                } catch (java.net.URISyntaxException urise) {
+                    if (runtime.getInstanceConfig().isDebug()) {
+                        runtime.getErr().println("URISyntaxException trying 
to parse " + loc + ", stack trace follows:");
+                        urise.printStackTrace(runtime.getErr());
+                    }
+                    return null;
+                }
             }
             LoadServiceResource foundResource = new LoadServiceResource(loc, 
path);
             debugLogFound(foundResource);




[jruby~main:646afeaa] Fix for JRUBY-4663: LoadService error in getClassPathResource when file l

nicksieger 03/19/2010
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120127.ac94057)
 
 
Close
loading
Please Confirm
Close