[jruby~main:a44514e6] fixes JRUBY-4543: Multiple RubySpec failures for Kernel's load() and requ

  • From: nicksieger@kenai.com
  • To: commits@jruby.kenai.com
  • Subject: [jruby~main:a44514e6] fixes JRUBY-4543: Multiple RubySpec failures for Kernel's load() and requ
  • Date: Tue, 9 Mar 2010 08:58:30 +0000

Project:    jruby
Repository: main
Revision:   a44514e6740648f27a3a9ebf1cd84363c2b2db5d
Author:     nicksieger
Date:       2010-02-14 16:32:14 UTC
Link:       

Log Message:
------------
fixes JRUBY-4543: Multiple RubySpec failures for Kernel's load() and require()
Signed-off-by: Charles Oliver Nutter <headius@headius.com>


Revisions:
----------
a44514e6740648f27a3a9ebf1cd84363c2b2db5d


Modified Paths:
---------------
spec/tags/1.8/ruby/core/kernel/load_tags.txt
spec/tags/1.9/ruby/core/kernel/load_tags.txt
spec/tags/1.9/ruby/core/kernel/require_tags.txt
src/org/jruby/RubyInstanceConfig.java
src/org/jruby/RubyKernel.java
src/org/jruby/runtime/load/LoadService.java
src/org/jruby/runtime/load/LoadServiceResource.java


Added Paths:
------------
src/org/jruby/runtime/load/LoadService19.java


Diffs:
------
diff --git a/spec/tags/1.8/ruby/core/kernel/load_tags.txt 
b/spec/tags/1.8/ruby/core/kernel/load_tags.txt
index e053076..e74cacb 100644
--- a/spec/tags/1.8/ruby/core/kernel/load_tags.txt
+++ b/spec/tags/1.8/ruby/core/kernel/load_tags.txt
@@ -1,5 +1,2 @@
 fails(JRUBY-4339):Kernel#load allows wrapping the code in the file in an 
anonymous module
-fails(JRUBY-4543):Kernel#load (path resolution) does not resolve a ./ 
relative path against $LOAD_PATH entries
 fails(JRUBY-4543):Kernel#load sets the enclosing scope to an anonymous 
module if passed true for 'wrap'
-fails(JRUBY-4543):Kernel#load (shell expansion) expands a tilde to the HOME 
environment variable as the path to load
-fails(JRUBY-4543):Kernel.load (path resolution) does not resolve a ./ 
relative path against $LOAD_PATH entries
diff --git a/spec/tags/1.8/ruby/core/kernel/require_tags.txt 
b/spec/tags/1.8/ruby/core/kernel/require_tags.txt
deleted file mode 100644
index 56fd62b..0000000
--- a/spec/tags/1.8/ruby/core/kernel/require_tags.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-fails(JRUBY-4543):Kernel#require (path resolution) does not resolve a ./ 
relative path against $LOAD_PATH entries
-fails(JRUBY-4543):Kernel#require (shell expansion) does not perform tilde 
expansion before storing paths in $LOADED_FEATURES
-fails(JRUBY-4543):Kernel.require (path resolution) does not resolve a ./ 
relative path against $LOAD_PATH entries
-fails(JRUBY-4543):Kernel.require (shell expansion) does not perform tilde 
expansion before storing paths in $LOADED_FEATURES
diff --git a/spec/tags/1.9/ruby/core/kernel/load_tags.txt 
b/spec/tags/1.9/ruby/core/kernel/load_tags.txt
index f51f1d9..913f72a 100644
--- a/spec/tags/1.9/ruby/core/kernel/load_tags.txt
+++ b/spec/tags/1.9/ruby/core/kernel/load_tags.txt
@@ -1,11 +1,4 @@
 fails:Kernel#load returns __FILE__ as an absolute path
 fails:Kernel#load calls #to_path on non-String arguments
 fails:Kernel#load allows wrapping the code in the file in an anonymous module
