|
From: <cr...@us...> - 2009-01-24 02:22:13
|
Revision: 4904
http://jnode.svn.sourceforge.net/jnode/?rev=4904&view=rev
Author: crawley
Date: 2009-01-24 02:16:41 +0000 (Sat, 24 Jan 2009)
Log Message:
-----------
Some incremental tidyups for the CommandShell and Shell APIs.
Modified Paths:
--------------
trunk/distr/src/apps/org/jnode/apps/charvabsh/CharvaBsh.java
trunk/shell/src/shell/org/jnode/shell/CommandLine.java
trunk/shell/src/shell/org/jnode/shell/CommandShell.java
trunk/shell/src/shell/org/jnode/shell/Shell.java
trunk/shell/src/shell/org/jnode/shell/command/HelpCommand.java
Modified: trunk/distr/src/apps/org/jnode/apps/charvabsh/CharvaBsh.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/charvabsh/CharvaBsh.java 2009-01-24 01:56:00 UTC (rev 4903)
+++ trunk/distr/src/apps/org/jnode/apps/charvabsh/CharvaBsh.java 2009-01-24 02:16:41 UTC (rev 4904)
@@ -420,7 +420,7 @@
if (shell instanceof CommandShell) {
CommandShell cs = (CommandShell) shell;
try {
- cs.invokeCommand(command);
+ cs.runCommand(command);
} catch (ShellException ex) {
System.err.println("Command invocation failed: " + ex.getMessage());
}
Modified: trunk/shell/src/shell/org/jnode/shell/CommandLine.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/CommandLine.java 2009-01-24 01:56:00 UTC (rev 4903)
+++ trunk/shell/src/shell/org/jnode/shell/CommandLine.java 2009-01-24 02:16:41 UTC (rev 4904)
@@ -573,7 +573,7 @@
* @throws CommandSyntaxException if the chosen syntax doesn't match the command
* line arguments.
*/
- public CommandInfo parseCommandLine(CommandShell shell) throws ShellException {
+ public CommandInfo parseCommandLine(Shell shell) throws ShellException {
String cmd = (commandToken == null) ? "" : commandToken.text.trim();
if (cmd.equals("")) {
throw new ShellFailureException("no command name");
@@ -595,8 +595,6 @@
bundle.parse(this, syntaxes);
}
return cmdInfo;
- } catch (ClassNotFoundException ex) {
- throw new ShellException("Command class not found", ex);
} catch (InstantiationException ex) {
throw new ShellException("Command class cannot be instantiated", ex);
} catch (IllegalAccessException ex) {
@@ -610,8 +608,8 @@
CommandInfo cmdClass;
try {
cmdClass = shell.getCommandInfo(cmd);
- } catch (ClassNotFoundException ex) {
- throw new CompletionException("Command class not found", ex);
+ } catch (ShellException ex) {
+ throw new CompletionException(ex.getMessage(), ex);
}
Command command;
@@ -652,15 +650,11 @@
}
}
- public CommandInfo getCommandInfo(CommandShell shell) {
+ public CommandInfo getCommandInfo(CommandShell shell) throws ShellException {
String cmd = (commandToken == null) ? "" : commandToken.text.trim();
if (cmd.equals("")) {
return null;
}
- try {
- return shell.getCommandInfo(cmd);
- } catch (ClassNotFoundException ex) {
- return null;
- }
+ return shell.getCommandInfo(cmd);
}
}
Modified: trunk/shell/src/shell/org/jnode/shell/CommandShell.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/CommandShell.java 2009-01-24 01:56:00 UTC (rev 4903)
+++ trunk/shell/src/shell/org/jnode/shell/CommandShell.java 2009-01-24 02:16:41 UTC (rev 4904)
@@ -280,7 +280,7 @@
if (e.startsWith(COMMAND_KEY)) {
final String cmd = e.substring(COMMAND_KEY.length());
outPW.println(prompt() + cmd);
- processCommand(cmd, false);
+ runCommand(cmd, false, this.interpreter);
}
} catch (Throwable ex) {
errPW.println("Error while processing bootarg commands: "
@@ -338,7 +338,7 @@
readingCommand = true;
String line = readInputLine().trim();
if (line.length() > 0) {
- processCommand(line, true);
+ runCommand(line, true, this.interpreter);
}
if (VmSystem.isShuttingDown()) {
@@ -464,12 +464,8 @@
((KeyboardReader) in).clearSoftEOF();
}
}
-
- protected int processCommand(String cmdLineStr, boolean interactive) {
- return processCommand(cmdLineStr, interactive, this.interpreter);
- }
- private int processCommand(String cmdLineStr, boolean interactive,
+ private int runCommand(String cmdLineStr, boolean interactive,
CommandInterpreter interpreter) {
if (interactive) {
clearEof();
@@ -536,8 +532,8 @@
* @param command the command line.
* @throws ShellException
*/
- public int invokeCommand(String command) throws ShellException {
- return processCommand(command, false);
+ public int runCommand(String command) throws ShellException {
+ return runCommand(command, false, this.interpreter);
}
/**
@@ -567,14 +563,20 @@
return this.invoker.invokeAsynchronous(cmdLine, cmdInfo);
}
- public CommandInfo getCommandInfo(String cmd) throws ClassNotFoundException {
+ public CommandInfo getCommandInfo(String cmd) throws ShellException {
try {
Class<?> cls = aliasMgr.getAliasClass(cmd);
return new CommandInfo(cls, aliasMgr.isInternal(cmd));
+ } catch (ClassNotFoundException ex) {
+ throw new ShellException("Cannot the load command class for alias '" + cmd + "'", ex);
} catch (NoSuchAliasException ex) {
- final ClassLoader cl =
- Thread.currentThread().getContextClassLoader();
- return new CommandInfo(cl.loadClass(cmd), false);
+ try {
+ final ClassLoader cl =
+ Thread.currentThread().getContextClassLoader();
+ return new CommandInfo(cl.loadClass(cmd), false);
+ } catch (ClassNotFoundException ex2) {
+ throw new ShellException("Cannot find an alias or load a command class for '" + cmd + "'", ex);
+ }
}
}
Modified: trunk/shell/src/shell/org/jnode/shell/Shell.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/Shell.java 2009-01-24 01:56:00 UTC (rev 4903)
+++ trunk/shell/src/shell/org/jnode/shell/Shell.java 2009-01-24 02:16:41 UTC (rev 4904)
@@ -75,4 +75,14 @@
*/
public int runCommandFile(File file) throws ShellException;
+ /**
+ * Resolve a command name to a CommandInfo object.
+ *
+ * @param commmandName this could be a command class name, an alias or some other
+ * supported by the shell.
+ * @return the resolved CommandInfo or <code>null</code>.
+ * @throws ShellException
+ */
+ public CommandInfo getCommandInfo(String commmandName) throws ShellException;
+
}
Modified: trunk/shell/src/shell/org/jnode/shell/command/HelpCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/HelpCommand.java 2009-01-24 01:56:00 UTC (rev 4903)
+++ trunk/shell/src/shell/org/jnode/shell/command/HelpCommand.java 2009-01-24 02:16:41 UTC (rev 4904)
@@ -29,6 +29,7 @@
import org.jnode.shell.CommandInfo;
import org.jnode.shell.CommandLine;
import org.jnode.shell.CommandShell;
+import org.jnode.shell.ShellException;
import org.jnode.shell.ShellUtils;
import org.jnode.shell.alias.AliasManager;
import org.jnode.shell.alias.NoSuchAliasException;
@@ -58,8 +59,7 @@
}
@Override
- public void execute() throws NameNotFoundException, ClassNotFoundException,
- HelpException, NoSuchAliasException {
+ public void execute() throws NameNotFoundException, ShellException, HelpException {
// The above exceptions are either bugs or configuration errors and should be allowed
// to propagate so that the shell can diagnose them appropriately.
String alias;
@@ -87,13 +87,8 @@
} catch (HelpException ex) {
err.println("Error getting help for alias / class '" + alias + "': " + ex.getMessage());
throw ex;
- } catch (ClassNotFoundException ex) {
- try {
- String className = shell.getAliasManager().getAliasClassName(alias);
- err.println("Cannot load class '" + className + "' for alias '" + alias + "'");
- } catch (NoSuchAliasException ex2) {
- err.println("'" + alias + "' is neither an alias or a loadable class name");
- }
+ } catch (ShellException ex) {
+ err.println(ex.getMessage());
throw ex;
} catch (SecurityException ex) {
err.println("Security exception while loading the class associated with alias '" + alias + "'");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|