Changes:
- load 'filename' now only looks for filename in the load path; it does not attempt to append any extensions.
- require 'filename' looks for filename first if it ends in .rb, otherwise it goes through the extension searching.
- the list of extensions searched no longer includes "" since require WILL NOT load files without extensions.
- the builtin libraries loaded in Ruby.java now are named with .rb extensions, since they are always "require"ed and require expects an extension.
Tests:
- rubicon looks pretty good with this; no major cock-ups
- I created no unit tests for this, but it probably should have some
With Rake actually running now (as a gem) we ought to be able to start playing with it.
On 6/29/06,
Charles O Nutter <[EMAIL PROTECTED]> wrote:
I have a patch for this modified behavior in the works. It seems to allow rake to run correctly installed from a gem (where it did not run at all before). There is also an additional difference in behavior I don't think we're enforcing: according to Ruby docs for Kernel#load: "In no circumstance will any local variables in the loaded file be propagated to the loading environment.". Since the original code was almost identical for load and require, I would bet we're not doing this.On 6/29/06, Charles O Nutter <[EMAIL PROTECTED]> wrote:Actually I think I figured it out. The gem install also has a bin dir, which is what gets loaded when you "load 'rake'". This actually kicks off the script.
I found the issue in JRuby, but I thought I'd confirm it with you:
The logic behind 'load' and 'require' in JRuby has long been identical, other than 'require' keeping a hash of loaded features. Both searched all load paths for the filename specified PLUS the filename specified followed by a series of possible extensions. It seems that the correct behavior is as follows:
- load only looks for the exact filename specified in the current load path, and does not attempt any additional extensions
- require will look for the exact filename if it has a .rb, .so, .dll, etc extension. Otherwise it will attempt to append .rb and load.
So based on this logic, given files testreq and testreq2.rb in the current dir:
- load 'testreq' will succeed
- load 'testreq2' will not succeed
- load 'testreq2.rb' will succeed
- require 'testreq' will not succeed
- require 'testreq2' will succeed
- require 'testreq2.rb' will succeed
Does this sound correct to you?On 6/29/06, Charles O Nutter < [EMAIL PROTECTED]> wrote:I'm trying to get Rake running well under JRuby today, and I'm having some trouble understanding how Rake actually starts up. I see the following in rake.rb:
if __FILE__ == $0 then
Rake::Application.new.run
end
However, when running the "rake" script in Ruby or JRuby, __FILE__ and $0 never appear to be ==. Since the "rake" script itself only loads rake.rb, I'm confused how Rake actually starts running under Ruby proper. Could you tell me what I'm missing?
Under Ruby, logging __FILE__ and $0 from above:
"/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb"
"/usr/bin/rake"
<then expected Rake run output displays>
Under JRuby:
"/home/headius/workspace/jruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb"
"/home/headius/workspace/jruby/bin/rake"
<nothing happens>
--
Charles Oliver Nutter @ headius.blogspot.com
JRuby Developer @ www.jruby.org
Application Architect @ www.ventera.com
--
Charles Oliver Nutter @ headius.blogspot.com
JRuby Developer @ www.jruby.org
Application Architect @ www.ventera.com
--
Charles Oliver Nutter @ headius.blogspot.com
JRuby Developer @ www.jruby.org
Application Architect @ www.ventera.com
--
Charles Oliver Nutter @ headius.blogspot.com
JRuby Developer @ www.jruby.org
Application Architect @ www.ventera.com
Index: src/org/jruby/Ruby.java
===================================================================
RCS file: /cvsroot/jruby/jruby/src/org/jruby/Ruby.java,v
retrieving revision 1.125
diff -u -r1.125 Ruby.java
--- src/org/jruby/Ruby.java 17 Jun 2006 22:27:22 -0000 1.125
+++ src/org/jruby/Ruby.java 29 Jun 2006 05:57:06 -0000
@@ -410,13 +410,13 @@
initBuiltinClasses();
// Load additional definitions and hacks from etc.rb
- getLoadService().load("builtin/etc.rb");
+ getLoadService().smartLoad("builtin/etc.rb");
}
private void initLibraries() {
loadService = new LoadService(this);
- loadService.registerBuiltin("java", new BuiltinScript("javasupport"));
- loadService.registerBuiltin("socket", new SocketLibrary());
+ loadService.registerBuiltin("java.rb", new BuiltinScript("javasupport"));
+ loadService.registerBuiltin("socket.rb", new SocketLibrary());
loadService.registerBuiltin("rbconfig.rb", new RbConfigLibrary());
for (int i=0; i<BUILTIN_LIBRARIES.length; i++) {
@@ -424,9 +424,9 @@
}
- loadService.registerBuiltin("jruby", new JRubyLibrary());
- loadService.registerBuiltin("stringio", new StringIOLibrary());
- loadService.registerBuiltin("zlib", new ZlibLibrary());
+ loadService.registerBuiltin("jruby.rb", new JRubyLibrary());
+ loadService.registerBuiltin("stringio.rb", new StringIOLibrary());
+ loadService.registerBuiltin("zlib.rb", new ZlibLibrary());
}
private void initCoreClasses() {
Index: src/org/jruby/runtime/load/LoadService.java
===================================================================
RCS file: /cvsroot/jruby/jruby/src/org/jruby/runtime/load/LoadService.java,v
retrieving revision 1.11
diff -u -r1.11 LoadService.java
--- src/org/jruby/runtime/load/LoadService.java 21 Mar 2006 22:37:05 -0000 1.11
+++ src/org/jruby/runtime/load/LoadService.java 29 Jun 2006 05:57:07 -0000
@@ -60,7 +60,7 @@
public class LoadService {
private static final String JRUBY_BUILTIN_SUFFIX = ".jrb";
- private static final String[] suffixes = { JRUBY_BUILTIN_SUFFIX, ".ast.ser", ".rb.ast.ser", ".rb", "", ".jar" };
+ private static final String[] suffixes = { JRUBY_BUILTIN_SUFFIX, ".ast.ser", ".rb.ast.ser", ".rb", ".jar" };
private final List loadPath = new ArrayList();
private final Set loadedFeatures = Collections.synchronizedSet(new HashSet());
@@ -112,19 +112,44 @@
public void load(String file) {
Library library = null;
- for (int i = 0; i < suffixes.length; i++) {
- library = findLibrary(file + suffixes[i]);
- if (library != null) {
- break;
+
+ library = findLibrary(file);
+
+ if (library == null) {
+ throw runtime.newLoadError("No such file to load -- " + file);
+ }
+ try {
+ library.load(runtime);
+ } catch (IOException e) {
+ throw runtime.newLoadError("IO error -- " + file);
+ }
+ }
+
+ public void smartLoad(String file) {
+ Library library = null;
+
+ if (file.endsWith(".rb")) {
+ // .rb specified, try without suffixes
+ library = findLibrary(file);
+ }
+
+ if (library == null) {
+ // nothing yet, try suffixes
+ for (int i = 0; i < suffixes.length; i++) {
+ library = findLibrary(file + suffixes[i]);
+ if (library != null) {
+ break;
+ }
}
}
+
if (library == null) {
throw runtime.newLoadError("No such file to load -- " + file);
}
try {
- library.load(runtime);
+ library.load(runtime);
} catch (IOException e) {
- throw runtime.newLoadError("IO error -- " + file);
+ throw runtime.newLoadError("IO error -- " + file);
}
}
@@ -155,7 +180,7 @@
loadedFeatures.add(name);
try {
- load(file);
+ smartLoad(file);
return true;
} catch (RuntimeException e) {
loadedFeatures.remove(name);
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________ Jruby-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jruby-devel