-fails(JRUBY-4543):Kernel#load (path resolution) calls #to_path on non-String 
objects
-fails(JRUBY-4543):Kernel#load (path resolution) calls #to_str on non-String 
objects returned by #to_path
-fails(JRUBY-4543):Kernel#load (path resolution) does not resolve a ./ 
relative path against $LOAD_PATH entries
 fails(JRUBY-4543):Kernel#load sets the enclosing scope to an anonymous 
module if passed true for 'wrap'
-fails(JRUBY-4543):Kernel#load (shell expansion) expands a tilde to the HOME 
environment variable as the path to load
-fails(JRUBY-4543):Kernel.load (path resolution) calls #to_path on non-String 
objects
-fails(JRUBY-4543):Kernel.load (path resolution) calls #to_str on non-String 
objects returned by #to_path
-fails(JRUBY-4543):Kernel.load (path resolution) does not resolve a ./ 
relative path against $LOAD_PATH entries
diff --git a/spec/tags/1.9/ruby/core/kernel/require_tags.txt 
b/spec/tags/1.9/ruby/core/kernel/require_tags.txt
index 7448b16..3f99a54 100644
--- a/spec/tags/1.9/ruby/core/kernel/require_tags.txt
+++ b/spec/tags/1.9/ruby/core/kernel/require_tags.txt
@@ -6,23 +6,3 @@ fails:Kernel#require performs tilde expansion before storing 
paths in $LOADED_FE
 fails:Kernel#require collapses multiple consecutive path separators before 
storing in $LOADED_FEATURES
 fails:Kernel#require collapses '../' inside an absolute path before storing 
in $LOADED_FEATURES
 fails:Kernel#require produces __FILE__ as the given filename and __LINE__ as 
the source line number
-fails(JRUBY-4543):Kernel#require (path resolution) does not resolve a ./ 
relative path against $LOAD_PATH entries
-fails(JRUBY-4543):Kernel#require ($LOAD_FEATURES) stores ../ relative paths 
as absolute paths
-fails(JRUBY-4543):Kernel#require ($LOAD_FEATURES) stores ./ relative paths 
as absolute paths
-fails(JRUBY-4543):Kernel#require ($LOAD_FEATURES) collapses duplicate path 
separators
-fails(JRUBY-4543):Kernel#require ($LOAD_FEATURES) canonicalizes non-unique 
absolute paths
-fails(JRUBY-4543):Kernel#require ($LOAD_FEATURES) adds the suffix of the 
resolved filename
-fails(JRUBY-4543):Kernel#require ($LOAD_FEATURES) does not load a 
non-canonical path for a file already loaded
-fails(JRUBY-4543):Kernel#require ($LOAD_FEATURES) does not load a ./ 
relative path for a file already loaded
-fails(JRUBY-4543):Kernel#require ($LOAD_FEATURES) does not load a ../ 
relative path for a file already loaded
-fails(JRUBY-4543):Kernel#require (shell expansion) performs tilde expansion 
before storing paths in $LOADED_FEATURES
-fails(JRUBY-4543):Kernel.require (path resolution) does not resolve a ./ 
relative path against $LOAD_PATH entries
-fails(JRUBY-4543):Kernel.require ($LOAD_FEATURES) stores ../ relative paths 
as absolute paths
-fails(JRUBY-4543):Kernel.require ($LOAD_FEATURES) stores ./ relative paths 
as absolute paths
-fails(JRUBY-4543):Kernel.require ($LOAD_FEATURES) collapses duplicate path 
separators
-fails(JRUBY-4543):Kernel.require ($LOAD_FEATURES) canonicalizes non-unique 
absolute paths
-fails(JRUBY-4543):Kernel.require ($LOAD_FEATURES) adds the suffix of the 
resolved filename
-fails(JRUBY-4543):Kernel.require ($LOAD_FEATURES) does not load a 
non-canonical path for a file already loaded
-fails(JRUBY-4543):Kernel.require ($LOAD_FEATURES) does not load a ./ 
relative path for a file already loaded
-fails(JRUBY-4543):Kernel.require ($LOAD_FEATURES) does not load a ../ 
relative path for a file already loaded
-fails(JRUBY-4543):Kernel.require (shell expansion) performs tilde expansion 
before storing paths in $LOADED_FEATURES
diff --git a/src/org/jruby/RubyInstanceConfig.java 
b/src/org/jruby/RubyInstanceConfig.java
index b0a1ef7..4859d84 100644
--- a/src/org/jruby/RubyInstanceConfig.java
+++ b/src/org/jruby/RubyInstanceConfig.java
@@ -53,6 +53,7 @@ import org.jruby.compiler.ASTCompiler19;
 import org.jruby.exceptions.MainExitException;
 import org.jruby.runtime.Constants;
 import org.jruby.runtime.load.LoadService;
+import org.jruby.runtime.load.LoadService19;
 import org.jruby.util.ClassCache;
 import org.jruby.util.JRubyFile;
 import org.jruby.util.KCode;
@@ -285,6 +286,9 @@ public class RubyInstanceConfig {
 
         LoadServiceCreator DEFAULT = new LoadServiceCreator() {
                 public LoadService create(Ruby runtime) {
+                    if (runtime.is1_9()) {
+                        return new LoadService19(runtime);
+                    }
                     return new LoadService(runtime);
                 }
             };
diff --git a/src/org/jruby/RubyKernel.java b/src/org/jruby/RubyKernel.java
index f543f73..d19334d 100644
--- a/src/org/jruby/RubyKernel.java
+++ b/src/org/jruby/RubyKernel.java
@@ -987,14 +987,28 @@ public class RubyKernel {
         return runtime.getFalse();
     }
 
-    @JRubyMethod(name = "load", required = 1, optional = 1, frame = true, 
module = true, visibility = PRIVATE)
+    @JRubyMethod(name = "load", required = 1, optional = 1, frame = true, 
module = true, visibility = PRIVATE, compat = CompatVersion.RUBY1_8)
     public static IRubyObject load(IRubyObject recv, IRubyObject[] args, 
Block block) {
-        Ruby runtime = recv.getRuntime();
-        RubyString file = args[0].convertToString();
+        return loadCommon(args[0], recv.getRuntime(), args, block);
+    }
+
+    @JRubyMethod(name = "load", required = 1, optional = 1, frame = true, 
module = true, visibility = PRIVATE, compat = CompatVersion.RUBY1_9)
+    public static IRubyObject load19(ThreadContext context, IRubyObject 
recv, IRubyObject[] args, Block block) {
+        IRubyObject file = args[0];
+        if (!(file instanceof RubyString) && file.respondsTo("to_path")) {
+            file = file.callMethod(context, "to_path");
+        }
+
+        return loadCommon(file, context.getRuntime(), args, block);
+    }
+
+    private static IRubyObject loadCommon(IRubyObject fileName, Ruby 
runtime, IRubyObject[] args, Block block) {
+        RubyString file = fileName.convertToString();
+
         boolean wrap = args.length == 2 ? args[1].isTrue() : false;
 
         runtime.getLoadService().load(file.getByteList().toString(), wrap);
-        
+
         return runtime.getTrue();
     }
 
diff --git a/src/org/jruby/runtime/load/LoadService.java 
b/src/org/jruby/runtime/load/LoadService.java
index de7a6f3..188f687 100644
--- a/src/org/jruby/runtime/load/LoadService.java
+++ b/src/org/jruby/runtime/load/LoadService.java
@@ -791,7 +791,7 @@ public class LoadService {
             String file = baseName + suffix;
             LoadServiceResource resource = findFileInClasspath(file);
             if (resource != null) {
-                state.loadName = file;
+                state.loadName = resolveLoadName(resource, file);
                 return createLibrary(state, resource);
             }
         }
@@ -831,7 +831,7 @@ public class LoadService {
                     }
                     foundResource = new LoadServiceResource(file, s, 
absolute);
                     debugLogFound(foundResource);
-                    state.loadName = namePlusSuffix;
+                    state.loadName = resolveLoadName(foundResource, 
namePlusSuffix);
                     break;
                 }
             } catch (IllegalArgumentException illArgEx) {
@@ -841,6 +841,40 @@ public class LoadService {
         
         return foundResource;
     }
+
+    protected LoadServiceResource tryResourceFromHome(SearchState state, 
String baseName, SuffixType suffixType) throws RaiseException {
+        LoadServiceResource foundResource = null;
+
+        RubyHash env = (RubyHash) runtime.getObject().fastGetConstant("ENV");
+        RubyString env_home = runtime.newString("HOME");
+        if (env.has_key_p(env_home).isFalse()) {
+            return null;
+        }
+        String home = env.op_aref(runtime.getCurrentContext(), 
env_home).toString();
+        String path = baseName.substring(2);
+
+        for (String suffix : suffixType.getSuffixes()) {
+            String namePlusSuffix = path + suffix;
+            // check home directory; if file exists, retrieve URL and return 
resource
+            try {
+                JRubyFile file = JRubyFile.create(home, 
RubyFile.expandUserPath(runtime.getCurrentContext(), namePlusSuffix));
+                debugLogTry("resourceFromHome", file.toString());
+                if (file.isFile() && file.isAbsolute() && file.canRead()) {
+                    boolean absolute = true;
+                    String s = "~/" + namePlusSuffix;
+                    
+                    foundResource = new LoadServiceResource(file, s, 
absolute);
+                    debugLogFound(foundResource);
+                    state.loadName = resolveLoadName(foundResource, s);
+                    break;
+                }
+            } catch (IllegalArgumentException illArgEx) {
+            } catch (SecurityException secEx) {
+            }
+        }
+
+        return foundResource;
+    }
     
     protected LoadServiceResource tryResourceFromJarURL(SearchState state, 
String baseName, SuffixType suffixType) {
         // if a jar or file URL, return load service resource directly 
without further searching
@@ -862,7 +896,7 @@ public class LoadService {
                     throw runtime.newIOErrorFromException(e);
                 }
                 if (foundResource != null) {
-                    state.loadName = namePlusSuffix;
+                    state.loadName = resolveLoadName(foundResource, 
namePlusSuffix);
                     break; // end suffix iteration
                 }
             }
@@ -882,7 +916,7 @@ public class LoadService {
                     }
                 } catch(Exception e) {}
                 if (foundResource != null) {
-                    state.loadName = namePlusSuffix;
+                    state.loadName = resolveLoadName(foundResource, 
namePlusSuffix);
                     break; // end suffix iteration
                 }
             }    
