From: <cr...@us...> - 2008-11-09 13:23:38
|
Revision: 4692 http://jnode.svn.sourceforge.net/jnode/?rev=4692&view=rev Author: crawley Date: 2008-11-09 13:23:28 +0000 (Sun, 09 Nov 2008) Log Message: ----------- Converting commands to use execute() and PrintWriter + API ripple. Modified Paths: -------------- trunk/core/src/driver/org/jnode/driver/console/ConsoleManager.java trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsoleManager.java trunk/shell/src/shell/org/jnode/shell/command/bsh/BshCommand.java trunk/shell/src/shell/org/jnode/shell/command/debug/DebugCommand.java trunk/shell/src/shell/org/jnode/shell/command/debug/RemoteOutputCommand.java trunk/shell/src/shell/org/jnode/shell/command/driver/console/ClearConsoleCommand.java trunk/shell/src/shell/org/jnode/shell/command/driver/console/ConsoleCommand.java Modified: trunk/core/src/driver/org/jnode/driver/console/ConsoleManager.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/console/ConsoleManager.java 2008-11-09 12:24:49 UTC (rev 4691) +++ trunk/core/src/driver/org/jnode/driver/console/ConsoleManager.java 2008-11-09 13:23:28 UTC (rev 4692) @@ -21,7 +21,7 @@ package org.jnode.driver.console; -import java.io.PrintStream; +import java.io.PrintWriter; import java.util.Set; import org.jnode.driver.input.KeyboardListener; @@ -151,5 +151,5 @@ */ public Console createConsole(String name, int options); - public void printConsoles(PrintStream ps); + public void printConsoles(PrintWriter pw); } Modified: trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsoleManager.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsoleManager.java 2008-11-09 12:24:49 UTC (rev 4691) +++ trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsoleManager.java 2008-11-09 13:23:28 UTC (rev 4692) @@ -23,7 +23,7 @@ import java.awt.event.InputEvent; import java.awt.event.KeyEvent; -import java.io.PrintStream; +import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -35,7 +35,9 @@ import java.util.Map; import java.util.Set; import java.util.Stack; + import javax.naming.NameNotFoundException; + import org.apache.log4j.Logger; import org.jnode.driver.ApiNotFoundException; import org.jnode.driver.Device; @@ -215,19 +217,19 @@ } } - public void printConsoles(PrintStream ps) { + public void printConsoles(PrintWriter pw) { ArrayList<Integer> list = new ArrayList<Integer>(); list.addAll(stackMap.keySet()); Collections.sort(list); for (Integer key : list) { - ps.println("Screen of " + KeyEvent.getKeyText(key) + ":"); + pw.println("Screen of " + KeyEvent.getKeyText(key) + ":"); Stack<Console> stack = stackMap.get(key); int t_ind = stack.size(); for (int i = t_ind; i-- > 0;) { Console console = stack.get(i); String prefix = console == current ? " > " : i == t_ind - 1 ? " * " : " "; - ps.println(prefix + console.getConsoleName()); + pw.println(prefix + console.getConsoleName()); } } } Modified: trunk/shell/src/shell/org/jnode/shell/command/bsh/BshCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/bsh/BshCommand.java 2008-11-09 12:24:49 UTC (rev 4691) +++ trunk/shell/src/shell/org/jnode/shell/command/bsh/BshCommand.java 2008-11-09 13:23:28 UTC (rev 4692) @@ -28,7 +28,6 @@ import java.io.PrintStream; import org.jnode.shell.AbstractCommand; -import org.jnode.shell.CommandLine; import org.jnode.shell.syntax.Argument; import org.jnode.shell.syntax.FileArgument; import org.jnode.shell.syntax.FlagArgument; @@ -58,12 +57,13 @@ new BshCommand().execute(args); } - public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) - throws Exception { + public void execute() throws Exception { Interpreter bsh = null; Object ret; boolean interactive = false; - + InputStream in = getInput().getInputStream(); + OutputStream out = getOutput().getOutputStream(); + OutputStream err = getError().getOutputStream(); if (FLAG_INTERACTIVE.isSet()) { bsh = createInterpreter(in, out, err, true); interactive = true; @@ -77,7 +77,7 @@ ret = bsh.eval(code); if (ret != null) { - out.println(ret); + out.write((ret + "\n").getBytes()); } } @@ -90,9 +90,10 @@ ret = bsh.source(file); if (ret != null) { - out.println(ret); + out.write((ret + "\n").getBytes()); } } + out.flush(); if (bsh == null) { // If no arguments were given, default to interactive mode. Modified: trunk/shell/src/shell/org/jnode/shell/command/debug/DebugCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/debug/DebugCommand.java 2008-11-09 12:24:49 UTC (rev 4691) +++ trunk/shell/src/shell/org/jnode/shell/command/debug/DebugCommand.java 2008-11-09 13:23:28 UTC (rev 4692) @@ -6,11 +6,10 @@ import gnu.classpath.jdwp.JNodeSocketTransport; import gnu.classpath.jdwp.Jdwp; -import java.io.InputStream; -import java.io.PrintStream; +import java.io.PrintWriter; +import java.io.Reader; import org.jnode.shell.AbstractCommand; -import org.jnode.shell.CommandLine; import org.jnode.shell.syntax.Argument; import org.jnode.shell.syntax.IntegerArgument; @@ -35,8 +34,7 @@ } @Override - public void execute(CommandLine commandLine, InputStream in, - PrintStream out, PrintStream err) throws Exception { + public void execute() throws Exception { int port = ARG_PORT.isSet() ? ARG_PORT.getValue() : DEFAULT_PORT; // FIXME - in the even of internal exceptions, JDWP writes to System.out. @@ -56,6 +54,8 @@ }); t.start(); + Reader in = getInput().getReader(); + PrintWriter out = getOutput().getPrintWriter(); while (in.read() != 'q') { out.println("Type 'q' to exit"); } Modified: trunk/shell/src/shell/org/jnode/shell/command/debug/RemoteOutputCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/debug/RemoteOutputCommand.java 2008-11-09 12:24:49 UTC (rev 4691) +++ trunk/shell/src/shell/org/jnode/shell/command/debug/RemoteOutputCommand.java 2008-11-09 13:23:28 UTC (rev 4692) @@ -22,10 +22,9 @@ package org.jnode.shell.command.debug; import java.io.IOException; -import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; -import java.io.PrintStream; +import java.io.PrintWriter; import java.io.Writer; import java.net.ConnectException; import java.net.InetAddress; @@ -39,7 +38,6 @@ import org.jnode.debug.RemoteReceiver; import org.jnode.debug.UDPOutputStream; import org.jnode.shell.AbstractCommand; -import org.jnode.shell.CommandLine; import org.jnode.shell.ShellUtils; import org.jnode.shell.syntax.Argument; import org.jnode.shell.syntax.FlagArgument; @@ -68,9 +66,8 @@ registerArguments(ARG_ADDRESS, ARG_PORT, FLAG_UDP); } - public void execute(CommandLine commandLine, InputStream in, - PrintStream out, PrintStream err) - throws Exception { + public void execute() throws Exception { + PrintWriter err = getError().getPrintWriter(); try { final int port = ARG_PORT.isSet() ? ARG_PORT.getValue() : DEFAULT_PORT; final InetAddress addr = ARG_ADDRESS.getAsInetAddress(); Modified: trunk/shell/src/shell/org/jnode/shell/command/driver/console/ClearConsoleCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/driver/console/ClearConsoleCommand.java 2008-11-09 12:24:49 UTC (rev 4691) +++ trunk/shell/src/shell/org/jnode/shell/command/driver/console/ClearConsoleCommand.java 2008-11-09 13:23:28 UTC (rev 4692) @@ -21,12 +21,8 @@ package org.jnode.shell.command.driver.console; -import java.io.InputStream; -import java.io.PrintStream; - import org.jnode.driver.console.TextConsole; import org.jnode.shell.AbstractCommand; -import org.jnode.shell.CommandLine; import org.jnode.shell.Shell; import org.jnode.shell.ShellUtils; @@ -51,8 +47,7 @@ } @Override - public void execute(CommandLine commandLine, InputStream in, - PrintStream out, PrintStream err) throws Exception { + public void execute() throws Exception { final Shell shell = ShellUtils.getCurrentShell(); TextConsole tc = (TextConsole) shell.getConsole(); tc.clear(); Modified: trunk/shell/src/shell/org/jnode/shell/command/driver/console/ConsoleCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/driver/console/ConsoleCommand.java 2008-11-09 12:24:49 UTC (rev 4691) +++ trunk/shell/src/shell/org/jnode/shell/command/driver/console/ConsoleCommand.java 2008-11-09 13:23:28 UTC (rev 4692) @@ -21,7 +21,7 @@ package org.jnode.shell.command.driver.console; -import java.io.InputStream; +import java.io.OutputStreamWriter; import java.io.PrintStream; import java.io.PrintWriter; @@ -33,7 +33,6 @@ import org.jnode.driver.console.TextConsole; import org.jnode.naming.InitialNaming; import org.jnode.shell.AbstractCommand; -import org.jnode.shell.CommandLine; import org.jnode.shell.CommandShell; import org.jnode.shell.ShellException; import org.jnode.shell.ShellManager; @@ -73,9 +72,8 @@ } @Override - public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) - throws NameNotFoundException, IsolateStartupException, ShellException { - + public void execute() throws NameNotFoundException, IsolateStartupException, ShellException { + final PrintWriter out = getOutput().getPrintWriter(); final ShellManager sm = InitialNaming.lookup(ShellManager.NAME); final ConsoleManager conMgr = sm.getCurrentShell().getConsole().getManager(); @@ -120,7 +118,8 @@ try { final ShellManager sm = InitialNaming.lookup(ShellManager.NAME); final ConsoleManager conMgr = sm.getCurrentShell().getConsole().getManager(); - TextConsole console = createConsoleWithShell(conMgr, System.out); + final PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); + TextConsole console = createConsoleWithShell(conMgr, out); System.setIn(new ReaderInputStream(console.getIn())); System.setOut(new PrintStream(new WriterOutputStream(console.getOut()), true)); System.setErr(new PrintStream(new WriterOutputStream(console.getErr()), true)); @@ -132,7 +131,7 @@ } } - private static TextConsole createConsoleWithShell(final ConsoleManager conMgr, PrintStream out) + private static TextConsole createConsoleWithShell(final ConsoleManager conMgr, PrintWriter out) throws ShellException { final TextConsole console = (TextConsole) conMgr.createConsole(null, ConsoleManager.CreateOptions.TEXT | ConsoleManager.CreateOptions.SCROLLABLE); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |