[jruby~main:9d5480d7] JRUBY-1650: "exit 0" not causing expected behaviour
- From: nicksieger@kenai.com
- To: commits@jruby.kenai.com
- Subject: [jruby~main:9d5480d7] JRUBY-1650: "exit 0" not causing expected behaviour
- Date: Tue, 9 Mar 2010 21:21:58 +0000
Project: jruby
Repository: main
Revision: 9d5480d704c57612a1e4d5139829cb6dbeb4467d
Author: nicksieger
Date: 2010-03-09 16:49:34 UTC
Link:
Log Message:
------------
JRUBY-1650: "exit 0" not causing expected behaviour
Main.run now returns a Status object, instead of an int, that can indicate
if this is an explicit or implicit exit.
Based on patch by Andrew Wason, with tweaks.
Signed-off-by: Charles Oliver Nutter <headius@headius.com>
Revisions:
----------
9d5480d704c57612a1e4d5139829cb6dbeb4467d
Modified Paths:
---------------
src/org/jruby/Main.java
src/org/jruby/util/NailMain.java
src/org/jruby/util/ShellLauncher.java
Diffs:
------
diff --git a/src/org/jruby/Main.java b/src/org/jruby/Main.java
index ed2d0f9..ea90dcd 100644
--- a/src/org/jruby/Main.java
+++ b/src/org/jruby/Main.java
@@ -94,9 +94,9 @@ public class Main {
Main main = new Main();
try {
- int status = main.run(args);
- if (status != 0) {
- System.exit(status);
+ Status status = main.run(args);
+ if (status.isExit()) {
+ System.exit(status.getStatus());
}
} catch (RaiseException re) {
throw re;
@@ -111,7 +111,7 @@ public class Main {
}
}
- public int run(String[] args) {
+ public Status run(String[] args) {
try {
config.processArguments(args);
return run();
@@ -122,7 +122,7 @@ public class Main {
printUsage();
}
}
- return mee.getStatus();
+ return new Status(mee.getStatus());
} catch (OutOfMemoryError oome) {
// produce a nicer error since Rubyists aren't used to seeing
this
System.gc();
@@ -141,7 +141,7 @@ public class Main {
} else {
config.getError().println("Specify -w for full
OutOfMemoryError stack trace");
}
- return 1;
+ return new Status(1);
} catch (StackOverflowError soe) {
// produce a nicer error since Rubyists aren't used to seeing
this
System.gc();
@@ -160,7 +160,7 @@ public class Main {
} else {
config.getError().println("Specify -w for full
StackOverflowError stack trace");
}
- return 1;
+ return new Status(1);
} catch (UnsupportedClassVersionError ucve) {
config.getError().println("Error: Some library (perhaps JRuby)
was built with a later JVM version.");
config.getError().println("Please use libraries built with the
version you intend to use or an earlier one.");
@@ -171,13 +171,13 @@ public class Main {
} else {
config.getError().println("Specify -w for full
UnsupportedClassVersionError stack trace");
}
- return 1;
+ return new Status(1);
} catch (ThreadKill kill) {
- return 0;
+ return new Status();
}
}
- public int run() {
+ public Status run() {
if (config.isShowVersion()) {
showVersion();
}
@@ -193,7 +193,7 @@ public class Main {
if (config.shouldPrintProperties()) {
printProperties();
}
- return 0;
+ return new Status();
}
InputStream in = config.getScriptSource();
@@ -258,7 +258,7 @@ public class Main {
}
}
}
- return status;
+ return new Status(status);
} else {
long now = -1;
@@ -290,15 +290,17 @@ public class Main {
IRubyObject status =
raisedException.callMethod(runtime.getCurrentContext(), "status");
if (status != null && !status.isNil()) {
- return RubyNumeric.fix2int(status);
+ return new Status(RubyNumeric.fix2int(status));
+ } else {
+ return new Status(0);
}
} else {
runtime.printError(raisedException);
- return 1;
+ return new Status(1);
}
}
}
- return 0;
+ return new Status();
}
private void showVersion() {
@@ -389,6 +391,32 @@ public class Main {
return result;
}
+ public static class Status {
+ private boolean isExit = false;
+ private int status = 0;
+
+ /**
+ * Creates a status object with the specified value and with explicit
+ * exit flag. An exit flag means that Kernel.exit() has been
explicitly
+ * invoked during the run.
+ *
+ * @param status
+ * The status value.
+ */
+ Status(int status) {
+ this.isExit = true;
+ this.status = status;
+ }
+
+ /**
+ * Creates a status object with 0 value and no explicit exit flag.
+ */
+ Status() {}
+
+ public boolean isExit() { return isExit; }
+ public int getStatus() { return status; }
+ }
+
protected boolean isShebangLine(String line) {
return (line.length() > 2 && line.charAt(0) == '#' && line.charAt(1)
== '!');
}
diff --git a/src/org/jruby/util/NailMain.java
b/src/org/jruby/util/NailMain.java
index 413dc20..a56f2c5 100644
--- a/src/org/jruby/util/NailMain.java
+++ b/src/org/jruby/util/NailMain.java
@@ -28,7 +28,7 @@ public class NailMain {
config.setCurrentDirectory(context.getWorkingDirectory());
config.setEnvironment(context.getEnv());
- return main.run();
+ return main.run().getStatus();
} catch (MainExitException mee) {
if (!mee.isAborted()) {
config.getOutput().println(mee.getMessage());
diff --git a/src/org/jruby/util/ShellLauncher.java
b/src/org/jruby/util/ShellLauncher.java
index 6381db8..a851985 100644
--- a/src/org/jruby/util/ShellLauncher.java
+++ b/src/org/jruby/util/ShellLauncher.java
@@ -132,7 +132,7 @@ public class ShellLauncher {
}
public void run() {
try {
- this.result = new Main(config).run(argArray);
+ this.result = (new Main(config).run(argArray)).getStatus();
} catch (Throwable throwable) {
throwable.printStackTrace(this.config.getError());
this.result = -1;
|
[jruby~main:9d5480d7] JRUBY-1650: "exit 0" not causing expected behaviour |
nicksieger | 03/09/2010 |