@@ -899,7 +933,17 @@ public class LoadService {
             foundResource = tryResourceFromCWD(state, baseName, suffixType);
 
             if (foundResource != null) {
-                state.loadName = foundResource.getName();
+                state.loadName = resolveLoadName(foundResource, 
foundResource.getName());
+                return foundResource;
+            }
+        }
+
+        // if it's a ~/ baseName use HOME logic
+        if (baseName.startsWith("~/")) {
+            foundResource = tryResourceFromHome(state, baseName, suffixType);
+
+            if (foundResource != null) {
+                state.loadName = resolveLoadName(foundResource, 
foundResource.getName());
                 return foundResource;
             }
         }
@@ -911,7 +955,7 @@ public class LoadService {
                 foundResource = tryResourceAsIs(namePlusSuffix);
 
                 if (foundResource != null) {
-                    state.loadName = namePlusSuffix;
+                    state.loadName = resolveLoadName(foundResource, 
namePlusSuffix);
                     return foundResource;
                 }
             }
@@ -933,7 +977,7 @@ public class LoadService {
                     if(ss.startsWith("./")) {
                         ss = ss.substring(2);
                     }
-                    state.loadName = ss;
+                    state.loadName = resolveLoadName(foundResource, ss);
                     break Outer;
                 }
             } else {
@@ -943,6 +987,8 @@ public class LoadService {
 
                     if (looksLikeJarURL) {
                         foundResource = 
tryResourceFromJarURLWithLoadPath(namePlusSuffix, loadPathEntry);
+                    } else if(namePlusSuffix.startsWith("./")) {
+                        throw runtime.newLoadError("");
                     } else {
                         foundResource = 
tryResourceFromLoadPath(namePlusSuffix, loadPathEntry);
                     }
@@ -952,7 +998,7 @@ public class LoadService {
                         if(ss.startsWith("./")) {
                             ss = ss.substring(2);
                         }
-                        state.loadName = ss;
+                        state.loadName = resolveLoadName(foundResource, ss);
                         break Outer; // end suffix iteration
                     }
                 }
@@ -1065,11 +1111,8 @@ public class LoadService {
                     if (reportedPath.charAt(0) == '.' && 
reportedPath.charAt(1) == '/') {
                         reportedPath = reportedPath.replaceFirst("\\./", 
runtime.getCurrentDirectory());
                     }
-//                     if (reportedPath.charAt(0) != '.') {
-//                         reportedPath = "./" + reportedPath;
-//                     }
+
                     actualPath = 
JRubyFile.create(runtime.getCurrentDirectory(), 
RubyFile.expandUserPath(runtime.getCurrentContext(), namePlusSuffix));
-                    //                    actualPath = new 
File(RubyFile.expandUserPath(runtime.getCurrentContext(), reportedPath));
                 }
                 debugLogTry("resourceAsIs", actualPath.toString());
                 if (actualPath.isFile() && actualPath.canRead()) {
@@ -1205,4 +1248,8 @@ public class LoadService {
         return path;
       }
     }
+
+    protected String resolveLoadName(LoadServiceResource foundResource, 
String previousPath) {
+        return previousPath;
+    }
 }
diff --git a/src/org/jruby/runtime/load/LoadService19.java 
b/src/org/jruby/runtime/load/LoadService19.java
new file mode 100644
index 0000000..54ac567
--- /dev/null
+++ b/src/org/jruby/runtime/load/LoadService19.java
@@ -0,0 +1,42 @@
+/***** BEGIN LICENSE BLOCK *****
+ * Version: CPL 1.0/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Common Public
+ * License Version 1.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * Copyright (C) 2002-2010 JRuby Community
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the 
"LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the CPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the CPL, the GPL or the LGPL.
+***** END LICENSE BLOCK *****/
+package org.jruby.runtime.load;
+
+import org.jruby.Ruby;
+
+public class LoadService19 extends LoadService {
+    
+    public LoadService19(Ruby runtime) {
+        super(runtime);
+    }
+
+    @Override
+    protected String resolveLoadName(LoadServiceResource foundResource, 
String previousPath) {
+        return foundResource.getAbsolutePath();
+    }
+}
diff --git a/src/org/jruby/runtime/load/LoadServiceResource.java 
b/src/org/jruby/runtime/load/LoadServiceResource.java
index 93fdf40..6a5f863 100644
--- a/src/org/jruby/runtime/load/LoadServiceResource.java
+++ b/src/org/jruby/runtime/load/LoadServiceResource.java
@@ -102,6 +102,14 @@ public class LoadServiceResource {
         }
     }
 
+    public String getAbsolutePath() {
+        try {
+            return new File(getURL().getFile()).getCanonicalPath();
+        } catch (IOException e) {
+            return resource.toString();
+        }
+    }
+
     public boolean isAbsolute() {
         return absolute;
     }




[jruby~main:a44514e6] fixes JRUBY-4543: Multiple RubySpec failures for Kernel's load() and requ

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