From: <ls...@us...> - 2007-10-20 10:29:41
|
Revision: 3561 http://jnode.svn.sourceforge.net/jnode/?rev=3561&view=rev Author: lsantha Date: 2007-10-20 03:29:35 -0700 (Sat, 20 Oct 2007) Log Message: ----------- Extensions to the command shell by crawley. Modified Paths: -------------- trunk/fs/descriptors/org.jnode.fs.command.xml trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java trunk/shell/descriptors/org.jnode.shell.command.driver.console.xml trunk/shell/src/shell/org/jnode/shell/ShellException.java trunk/shell/src/shell/org/jnode/shell/help/Argument.java trunk/shell/src/shell/org/jnode/shell/help/CompletionException.java trunk/shell/src/shell/org/jnode/shell/help/HelpException.java trunk/shell/src/shell/org/jnode/shell/help/argument/FileArgument.java trunk/shell/src/shell/org/jnode/shell/proclet/ProcletContext.java trunk/shell/src/shell/org/jnode/shell/proclet/ProcletProxyPrintStream.java Added Paths: ----------- trunk/shell/src/shell/org/jnode/shell/CommandInterpreter.java trunk/shell/src/shell/org/jnode/shell/CommandThread.java trunk/shell/src/shell/org/jnode/shell/Completable.java trunk/shell/src/shell/org/jnode/shell/NullInputStream.java trunk/shell/src/shell/org/jnode/shell/NullOutputStream.java trunk/shell/src/shell/org/jnode/shell/ShellFailureException.java trunk/shell/src/shell/org/jnode/shell/ShellInvocationException.java trunk/shell/src/shell/org/jnode/shell/ShellSyntaxException.java trunk/shell/src/shell/org/jnode/shell/ThreadExitListener.java Modified: trunk/fs/descriptors/org.jnode.fs.command.xml =================================================================== --- trunk/fs/descriptors/org.jnode.fs.command.xml 2007-10-20 08:19:21 UTC (rev 3560) +++ trunk/fs/descriptors/org.jnode.fs.command.xml 2007-10-20 10:29:35 UTC (rev 3561) @@ -41,6 +41,7 @@ <permission class="java.util.PropertyPermission" name="*" actions="read,write"/> <permission class="java.net.NetPermission" name="specifyStreamHandler"/> <permission class="java.lang.RuntimePermission" name="modifyThreadGroup"/> + <permission class="java.lang.RuntimePermission" name="exitVM"/> </extension> </plugin> Modified: trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java 2007-10-20 08:19:21 UTC (rev 3560) +++ trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -108,14 +108,17 @@ } } } - out.flush(); + if (out.checkError()) { + ok = false; + } } catch (IOException ex) { // Deal with i/o errors reading from in/is or writing to out. err.println("Problem concatenating file(s): " + ex.getMessage()); ok = false; } - // TODO need to set a 'return code'; e.g. - // if (!ok) { System.exit(1); } + if (!ok) { + System.exit(1); + } } /** Modified: trunk/shell/descriptors/org.jnode.shell.command.driver.console.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.driver.console.xml 2007-10-20 08:19:21 UTC (rev 3560) +++ trunk/shell/descriptors/org.jnode.shell.command.driver.console.xml 2007-10-20 10:29:35 UTC (rev 3561) @@ -29,9 +29,6 @@ <permission class="java.lang.RuntimePermission" name="setIO"/> <permission class="java.net.SocketPermission" name="*" actions="resolve,listen,connect"/> <permission class="java.net.SocketPermission" name="*:0-" actions="connect,resolve,listen"/> - <permission class="java.util.PropertyPermission" name="jnode.cmdline" actions="read"/> - <permission class="java.util.PropertyPermission" name="jnode.invoker" actions="read"/> - <permission class="java.util.PropertyPermission" name="jnode.prompt" actions="read,write"/> - <permission class="java.util.PropertyPermission" name="user.dir" actions="read"/> + <permission class="java.util.PropertyPermission" name="*" actions="read,write"/> </extension> </plugin> \ No newline at end of file Added: trunk/shell/src/shell/org/jnode/shell/CommandInterpreter.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/CommandInterpreter.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/CommandInterpreter.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -0,0 +1,56 @@ +/* + * $Id: ThreadCommandInvoker.java 3374 2007-08-02 18:15:27Z lsantha $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.shell; + +/** + * This is the API that a shell-based interpreter must implement. + * + * @author cr...@jn... + */ +public interface CommandInterpreter { + /** + * Parse and execute a command line, and return the resulting return code. + * + * @param shell the CommandShell that provides low-level command invocation, + * command history and so on. + * @param line the line of input to be interpreted. + * @return the return code. + * @throws ShellException + */ + int interpret(CommandShell shell, String line) throws ShellException; + + /** + * Parse a partial command line, returning the command line fragment to be completed. + * + * @param shell the current CommandShell. + * @param partial a input to the interpreter. + * @return the CommandLine represent the fragment of the supplied command input to be completed. + * @throws ShellException + */ + Completable parsePartial(CommandShell shell, String partial) throws ShellSyntaxException; + + /** + * Get the interpreter's name + * @return the name + */ + String getName(); +} Added: trunk/shell/src/shell/org/jnode/shell/CommandThread.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/CommandThread.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/CommandThread.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -0,0 +1,94 @@ +/* + * $Id: ThreadCommandInvoker.java 3374 2007-08-02 18:15:27Z lsantha $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.shell; + +/** + * The CommandThread class enhances Thread with a simple mechanism for recording + * a 'command's return code. + * + * @author cr...@jn... + */ +public class CommandThread extends Thread { + + private int rc; + private ThreadExitListener listener; + + /** + * @param group the parent group for the thread + * @param target the runnable that implements the command + * @param name a thread name + * @param size the threads stack size + * @param invoker the invoker to be notified of the thread's exit + */ + public CommandThread(ThreadGroup group, Runnable target, String name, long size) { + super(group, target, name, size); + } + + /** + * @param group the parent group for the thread + * @param target the runnable that implements the command + * @param invoker the invoker to be notified of the thread's exit + */ + public CommandThread(ThreadGroup group, Runnable target) { + super(group, target); + } + + /** + * @param target the runnable that implements the command + * @param name a thread name + * @param invoker the invoker to be notified of the thread's exit + */ + public CommandThread(Runnable target, String name) { + super(target, name); + } + + @Override + public void run() { + super.run(); + if (listener != null) { + listener.notifyThreadExitted(this); + } + } + + /** + * This overload for start registers an optional thread exit listener + * to be notified of the thread's exit + * + * @param listener the listener or <code>null</code> + */ + public void start(ThreadExitListener listener) { + this.listener = listener; + super.start(); + } + + public final int getReturnCode() { + return rc; + } + + public final void setReturnCode(int rc) { + this.rc = rc; + } + + public static final void setRC(int rc) throws ClassCastException { + ((CommandThread) Thread.currentThread()).setReturnCode(rc); + } +} Added: trunk/shell/src/shell/org/jnode/shell/Completable.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/Completable.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/Completable.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -0,0 +1,10 @@ +package org.jnode.shell; + +import org.jnode.driver.console.CompletionInfo; +import org.jnode.shell.help.CompletionException; + +public interface Completable { + + void complete(CompletionInfo completion, CommandShell shell) throws CompletionException; + +} Added: trunk/shell/src/shell/org/jnode/shell/NullInputStream.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/NullInputStream.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/NullInputStream.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -0,0 +1,12 @@ +package org.jnode.shell; + +import java.io.IOException; +import java.io.InputStream; + +public class NullInputStream extends InputStream { + + @Override + public int read() throws IOException { + return 0; + } +} Added: trunk/shell/src/shell/org/jnode/shell/NullOutputStream.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/NullOutputStream.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/NullOutputStream.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -0,0 +1,13 @@ +package org.jnode.shell; + +import java.io.IOException; +import java.io.OutputStream; + +public class NullOutputStream extends OutputStream { + + @Override + public void write(int b) throws IOException { + // black-hole all output. + } + +} Modified: trunk/shell/src/shell/org/jnode/shell/ShellException.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/ShellException.java 2007-10-20 08:19:21 UTC (rev 3560) +++ trunk/shell/src/shell/org/jnode/shell/ShellException.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -29,6 +29,11 @@ /** * */ + private static final long serialVersionUID = 1L; + + /** + * + */ public ShellException() { super(); } Added: trunk/shell/src/shell/org/jnode/shell/ShellFailureException.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/ShellFailureException.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/ShellFailureException.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -0,0 +1,48 @@ +/* + * $Id: ShellException.java 2224 2006-01-01 12:49:03Z epr $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.shell; + +/** + * This exception is used to signal an internal error in the + * command shell, interpretter or invoker. + * + * @author cr...@jn... + */ +public class ShellFailureException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + /** + * @param message + * @param cause + */ + public ShellFailureException(String message, Throwable cause) { + super(message, cause); + } + + /** + * @param s + */ + public ShellFailureException(String s) { + super(s); + } +} Added: trunk/shell/src/shell/org/jnode/shell/ShellInvocationException.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/ShellInvocationException.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/ShellInvocationException.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -0,0 +1,19 @@ +package org.jnode.shell; + +public class ShellInvocationException extends ShellException { + + private static final long serialVersionUID = 1L; + + public ShellInvocationException(String s, Throwable cause) { + super(s, cause); + } + + public ShellInvocationException(String s) { + super(s); + } + + public ShellInvocationException(Throwable cause) { + super(cause); + } + +} Added: trunk/shell/src/shell/org/jnode/shell/ShellSyntaxException.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/ShellSyntaxException.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/ShellSyntaxException.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -0,0 +1,19 @@ +package org.jnode.shell; + +public class ShellSyntaxException extends ShellException { + + private static final long serialVersionUID = 1L; + + public ShellSyntaxException(String s, Throwable cause) { + super(s, cause); + } + + public ShellSyntaxException(String s) { + super(s); + } + + public ShellSyntaxException(Throwable cause) { + super(cause); + } + +} Added: trunk/shell/src/shell/org/jnode/shell/ThreadExitListener.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/ThreadExitListener.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/ThreadExitListener.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -0,0 +1,7 @@ +package org.jnode.shell; + +public interface ThreadExitListener { + + void notifyThreadExitted(CommandThread thread); + +} Modified: trunk/shell/src/shell/org/jnode/shell/help/Argument.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/help/Argument.java 2007-10-20 08:19:21 UTC (rev 3560) +++ trunk/shell/src/shell/org/jnode/shell/help/Argument.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -25,6 +25,7 @@ import javax.naming.NameNotFoundException; +import org.jnode.shell.CommandLine; import org.jnode.shell.ShellUtils; /** Modified: trunk/shell/src/shell/org/jnode/shell/help/CompletionException.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/help/CompletionException.java 2007-10-20 08:19:21 UTC (rev 3560) +++ trunk/shell/src/shell/org/jnode/shell/help/CompletionException.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -28,4 +28,8 @@ public CompletionException(String message) { super(message); } + + public CompletionException(String message, Throwable cause) { + super(message, cause); + } } Modified: trunk/shell/src/shell/org/jnode/shell/help/HelpException.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/help/HelpException.java 2007-10-20 08:19:21 UTC (rev 3560) +++ trunk/shell/src/shell/org/jnode/shell/help/HelpException.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -28,7 +28,12 @@ HelpException() { super(); } + HelpException(String message) { super(message); } + + public HelpException(String message, Throwable cause) { + super(message, cause); + } } Modified: trunk/shell/src/shell/org/jnode/shell/help/argument/FileArgument.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/help/argument/FileArgument.java 2007-10-20 08:19:21 UTC (rev 3560) +++ trunk/shell/src/shell/org/jnode/shell/help/argument/FileArgument.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -114,7 +114,14 @@ list.add(name); } } - return complete(partial, list); + String completed = complete(partial, list); + if (completed.endsWith(" ")) { + String path = completed.substring(0, completed.length() - 1); + if (new File(path).isDirectory()) { + completed = path + File.separatorChar; + } + } + return completed; } } } Modified: trunk/shell/src/shell/org/jnode/shell/proclet/ProcletContext.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/proclet/ProcletContext.java 2007-10-20 08:19:21 UTC (rev 3560) +++ trunk/shell/src/shell/org/jnode/shell/proclet/ProcletContext.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -6,6 +6,8 @@ import java.util.HashMap; import java.util.Map; import java.util.Properties; + +import org.jnode.shell.CommandThread; import org.jnode.vm.VmSystem; import org.jnode.vm.VmExit; @@ -188,7 +190,7 @@ * @param target the new Thread's Runnable object. * @return the new Thread */ - public static Thread createProclet(Runnable target) { + public static CommandThread createProclet(Runnable target) { return createProclet(target, null, null, null, null, 0); } @@ -206,7 +208,7 @@ * @param target the new Thread's Runnable object. * @return the new Thread */ - public static Thread createProclet(Runnable target, Properties properties, + public static CommandThread createProclet(Runnable target, Properties properties, Map<String, String> environment, Object[] streams) { return createProclet(target, properties, environment, streams, null, 0); } @@ -227,7 +229,7 @@ * @param name an optional Thread name. * @return the new Thread */ - public static Thread createProclet(Runnable target, Properties properties, + public static CommandThread createProclet(Runnable target, Properties properties, Map<String, String> environment, Object[] streams, String name) { return createProclet(target, properties, environment, streams, name, 0); } @@ -249,7 +251,7 @@ * @param size the new Thread's stack size; zero denotes the default thread stack size. * @return the new Thread */ - public static Thread createProclet(Runnable target, Properties properties, + public static CommandThread createProclet(Runnable target, Properties properties, Map<String, String> environment, Object[] streams, String name, long size) { ProcletContext procletContext = @@ -258,7 +260,7 @@ if (name == null) { name = procletContext.autoThreadName(); } - return new Thread(procletContext, target, name, size); + return new CommandThread(procletContext, target, name, size); } /** Modified: trunk/shell/src/shell/org/jnode/shell/proclet/ProcletProxyPrintStream.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/proclet/ProcletProxyPrintStream.java 2007-10-20 08:19:21 UTC (rev 3560) +++ trunk/shell/src/shell/org/jnode/shell/proclet/ProcletProxyPrintStream.java 2007-10-20 10:29:35 UTC (rev 3561) @@ -68,7 +68,6 @@ return getRealStream(); } catch (ProxyStreamException ex) { - setError(); return getNullPrintStream(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |