|
From: <cr...@us...> - 2009-06-11 13:41:55
|
Revision: 5567
http://jnode.svn.sourceforge.net/jnode/?rev=5567&view=rev
Author: crawley
Date: 2009-06-11 12:45:24 +0000 (Thu, 11 Jun 2009)
Log Message:
-----------
Bjorne now handles unknown command names w/o printing an exception and
exiting the current script. No we just get a one line error message on
the current stderr and rc set to 1.
Modified Paths:
--------------
trunk/shell/src/shell/org/jnode/shell/CommandInfo.java
trunk/shell/src/shell/org/jnode/shell/CommandShell.java
trunk/shell/src/shell/org/jnode/shell/DefaultInterpreter.java
trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneBuiltin.java
trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneInterpreter.java
trunk/shell/src/shell/org/jnode/shell/bjorne/SimpleCommandNode.java
trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-builtin-tests.xml
trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml
Modified: trunk/shell/src/shell/org/jnode/shell/CommandInfo.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/CommandInfo.java 2009-06-09 14:04:19 UTC (rev 5566)
+++ trunk/shell/src/shell/org/jnode/shell/CommandInfo.java 2009-06-11 12:45:24 UTC (rev 5567)
@@ -218,9 +218,9 @@
bundle.parse(cmdLine, syntaxBundle);
}
} catch (InstantiationException ex) {
- throw new ShellException("Command class cannot be instantiated", ex);
+ throw new ShellInvocationException("Command class cannot be instantiated", ex);
} catch (IllegalAccessException ex) {
- throw new ShellException("Command class cannot be instantiated", ex);
+ throw new ShellInvocationException("Command class cannot be instantiated", ex);
}
}
}
Modified: trunk/shell/src/shell/org/jnode/shell/CommandShell.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/CommandShell.java 2009-06-09 14:04:19 UTC (rev 5566)
+++ trunk/shell/src/shell/org/jnode/shell/CommandShell.java 2009-06-11 12:45:24 UTC (rev 5567)
@@ -655,14 +655,14 @@
return new CommandInfo(cls, cmd, syntaxBundle, argBundle);
}
} catch (ClassNotFoundException ex) {
- throw new ShellException("Cannot load the command class for alias '" + cmd + "'", ex);
+ throw new ShellInvocationException("Cannot load the command class for alias '" + cmd + "'", ex);
} catch (NoSuchAliasException ex) {
try {
final ClassLoader cl =
Thread.currentThread().getContextClassLoader();
return new CommandInfo(cl.loadClass(cmd), cmd, syntaxBundle, false);
} catch (ClassNotFoundException ex2) {
- throw new ShellException(
+ throw new ShellInvocationException(
"Cannot find an alias or load a command class for '" + cmd + "'", ex);
}
}
@@ -900,7 +900,7 @@
}
return interpreter.interpret(this, file, alias, args);
} catch (IOException ex) {
- throw new ShellException("Cannot open command file: " + ex.getMessage(), ex);
+ throw new ShellInvocationException("Cannot open command file: " + ex.getMessage(), ex);
} finally {
setHistoryEnabled(enabled);
}
@@ -918,7 +918,7 @@
try {
InputStream input = getClass().getResourceAsStream(resourceName);
if (input == null) {
- throw new ShellException("Cannot find resource '" + resourceName + "'");
+ throw new ShellInvocationException("Cannot find resource '" + resourceName + "'");
}
CommandInterpreter interpreter = createInterpreter(new InputStreamReader(input));
Reader reader = new InputStreamReader(getClass().getResourceAsStream(resourceName));
Modified: trunk/shell/src/shell/org/jnode/shell/DefaultInterpreter.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/DefaultInterpreter.java 2009-06-09 14:04:19 UTC (rev 5566)
+++ trunk/shell/src/shell/org/jnode/shell/DefaultInterpreter.java 2009-06-11 12:45:24 UTC (rev 5567)
@@ -114,7 +114,7 @@
public int interpret(CommandShell shell, Reader reader, String alias, String[] args)
throws ShellException {
if (args != null && args.length > 0) {
- throw new ShellException(
+ throw new ShellInvocationException(
"The " + getName() + " interpreter does not support script file arguments");
}
try {
@@ -130,7 +130,7 @@
}
return rc;
} catch (IOException ex) {
- throw new ShellException("Problem reading command file: " + ex.getMessage(), ex);
+ throw new ShellInvocationException("Problem reading command file: " + ex.getMessage(), ex);
} finally {
if (reader != null) {
try {
@@ -161,7 +161,7 @@
try {
return interpret(shell, new FileReader(file), alias, args);
} catch (FileNotFoundException ex) {
- throw new ShellException("Problem reading command file: " + ex.getMessage(), ex);
+ throw new ShellInvocationException("Problem reading command file: " + ex.getMessage(), ex);
}
}
Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneBuiltin.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneBuiltin.java 2009-06-09 14:04:19 UTC (rev 5566)
+++ trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneBuiltin.java 2009-06-11 12:45:24 UTC (rev 5567)
@@ -24,6 +24,7 @@
import org.jnode.shell.Command;
import org.jnode.shell.CommandLine;
import org.jnode.shell.ShellException;
+import org.jnode.shell.ShellInvocationException;
import org.jnode.vm.VmExit;
/**
@@ -64,7 +65,7 @@
} catch (VmExit ex) {
return ex.getStatus();
} catch (Exception ex) {
- throw new ShellException("Exception in bjorne builtin", ex);
+ throw new ShellInvocationException("Exception in bjorne builtin", ex);
}
return 0;
}
Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneInterpreter.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneInterpreter.java 2009-06-09 14:04:19 UTC (rev 5566)
+++ trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneInterpreter.java 2009-06-11 12:45:24 UTC (rev 5567)
@@ -51,6 +51,7 @@
import org.jnode.shell.IncompleteCommandException;
import org.jnode.shell.ShellException;
import org.jnode.shell.ShellFailureException;
+import org.jnode.shell.ShellInvocationException;
import org.jnode.shell.ShellSyntaxException;
import org.jnode.shell.io.CommandIO;
import org.jnode.shell.io.CommandOutput;
@@ -288,7 +289,7 @@
}
return rc;
} catch (IOException ex) {
- throw new ShellException("Problem reading command file: " + ex.getMessage(), ex);
+ throw new ShellInvocationException("Problem reading command file: " + ex.getMessage(), ex);
} finally {
if (reader != null) {
try {
@@ -305,7 +306,7 @@
try {
return interpret(shell, new FileReader(file), alias, args);
} catch (FileNotFoundException ex) {
- throw new ShellException("Problem reading command file: " + ex.getMessage(), ex);
+ throw new ShellInvocationException("Problem reading command file: " + ex.getMessage(), ex);
}
}
Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/SimpleCommandNode.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/bjorne/SimpleCommandNode.java 2009-06-09 14:04:19 UTC (rev 5566)
+++ trunk/shell/src/shell/org/jnode/shell/bjorne/SimpleCommandNode.java 2009-06-11 12:45:24 UTC (rev 5567)
@@ -26,6 +26,7 @@
import org.jnode.shell.CommandThread;
import org.jnode.shell.ShellException;
import org.jnode.shell.ShellFailureException;
+import org.jnode.shell.ShellInvocationException;
import org.jnode.shell.help.CompletionException;
import org.jnode.shell.io.CommandIO;
import org.jnode.shell.io.CommandIOHolder;
@@ -111,6 +112,9 @@
rc = childContext.execute(command, ios, builtin);
}
}
+ } catch (ShellInvocationException ex) {
+ context.getShell().resolvePrintStream(context.getIO(2)).println(ex.getMessage());
+ rc = 1;
} finally {
if (holders != null) {
for (CommandIOHolder holder : holders) {
Modified: trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-builtin-tests.xml
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-builtin-tests.xml 2009-06-09 14:04:19 UTC (rev 5566)
+++ trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-builtin-tests.xml 2009-06-11 12:45:24 UTC (rev 5567)
@@ -74,8 +74,7 @@
<output>fred='ls'
</output>
</testSpec>
- <testSpec title="builtins recognized early" command="test"
- runMode="AS_SCRIPT" rc="0" trapException="org.jnode.shell.ShellException">
+ <testSpec title="builtins recognized early" command="test" runMode="AS_SCRIPT" rc="0">
<script>#!bjorne
alias fred=ls
alias
@@ -90,6 +89,9 @@
<output>fred='ls'
done
fred='dir'
+done
</output>
+ <error>Cannot find an alias or load a command class for 'unalias'
+</error>
</testSpec>
</testSet>
\ No newline at end of file
Modified: trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml 2009-06-09 14:04:19 UTC (rev 5566)
+++ trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml 2009-06-11 12:45:24 UTC (rev 5567)
@@ -902,4 +902,14 @@
0
</file>
</testSpec>
+ <testSpec title="unknown command" command="test" runMode="AS_SCRIPT" rc="0">
+ <script>#!bjorne
+ foo
+ echo hi
+ </script>
+ <output >hi
+</output>
+ <error>Cannot find an alias or load a command class for 'foo'
+</error>
+ </testSpec>
</testSet>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|