From: <cr...@us...> - 2008-11-09 14:20:37
|
Revision: 4694 http://jnode.svn.sourceforge.net/jnode/?rev=4694&view=rev Author: crawley Date: 2008-11-09 14:20:31 +0000 (Sun, 09 Nov 2008) Log Message: ----------- Changing commands to use 'execute()' and PrintWriter were appropriate Modified Paths: -------------- trunk/all/conf/x86/menu-cdrom.lst trunk/shell/src/shell/org/jnode/shell/command/AliasCommand.java trunk/shell/src/shell/org/jnode/shell/command/ClassCommand.java trunk/shell/src/shell/org/jnode/shell/command/ClasspathCommand.java trunk/shell/src/shell/org/jnode/shell/command/CompileCommand.java trunk/shell/src/shell/org/jnode/shell/command/DateCommand.java trunk/shell/src/shell/org/jnode/shell/command/DisassembleCommand.java trunk/shell/src/shell/org/jnode/shell/command/EchoCommand.java trunk/shell/src/shell/org/jnode/shell/command/EnvCommand.java trunk/shell/src/shell/org/jnode/shell/command/ExitCommand.java trunk/shell/src/shell/org/jnode/shell/command/GcCommand.java trunk/shell/src/shell/org/jnode/shell/command/GrepCommand.java trunk/shell/src/shell/org/jnode/shell/command/HistoryCommand.java trunk/shell/src/shell/org/jnode/shell/command/IsolateCommand.java trunk/shell/src/shell/org/jnode/shell/command/test/SuiteCommand.java trunk/shell/src/shell/org/jnode/shell/command/test/TestCommand.java trunk/shell/src/shell/org/jnode/shell/command/unix/UnixTestCommand.java Modified: trunk/all/conf/x86/menu-cdrom.lst =================================================================== (Binary files differ) Modified: trunk/shell/src/shell/org/jnode/shell/command/AliasCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/AliasCommand.java 2008-11-09 13:57:29 UTC (rev 4693) +++ trunk/shell/src/shell/org/jnode/shell/command/AliasCommand.java 2008-11-09 14:20:31 UTC (rev 4694) @@ -21,13 +21,11 @@ package org.jnode.shell.command; -import java.io.InputStream; -import java.io.PrintStream; +import java.io.PrintWriter; import java.util.Map; import java.util.TreeMap; import org.jnode.shell.AbstractCommand; -import org.jnode.shell.CommandLine; import org.jnode.shell.ShellUtils; import org.jnode.shell.alias.AliasManager; import org.jnode.shell.alias.NoSuchAliasException; @@ -63,8 +61,7 @@ new AliasCommand().execute(args); } - public void execute(CommandLine commandLine, InputStream in, - PrintStream out, PrintStream err) throws Exception { + public void execute() throws Exception { final AliasManager aliasMgr = ShellUtils.getCurrentAliasManager(); if (ARG_REMOVE.isSet()) { @@ -86,11 +83,11 @@ aliasMgr.add(ARG_ALIAS.getValue(), className); } else { // list the aliases - showAliases(aliasMgr, out); + showAliases(aliasMgr, getOutput().getPrintWriter()); } } - private void showAliases(AliasManager aliasMgr, PrintStream out) throws NoSuchAliasException { + private void showAliases(AliasManager aliasMgr, PrintWriter out) throws NoSuchAliasException { final TreeMap<String, String> map = new TreeMap<String, String>(); for (String alias : aliasMgr.aliases()) { Modified: trunk/shell/src/shell/org/jnode/shell/command/ClassCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/ClassCommand.java 2008-11-09 13:57:29 UTC (rev 4693) +++ trunk/shell/src/shell/org/jnode/shell/command/ClassCommand.java 2008-11-09 14:20:31 UTC (rev 4694) @@ -21,13 +21,11 @@ package org.jnode.shell.command; -import java.io.InputStream; -import java.io.PrintStream; +import java.io.PrintWriter; import java.security.AccessController; import java.security.PrivilegedAction; import org.jnode.shell.AbstractCommand; -import org.jnode.shell.CommandLine; import org.jnode.shell.syntax.Argument; import org.jnode.shell.syntax.ClassNameArgument; import org.jnode.vm.classmgr.VmArrayClass; @@ -49,15 +47,14 @@ registerArguments(ARG_CLASS); } - public void execute(CommandLine commandLine, InputStream in, - PrintStream out, PrintStream err) throws Exception { + public void execute() throws Exception { String className = ARG_CLASS.getValue(); final ClassLoader cl = Thread.currentThread().getContextClassLoader(); try { final Class<?> type = cl.loadClass(className); - showClass(type, out); + showClass(type, getOutput().getPrintWriter()); } catch (ClassNotFoundException ex) { - err.println("Cannot find the requested class: " + className); + getError().getPrintWriter().println("Cannot find the requested class: " + className); exit(1); } } @@ -66,7 +63,7 @@ new ClassCommand().execute(args); } - private void showClass(final Class<?> type, final PrintStream out) { + private void showClass(final Class<?> type, final PrintWriter out) { final VmType<?> vmType = AccessController.doPrivileged( new PrivilegedAction<VmType<?>>() { public VmType<?> run() { Modified: trunk/shell/src/shell/org/jnode/shell/command/ClasspathCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/ClasspathCommand.java 2008-11-09 13:57:29 UTC (rev 4693) +++ trunk/shell/src/shell/org/jnode/shell/command/ClasspathCommand.java 2008-11-09 14:20:31 UTC (rev 4694) @@ -21,13 +21,11 @@ package org.jnode.shell.command; -import java.io.InputStream; -import java.io.PrintStream; +import java.io.PrintWriter; import java.net.URL; import java.net.URLClassLoader; import org.jnode.shell.AbstractCommand; -import org.jnode.shell.CommandLine; import org.jnode.shell.syntax.Argument; import org.jnode.shell.syntax.FlagArgument; import org.jnode.shell.syntax.URLArgument; @@ -58,8 +56,7 @@ } @Override - public void execute(CommandLine commandLine, InputStream in, - PrintStream out, PrintStream err) throws Exception { + public void execute() throws Exception { if (ARG_ADD.isSet()) { addToClassPath(ARG_ADD.getValue()); } else if (ARG_CLEAR.isSet()) { @@ -67,7 +64,7 @@ } else if (ARG_REFRESH.isSet()) { refreshClassPath(); } else { - printClassPath(out); + printClassPath(getOutput().getPrintWriter()); } } @@ -101,7 +98,7 @@ } } - private void printClassPath(PrintStream out) { + private void printClassPath(PrintWriter out) { getClassLoader().print(out); } @@ -128,7 +125,7 @@ addURL(url); } - public void print(PrintStream out) { + public void print(PrintWriter out) { URL[] urls = getURLs(); for (int i = 0; i < urls.length; i++) { out.println(urls[i]); Modified: trunk/shell/src/shell/org/jnode/shell/command/CompileCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/CompileCommand.java 2008-11-09 13:57:29 UTC (rev 4693) +++ trunk/shell/src/shell/org/jnode/shell/command/CompileCommand.java 2008-11-09 14:20:31 UTC (rev 4694) @@ -21,11 +21,9 @@ package org.jnode.shell.command; -import java.io.InputStream; -import java.io.PrintStream; +import java.io.PrintWriter; import org.jnode.shell.AbstractCommand; -import org.jnode.shell.CommandLine; import org.jnode.shell.syntax.Argument; import org.jnode.shell.syntax.ClassNameArgument; import org.jnode.shell.syntax.FlagArgument; @@ -61,12 +59,12 @@ } @Override - public void execute(CommandLine commandLine, InputStream in, - PrintStream out, PrintStream err) throws Exception { + public void execute() throws Exception { final String className = ARG_CLASS.getValue(); final int level = ARG_LEVEL.isSet() ? ARG_LEVEL.getValue() : 0; final boolean test = ARG_TEST.isSet(); - + PrintWriter out = getOutput().getPrintWriter(); + PrintWriter err = getError().getPrintWriter(); if (test) { if (maxTestLevel == -1) { err.println("No test compilers are currently registered"); Modified: trunk/shell/src/shell/org/jnode/shell/command/DateCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/DateCommand.java 2008-11-09 13:57:29 UTC (rev 4693) +++ trunk/shell/src/shell/org/jnode/shell/command/DateCommand.java 2008-11-09 14:20:31 UTC (rev 4694) @@ -21,12 +21,9 @@ package org.jnode.shell.command; -import java.io.InputStream; -import java.io.PrintStream; import java.util.Date; import org.jnode.shell.AbstractCommand; -import org.jnode.shell.CommandLine; /** * A shell command to access the display the system date. @@ -40,9 +37,8 @@ } @Override - public void execute(CommandLine commandLine, InputStream in, - PrintStream out, PrintStream err) throws Exception { - out.println(new Date()); + public void execute() throws Exception { + getOutput().getPrintWriter().println(new Date()); } /** Modified: trunk/shell/src/shell/org/jnode/shell/command/DisassembleCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/DisassembleCommand.java 2008-11-09 13:57:29 UTC (rev 4693) +++ trunk/shell/src/shell/org/jnode/shell/command/DisassembleCommand.java 2008-11-09 14:20:31 UTC (rev 4694) @@ -21,12 +21,9 @@ package org.jnode.shell.command; -import java.io.InputStream; -import java.io.OutputStreamWriter; -import java.io.PrintStream; +import java.io.PrintWriter; import org.jnode.shell.AbstractCommand; -import org.jnode.shell.CommandLine; import org.jnode.shell.syntax.Argument; import org.jnode.shell.syntax.ClassNameArgument; import org.jnode.shell.syntax.FlagArgument; @@ -65,8 +62,9 @@ } @Override - public void execute(CommandLine commandLine, InputStream in, - PrintStream out, PrintStream err) throws Exception { + public void execute() throws Exception { + final PrintWriter out = getOutput().getPrintWriter(); + final PrintWriter err = getError().getPrintWriter(); final String className = ARG_CLASS.getValue(); final String methodName = ARG_METHOD.isSet() ? ARG_METHOD.getValue() : null; final int level = ARG_LEVEL.isSet() ? ARG_LEVEL.getValue() : 0; @@ -96,7 +94,7 @@ exit(1); } final long start = System.currentTimeMillis(); - final int count = type.disassemble(methodName, level, test, new OutputStreamWriter(out)); + final int count = type.disassemble(methodName, level, test, out); final long end = System.currentTimeMillis(); out.println("Disassembling " + count + " methods took " + (end - start) + "ms"); } Modified: trunk/shell/src/shell/org/jnode/shell/command/EchoCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/EchoCommand.java 2008-11-09 13:57:29 UTC (rev 4693) +++ trunk/shell/src/shell/org/jnode/shell/command/EchoCommand.java 2008-11-09 14:20:31 UTC (rev 4694) @@ -21,11 +21,9 @@ package org.jnode.shell.command; -import java.io.InputStream; -import java.io.PrintStream; +import java.io.PrintWriter; import org.jnode.shell.AbstractCommand; -import org.jnode.shell.CommandLine; import org.jnode.shell.syntax.Argument; import org.jnode.shell.syntax.StringArgument; @@ -37,7 +35,8 @@ */ public class EchoCommand extends AbstractCommand { - private final StringArgument ARG_WORDS = new StringArgument("text", Argument.MULTIPLE, "the text to be printed"); + private final StringArgument ARG_WORDS = + new StringArgument("text", Argument.MULTIPLE, "the text to be printed"); public EchoCommand() { super("Print the argument text to standard output"); @@ -51,8 +50,8 @@ /** * Execute the command */ - public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) - throws Exception { + public void execute() throws Exception { + final PrintWriter out = getOutput().getPrintWriter(); String[] words = ARG_WORDS.getValues(); for (int i = 0; i < words.length; i++) { if (i > 0) { Modified: trunk/shell/src/shell/org/jnode/shell/command/EnvCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/EnvCommand.java 2008-11-09 13:57:29 UTC (rev 4693) +++ trunk/shell/src/shell/org/jnode/shell/command/EnvCommand.java 2008-11-09 14:20:31 UTC (rev 4694) @@ -23,15 +23,13 @@ import gnu.java.security.action.GetPropertiesAction; -import java.io.InputStream; -import java.io.PrintStream; +import java.io.PrintWriter; import java.security.AccessController; import java.util.Map; import java.util.Properties; import java.util.TreeMap; import org.jnode.shell.AbstractCommand; -import org.jnode.shell.CommandLine; /** * @author epr @@ -49,14 +47,13 @@ /** * Execute this command */ - public void execute(CommandLine cmdLine, InputStream in, PrintStream out, PrintStream err) - throws Exception { + public void execute() throws Exception { final Properties ps = (Properties) AccessController.doPrivileged(new GetPropertiesAction()); final TreeMap<Object, Object> sortedPs = new TreeMap<Object, Object>(ps); + final PrintWriter out = getOutput().getPrintWriter(); for (Map.Entry<Object, Object> entry : sortedPs.entrySet()) { final String key = entry.getKey().toString(); final String value = entry.getValue().toString(); - out.println(key + '=' + value); } } Modified: trunk/shell/src/shell/org/jnode/shell/command/ExitCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/ExitCommand.java 2008-11-09 13:57:29 UTC (rev 4693) +++ trunk/shell/src/shell/org/jnode/shell/command/ExitCommand.java 2008-11-09 14:20:31 UTC (rev 4694) @@ -1,11 +1,7 @@ package org.jnode.shell.command; -import java.io.InputStream; -import java.io.PrintStream; - import org.jnode.naming.InitialNaming; import org.jnode.shell.AbstractCommand; -import org.jnode.shell.CommandLine; import org.jnode.shell.CommandShell; import org.jnode.shell.ShellManager; @@ -25,8 +21,7 @@ /** * Execute this command */ - public void execute(CommandLine cmdLine, - InputStream in, PrintStream out, PrintStream err) throws Exception { + public void execute() throws Exception { ShellManager sm = InitialNaming.lookup(ShellManager.NAME); ((CommandShell) sm.getCurrentShell()).exit(); } Modified: trunk/shell/src/shell/org/jnode/shell/command/GcCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/GcCommand.java 2008-11-09 13:57:29 UTC (rev 4693) +++ trunk/shell/src/shell/org/jnode/shell/command/GcCommand.java 2008-11-09 14:20:31 UTC (rev 4694) @@ -23,6 +23,7 @@ import java.io.InputStream; import java.io.PrintStream; +import java.io.PrintWriter; import org.jnode.shell.AbstractCommand; import org.jnode.shell.CommandLine; @@ -86,8 +87,8 @@ /** * Execute this command */ - public void execute(CommandLine cmdLine, InputStream in, PrintStream out, PrintStream err) - throws Exception { + public void execute() throws Exception { + final PrintWriter out = getOutput().getPrintWriter(); if (ARG_SET.isSet()) { Vm.getHeapManager().setHeapFlags(getFlags()); } else if (ARG_CLEAR.isSet()) { @@ -114,7 +115,7 @@ } } - private void showFlags(int flags, PrintStream out) { + private void showFlags(int flags, PrintWriter out) { StringBuilder sb = new StringBuilder(); for (int flagBitMask = 1; flagBitMask != 0; flagBitMask = flagBitMask << 1) { if ((flags & flagBitMask) != 0) { Modified: trunk/shell/src/shell/org/jnode/shell/command/GrepCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/GrepCommand.java 2008-11-09 13:57:29 UTC (rev 4693) +++ trunk/shell/src/shell/org/jnode/shell/command/GrepCommand.java 2008-11-09 14:20:31 UTC (rev 4694) @@ -21,14 +21,11 @@ package org.jnode.shell.command; import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.PrintStream; +import java.io.PrintWriter; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; import org.jnode.shell.AbstractCommand; -import org.jnode.shell.CommandLine; import org.jnode.shell.syntax.Argument; import org.jnode.shell.syntax.FlagArgument; import org.jnode.shell.syntax.StringArgument; @@ -63,8 +60,7 @@ /** * Primary entry point */ - public void execute(CommandLine commandLine, InputStream in, - PrintStream out, PrintStream err) throws Exception { + public void execute() throws Exception { boolean inverse = FLAG_INVERSE.isSet(); boolean useRegex = FLAG_REGEX.isSet(); @@ -81,15 +77,16 @@ pattern = Pattern.compile(Pattern.quote(expr)); } } catch (PatternSyntaxException ex) { - err.println("Invalid regex: " + ex.getMessage()); + getError().getPrintWriter().println("Invalid regex: " + ex.getMessage()); exit(2); } - final BufferedReader r = new BufferedReader(new InputStreamReader(in)); + final BufferedReader r = new BufferedReader(getInput().getReader()); // Read the input a line at a time, searching each line for the expression. boolean found = false; String line; + PrintWriter out = getOutput().getPrintWriter(); while ((line = r.readLine()) != null) { if (pattern.matcher(line).find()) { if (!inverse) { Modified: trunk/shell/src/shell/org/jnode/shell/command/HistoryCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/HistoryCommand.java 2008-11-09 13:57:29 UTC (rev 4693) +++ trunk/shell/src/shell/org/jnode/shell/command/HistoryCommand.java 2008-11-09 14:20:31 UTC (rev 4694) @@ -20,12 +20,10 @@ */ package org.jnode.shell.command; -import java.io.InputStream; -import java.io.PrintStream; +import java.io.PrintWriter; import org.jnode.driver.console.InputHistory; import org.jnode.shell.AbstractCommand; -import org.jnode.shell.CommandLine; import org.jnode.shell.Shell; import org.jnode.shell.ShellUtils; import org.jnode.shell.syntax.Argument; @@ -49,8 +47,8 @@ new FlagArgument("test", Argument.OPTIONAL, "If set, don't try to execute the history command"); private Shell shell; - private PrintStream out; - private PrintStream err; + private PrintWriter out; + private PrintWriter err; private InputHistory history; @@ -60,12 +58,11 @@ } @Override - public void execute(CommandLine commandLine, InputStream in, - PrintStream out, PrintStream err) throws Exception { + public void execute() throws Exception { shell = ShellUtils.getShellManager().getCurrentShell(); history = shell.getCommandHistory(); - this.out = out; - this.err = err; + this.out = getOutput().getPrintWriter(); + this.err = getError().getPrintWriter(); int index = ARG_INDEX.isSet() ? ARG_INDEX.getValue() : -1; String prefix = ARG_PREFIX.isSet() ? ARG_PREFIX.getValue() : null; Modified: trunk/shell/src/shell/org/jnode/shell/command/IsolateCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/IsolateCommand.java 2008-11-09 13:57:29 UTC (rev 4693) +++ trunk/shell/src/shell/org/jnode/shell/command/IsolateCommand.java 2008-11-09 14:20:31 UTC (rev 4694) @@ -3,11 +3,10 @@ */ package org.jnode.shell.command; +import java.io.PrintWriter; + import org.jnode.shell.AbstractCommand; -import org.jnode.shell.CommandLine; import org.jnode.vm.isolate.VmIsolate; -import java.io.InputStream; -import java.io.PrintStream; /** * The IsolateCommand provides information about the current isolates in the system. @@ -15,8 +14,8 @@ */ public class IsolateCommand extends AbstractCommand { @Override - public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) - throws Exception { + public void execute() throws Exception { + final PrintWriter out = getOutput().getPrintWriter(); out.println(" Id " + " Creator " + "State " + "Main class"); VmIsolate root = VmIsolate.getRoot(); if (root != null) { Modified: trunk/shell/src/shell/org/jnode/shell/command/test/SuiteCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/test/SuiteCommand.java 2008-11-09 13:57:29 UTC (rev 4693) +++ trunk/shell/src/shell/org/jnode/shell/command/test/SuiteCommand.java 2008-11-09 14:20:31 UTC (rev 4694) @@ -21,8 +21,7 @@ package org.jnode.shell.command.test; -import java.io.InputStream; -import java.io.PrintStream; +import java.io.PrintWriter; import java.util.Arrays; import java.util.Set; @@ -31,7 +30,6 @@ import org.jnode.driver.console.CompletionInfo; import org.jnode.shell.AbstractCommand; -import org.jnode.shell.CommandLine; import org.jnode.shell.syntax.Argument; import org.jnode.shell.syntax.CommandSyntaxException; import org.jnode.shell.syntax.FlagArgument; @@ -68,10 +66,10 @@ /** * Execute this command */ - public void execute(CommandLine cmdLine, InputStream in, - PrintStream out, PrintStream err) { + public void execute() { TestManager mgr = TestManager.getInstance(); if (FLAG_LIST.isSet()) { + PrintWriter out = getOutput().getPrintWriter(); for (Class<? extends Test> test : mgr.getTests()) { out.print(test.getName() + " :"); for (String category : mgr.getCategories(test)) { Modified: trunk/shell/src/shell/org/jnode/shell/command/test/TestCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/test/TestCommand.java 2008-11-09 13:57:29 UTC (rev 4693) +++ trunk/shell/src/shell/org/jnode/shell/command/test/TestCommand.java 2008-11-09 14:20:31 UTC (rev 4694) @@ -21,15 +21,11 @@ package org.jnode.shell.command.test; -import java.io.InputStream; -import java.io.PrintStream; - import junit.framework.TestResult; import junit.framework.TestSuite; import junit.textui.TestRunner; import org.jnode.shell.AbstractCommand; -import org.jnode.shell.CommandLine; import org.jnode.shell.syntax.Argument; import org.jnode.shell.syntax.ClassNameArgument; @@ -56,8 +52,7 @@ * * @throws ClassNotFoundException */ - public void execute(CommandLine cmdLine, InputStream in, - PrintStream out, PrintStream err) { + public void execute() { try { Class<?> clazz = ARG_CLASS.getValueAsClass(); TestResult res = new TestRunner().doRun(new TestSuite(clazz)); @@ -65,7 +60,7 @@ exit(1); } } catch (ClassNotFoundException ex) { - err.println("Class not found: " + ex.getMessage()); + getError().getPrintWriter().println("Class not found: " + ex.getMessage()); exit(2); } } Modified: trunk/shell/src/shell/org/jnode/shell/command/unix/UnixTestCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/unix/UnixTestCommand.java 2008-11-09 13:57:29 UTC (rev 4693) +++ trunk/shell/src/shell/org/jnode/shell/command/unix/UnixTestCommand.java 2008-11-09 14:20:31 UTC (rev 4694) @@ -22,7 +22,6 @@ package org.jnode.shell.command.unix; import java.io.File; -import java.io.PrintStream; import java.io.PrintWriter; import java.util.HashMap; import java.util.Stack; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |