From: <cr...@us...> - 2008-04-25 09:58:58
|
Revision: 4018 http://jnode.svn.sourceforge.net/jnode/?rev=4018&view=rev Author: crawley Date: 2008-04-25 02:58:56 -0700 (Fri, 25 Apr 2008) Log Message: ----------- Converted MemoryCommand Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/MemoryCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-25 05:56:03 UTC (rev 4017) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-25 09:58:56 UTC (rev 4018) @@ -149,8 +149,8 @@ </sequence> </syntax> <syntax alias="loadkeys"> - <empty description="print the current keyboard layout"/> - <sequence description="change the keyboard layout"> + <empty description="Print the current keyboard layout"/> + <sequence description="Change the keyboard layout"> <argument argLabel="country"/> <optional> <argument argLabel="language"/> @@ -161,9 +161,9 @@ </sequence> </syntax> <syntax alias="locale"> - <empty description="print the current default Locale name"/> - <option argLabel="list" longName="list" shortName="l" description="list the names of the available Locales"/> - <sequence description="change the default Locale"> + <empty description="Print the current default Locale name"/> + <option argLabel="list" longName="list" shortName="l" description="List the names of the available Locales"/> + <sequence description="Change the default Locale"> <argument argLabel="language"/> <optional> <argument argLabel="country"/> @@ -173,6 +173,7 @@ </optional> </sequence> </syntax> + <syntax alias="memory" description="Show JNode memory usage"/> <syntax alias="run" description="Run a command file"> <argument argLabel="file"/> </syntax> Modified: trunk/shell/src/shell/org/jnode/shell/command/MemoryCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/MemoryCommand.java 2008-04-25 05:56:03 UTC (rev 4017) +++ trunk/shell/src/shell/org/jnode/shell/command/MemoryCommand.java 2008-04-25 09:58:56 UTC (rev 4018) @@ -26,7 +26,6 @@ import org.jnode.shell.AbstractCommand; import org.jnode.shell.CommandLine; -import org.jnode.shell.help.Help; import org.jnode.util.NumberUtils; /** @@ -34,17 +33,19 @@ */ public class MemoryCommand extends AbstractCommand { - - public static Help.Info HELP_INFO = new Help.Info("memory", "View the current memory status"); - public static void main(String[] args) throws Exception { new MemoryCommand().execute(args); } + + public MemoryCommand() { + super("shows current JNode memory usage"); + } - /** + /** * Execute this command */ - public void execute(CommandLine cmdLine, InputStream in, PrintStream out, PrintStream err) throws Exception { + public void execute(CommandLine cmdLine, InputStream in, PrintStream out, PrintStream err) + throws Exception { final Runtime rt = Runtime.getRuntime(); out.println("Total memory " + NumberUtils.toBinaryByte(rt.totalMemory())); out.println("Used memory " + NumberUtils.toBinaryByte(rt.totalMemory() - rt.freeMemory())); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-04-25 13:12:01
|
Revision: 4021 http://jnode.svn.sourceforge.net/jnode/?rev=4021&view=rev Author: crawley Date: 2008-04-25 06:11:59 -0700 (Fri, 25 Apr 2008) Log Message: ----------- Converted NamepaceCommand. Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/NamespaceCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-25 12:01:06 UTC (rev 4020) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-25 13:11:59 UTC (rev 4021) @@ -174,6 +174,7 @@ </sequence> </syntax> <syntax alias="memory" description="Show JNode memory usage"/> + <syntax alias="namespace" description="Print the contents of the system namespace"/> <syntax alias="run" description="Run a command file"> <argument argLabel="file"/> </syntax> Modified: trunk/shell/src/shell/org/jnode/shell/command/NamespaceCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/NamespaceCommand.java 2008-04-25 12:01:06 UTC (rev 4020) +++ trunk/shell/src/shell/org/jnode/shell/command/NamespaceCommand.java 2008-04-25 13:11:59 UTC (rev 4021) @@ -28,15 +28,15 @@ import org.jnode.naming.InitialNaming; import org.jnode.shell.AbstractCommand; import org.jnode.shell.CommandLine; -import org.jnode.shell.help.Help; /** * @author epr */ public class NamespaceCommand extends AbstractCommand { - public static Help.Info HELP_INFO = new Help.Info("namespace", - "Print the contents of the system namespace"); + public NamespaceCommand() { + super("Print the contents of the system namespace"); + } public static void main(String[] args) throws Exception { new NamespaceCommand().execute(args); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-04-25 14:04:05
|
Revision: 4023 http://jnode.svn.sourceforge.net/jnode/?rev=4023&view=rev Author: crawley Date: 2008-04-25 07:03:56 -0700 (Fri, 25 Apr 2008) Log Message: ----------- Converted OnheapCommand Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/OnHeapCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-25 14:03:05 UTC (rev 4022) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-25 14:03:56 UTC (rev 4023) @@ -175,6 +175,12 @@ </syntax> <syntax alias="memory" description="Show JNode memory usage"/> <syntax alias="namespace" description="Print the contents of the system namespace"/> + <syntax alias="onheap" description="Print heap object count and size statistics"> + <optionSet> + <option argLabel="minCount" longName="minCount"/> + <option argLabel="minTotalSize" longName="minTotalSize"/> + </optionSet> + </syntax> <syntax alias="run" description="Run a command file"> <argument argLabel="file"/> </syntax> Modified: trunk/shell/src/shell/org/jnode/shell/command/OnHeapCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/OnHeapCommand.java 2008-04-25 14:03:05 UTC (rev 4022) +++ trunk/shell/src/shell/org/jnode/shell/command/OnHeapCommand.java 2008-04-25 14:03:56 UTC (rev 4023) @@ -26,11 +26,9 @@ import org.jnode.shell.AbstractCommand; import org.jnode.shell.CommandLine; -import org.jnode.shell.help.Help; -import org.jnode.shell.help.Parameter; -import org.jnode.shell.help.ParsedArguments; -import org.jnode.shell.help.argument.IntegerArgument; -import org.jnode.shell.help.argument.SizeArgument; +import org.jnode.shell.syntax.Argument; +import org.jnode.shell.syntax.IntegerArgument; +import org.jnode.shell.syntax.LongArgument; import org.jnode.vm.Vm; import org.jnode.vm.memmgr.HeapStatistics; @@ -39,22 +37,17 @@ */ public class OnHeapCommand extends AbstractCommand { - private static final IntegerArgument ARG_MININSTANCECOUNT = new IntegerArgument( - "mic", "the minimum instance count to show"); + private final IntegerArgument ARG_MIN_INSTANCE_COUNT = new IntegerArgument( + "minCount", Argument.OPTIONAL, 1, Integer.MAX_VALUE, "the minimum instance count to show"); - private static final SizeArgument ARG_MINTOTALSIZE = new SizeArgument( - "mts", "the minimum total size to show"); + private final LongArgument ARG_MIN_TOTAL_SIZE = new LongArgument( + "minTotalSize", Argument.OPTIONAL, 1L, Long.MAX_VALUE, "the minimum total size to show"); - private static final Parameter PARAM_MININSTANCECOUNT = new Parameter( - ARG_MININSTANCECOUNT, Parameter.OPTIONAL); + public OnHeapCommand() { + super("show the number of instances on the heap with memory usage"); + registerArguments(ARG_MIN_INSTANCE_COUNT, ARG_MIN_TOTAL_SIZE); + } - private static final Parameter PARAM_MINTOTALSIZE = new Parameter( - ARG_MINTOTALSIZE, Parameter.OPTIONAL); - - public static Help.Info HELP_INFO = new Help.Info("onheap", - "show the number of instances on the heap with memory usage", - new Parameter[] { PARAM_MININSTANCECOUNT , PARAM_MINTOTALSIZE }); - public static void main(String[] args) throws Exception { new OnHeapCommand().execute(null, System.in, System.out, System.err); } @@ -64,16 +57,14 @@ */ public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception { - final ParsedArguments args = HELP_INFO.parse(commandLine); - out.println("on heap:"); final HeapStatistics stats = Vm.getHeapManager().getHeapStatistics(); - if (PARAM_MININSTANCECOUNT.isSet(args)) { - stats.setMinimumInstanceCount(ARG_MININSTANCECOUNT.getInteger(args)); + if (ARG_MIN_INSTANCE_COUNT.isSet()) { + stats.setMinimumInstanceCount(ARG_MIN_INSTANCE_COUNT.getValue()); } - if (PARAM_MINTOTALSIZE.isSet(args)) { - stats.setMinimumTotalSize(ARG_MINTOTALSIZE.getLong(args)); + if (ARG_MIN_TOTAL_SIZE.isSet()) { + stats.setMinimumTotalSize(ARG_MIN_TOTAL_SIZE.getValue()); } out.println(stats.toString()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-04-26 03:06:33
|
Revision: 4025 http://jnode.svn.sourceforge.net/jnode/?rev=4025&view=rev Author: crawley Date: 2008-04-25 20:06:32 -0700 (Fri, 25 Apr 2008) Log Message: ----------- Converted and tidied up ThreadCommand Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/ThreadCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-26 03:05:45 UTC (rev 4024) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-26 03:06:32 UTC (rev 4025) @@ -202,11 +202,18 @@ <option argLabel="file" longName="load" shortName="l"/> <argument argLabel="alias"/> </sequence> - <sequence description="set a system property"> + <sequence description="Set a system property"> <option argLabel="remove" longName="remove" shortName="r"/> <argument argLabel="alias"/> </sequence> </syntax> + <syntax alias="thread"> + <optional description="Display all extant JNode Threads"> + <option argLabel="groupDump" longName="groupDump" shortName="g" + description="Display as a ThreadGroup dump"/> + </optional> + <argument argLabel="threadName" description="Display the named Thread"/> + </syntax> </extension> <extension point="org.jnode.security.permissions"> Modified: trunk/shell/src/shell/org/jnode/shell/command/ThreadCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/ThreadCommand.java 2008-04-26 03:05:45 UTC (rev 4024) +++ trunk/shell/src/shell/org/jnode/shell/command/ThreadCommand.java 2008-04-26 03:06:32 UTC (rev 4025) @@ -26,29 +26,35 @@ import org.jnode.shell.AbstractCommand; import org.jnode.shell.CommandLine; -import org.jnode.shell.help.Help; -import org.jnode.shell.help.Parameter; -import org.jnode.shell.help.ParsedArguments; -import org.jnode.shell.help.argument.ThreadNameArgument; +import org.jnode.shell.syntax.Argument; +import org.jnode.shell.syntax.FlagArgument; +import org.jnode.shell.syntax.ThreadNameArgument; import org.jnode.vm.scheduler.VmThread; /** - * Shell command to view threads or a specific thread. + * Shell command to print information about all threads or a specific thread. * * @author Ewout Prangsma (ep...@us...) * @author Martin Husted Hartvig (ha...@jn...) + * @author cr...@jn... */ - public class ThreadCommand extends AbstractCommand { - private static final ThreadNameArgument ARG_NAME = new ThreadNameArgument("threadName", "the name of the thread to view"); - private static final Parameter PAR_NAME = new Parameter(ARG_NAME, Parameter.OPTIONAL); + private final static String SEPARATOR = ", "; + private final static String SLASH_T = "\t"; + private final static String GROUP = "Group "; + private final static String TRACE = "Stack trace"; - public static Help.Info HELP_INFO = new Help.Info("thread", "View all or a specific threads", new Parameter[] { PAR_NAME }); + private final ThreadNameArgument ARG_NAME = + new ThreadNameArgument("threadName", Argument.OPTIONAL, "the name of a specific thread to be printed"); + private final FlagArgument FLAG_GROUP_DUMP = + new FlagArgument("groupDump", Argument.OPTIONAL, "if set, output a ThreadGroup dump"); - private final static String SEPARATOR = ", ", SLASH_T = "\t", GROUP = "Group "; - - + public ThreadCommand() { + super("View all or a specific threads"); + registerArguments(ARG_NAME, FLAG_GROUP_DUMP); + } + public static void main(String[] args) throws Exception { new ThreadCommand().execute(args); } @@ -58,70 +64,57 @@ */ public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception { - ParsedArguments parsedArguments = HELP_INFO.parse(commandLine); - - if (PAR_NAME.isSet(parsedArguments)) { - execute(out, ARG_NAME.getValue(parsedArguments)); - } else { - execute(out, null); - } - } - - public void execute(PrintStream out, String threadName) { + // If threadName is null, we'll print all threads + String threadName = (ARG_NAME.isSet()) ? ARG_NAME.getValue() : null; + boolean dump = FLAG_GROUP_DUMP.isSet(); + + // Find the root of the ThreadGroup tree ThreadGroup grp = Thread.currentThread().getThreadGroup(); - while (grp.getParent() != null) { grp = grp.getParent(); } - showGroup(grp, out, threadName); + + if (dump) { + // Produce an ugly (but useful) ThreadGroup dump + grp.list(); + } + else { + // Show the threads in the ThreadGroup tree. + showThreads(grp, out, threadName); + } } - private void showGroup(ThreadGroup grp, PrintStream out, String threadName) { - if (threadName == null - // preserve compatible behavior when piped - && out == System.out) { - grp.list(); - return; + /** + * Traverse the ThreadGroups threads and its child ThreadGroups printing + * information for each thread found. If 'threadName' is non-null, only + * print information for the thread that matches the name. + * + * @param grp the ThreadGroup to traverse + * @param out the destination for output + * @param threadName if non-null, only display this thread. + */ + private void showThreads(ThreadGroup grp, PrintStream out, String threadName) { + if (threadName == null) { + out.println(GROUP + grp.getName()); } - if (threadName != null) { - out.print(GROUP); - out.println(grp.getName()); - } - final int max = grp.activeCount() * 2; final Thread[] ts = new Thread[max]; grp.enumerate(ts); - for (int i = 0; i < max; i++) { final Thread t = ts[i]; if (t != null) { if ((threadName == null) || threadName.equals(t.getName())) { - out.print(SLASH_T); - StringBuilder buffer = new StringBuilder(); - - buffer.append(t.getId()); - buffer.append(SEPARATOR); - buffer.append(t.getName()); - buffer.append(SEPARATOR); - buffer.append(t.getPriority()); - buffer.append(SEPARATOR); - buffer.append(t.getVmThread().getThreadStateName()); - - out.println(buffer.toString()); + out.println(SLASH_T + t.getId() + SEPARATOR + t.getName() + SEPARATOR + + t.getPriority() + SEPARATOR + t.getVmThread().getThreadStateName()); if (threadName != null) { final Object[] trace = VmThread.getStackTrace(t.getVmThread()); final int traceLen = trace.length; + out.println(SLASH_T + SLASH_T + TRACE); for (int k = 0; k < traceLen; k++) { - buffer = new StringBuilder(); - buffer.append(SLASH_T); - buffer.append(SLASH_T); - buffer.append(trace[k]); - - out.println(buffer.toString()); + out.println(SLASH_T + SLASH_T + trace[k]); } - return; } } @@ -134,9 +127,8 @@ for (int i = 0; i < gmax; i++) { final ThreadGroup tg = tgs[i]; if (tg != null) { - showGroup(tg, out, threadName); + showThreads(tg, out, threadName); } } } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-04-26 04:46:17
|
Revision: 4026 http://jnode.svn.sourceforge.net/jnode/?rev=4026&view=rev Author: crawley Date: 2008-04-25 21:46:15 -0700 (Fri, 25 Apr 2008) Log Message: ----------- Converted BshCommand Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.bsh.xml trunk/shell/src/shell/org/jnode/shell/command/bsh/BshCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.bsh.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.bsh.xml 2008-04-26 03:06:32 UTC (rev 4025) +++ trunk/shell/descriptors/org.jnode.shell.command.bsh.xml 2008-04-26 04:46:15 UTC (rev 4026) @@ -21,7 +21,17 @@ <extension point="org.jnode.shell.aliases"> <alias name="bsh" class="org.jnode.shell.command.bsh.BshCommand"/> </extension> - + + <extension point="org.jnode.shell.syntaxes"> + <syntax alias="bsh"> + <optionSet description="Run the BeanShell interpreter"> + <option argLabel="file" shortName="f" longName="file"/> + <option argLabel="code" shortName="c" longName="code"/> + <option argLabel="interactive" shortName="i" longName="interactive"/> + </optionSet> + </syntax> + </extension> + <extension point="org.jnode.security.permissions"> <permission class="java.io.FilePermission" name="<<ALL FILES>>" actions="read,write"/> <permission class="java.lang.RuntimePermission" name="setSecurityManager" actions="*" /> Modified: trunk/shell/src/shell/org/jnode/shell/command/bsh/BshCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/bsh/BshCommand.java 2008-04-26 03:06:32 UTC (rev 4025) +++ trunk/shell/src/shell/org/jnode/shell/command/bsh/BshCommand.java 2008-04-26 04:46:15 UTC (rev 4026) @@ -29,100 +29,87 @@ import org.jnode.shell.AbstractCommand; import org.jnode.shell.CommandLine; -import org.jnode.shell.help.Help; -import org.jnode.shell.help.Parameter; -import org.jnode.shell.help.ParsedArguments; -import org.jnode.shell.help.Syntax; -import org.jnode.shell.help.argument.FileArgument; -import org.jnode.shell.help.argument.OptionArgument; -import org.jnode.shell.help.argument.StringArgument; +import org.jnode.shell.syntax.*; import bsh.Interpreter; /** * @author Levente S\u00e1ntha + * @author cr...@jn... */ public class BshCommand extends AbstractCommand { - private static final StringArgument ARG_CODE = new StringArgument("code", "a BeanShell code snippet to execute"); - static final OptionArgument ARG_C = new OptionArgument("-c", "execute code", - new OptionArgument.Option("-c", "execute code")); - private static final Parameter PARAM_C = new Parameter(ARG_C, Parameter.MANDATORY); - private static final Parameter PARAM_CODE = new Parameter(ARG_CODE, Parameter.MANDATORY); - private static final FileArgument ARG_FILE = new FileArgument("file", "a BeanShell script file to execute"); - static final OptionArgument ARG_F = new OptionArgument("-f", "execute file", - new OptionArgument.Option("-f", "execute file")); - private static final Parameter PARAM_F = new Parameter(ARG_F, Parameter.MANDATORY); - private static final Parameter PARAM_FILE = new Parameter(ARG_FILE, Parameter.MANDATORY); - static final OptionArgument ARG_I = new OptionArgument("-i", "go interactive", - new OptionArgument.Option("-i", "go interactive")); - private static final Parameter PARAM_INTERACTIVE = new Parameter(ARG_I, Parameter.MANDATORY); - public static Help.Info HELP_INFO = new Help.Info( - "bsh", - new Syntax("start the interactive BeanShell interpreter"), - new Syntax("invoke the BeanShell interpreter", PARAM_C, PARAM_CODE), - new Syntax("invoke the BeanShell interpreter", PARAM_F, PARAM_FILE), - new Syntax("invoke the BeanShell interpreter", PARAM_C, PARAM_CODE, PARAM_F, PARAM_FILE), - new Syntax("invoke the BeanShell interpreter", PARAM_INTERACTIVE, PARAM_C, PARAM_CODE), - new Syntax("invoke the BeanShell interpreter", PARAM_INTERACTIVE, PARAM_F, PARAM_FILE), - new Syntax("invoke the BeanShell interpreter", PARAM_INTERACTIVE, PARAM_C, PARAM_CODE, PARAM_F, PARAM_FILE) - ); + private final StringArgument ARG_CODE = + new StringArgument("code", Argument.OPTIONAL, "a BeanShell code snippet to execute"); + private final FileArgument ARG_FILE = + new FileArgument("file", Argument.OPTIONAL, "a BeanShell script file to execute"); + private final FlagArgument FLAG_INTERACTIVE = + new FlagArgument("interactive", Argument.OPTIONAL, "go interactive"); + + public BshCommand() { + super("run the BeanShell interpreter"); + registerArguments(ARG_CODE, ARG_FILE, FLAG_INTERACTIVE); + } public static void main(String[] args) throws Exception { new BshCommand().execute(args); } - public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception { - ParsedArguments parsedArguments = HELP_INFO.parse(commandLine); + public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) + throws Exception { Interpreter bsh = null; Object ret; boolean interactive = false; - if(PARAM_INTERACTIVE.isSet(parsedArguments)){ + if (FLAG_INTERACTIVE.isSet()) { bsh = createInterpreter(in, out, err, true); interactive = true; } - - if (PARAM_C.isSet(parsedArguments)){ - if(bsh == null) + if (ARG_CODE.isSet()) { + if (bsh == null) { bsh = createInterpreter(in, out, err, false); - - String code = ARG_CODE.getValue(parsedArguments); + } + String code = ARG_CODE.getValue(); ret = bsh.eval(code); - if(ret != null) + if (ret != null) { out.println(ret); + } } - - if(PARAM_F.isSet(parsedArguments)){ - if(bsh == null) + if (ARG_FILE.isSet()){ + if (bsh == null) { bsh = createInterpreter(in, out, err, false); + } - String file = ARG_FILE.getValue(parsedArguments); + String file = ARG_FILE.getValue().toString(); ret = bsh.source(file); - if(ret != null) + if (ret != null) { out.println(ret); + } } - if(bsh == null){ + if (bsh == null) { + // If no arguments were given, default to interactive mode. bsh = createInterpreter(in, out, err, true); interactive = true; } - - if(interactive) + + if (interactive) { bsh.run(); + } } - private static Interpreter createInterpreter(InputStream in, OutputStream out, OutputStream err, boolean interactive) + private Interpreter createInterpreter( + InputStream in, OutputStream out, OutputStream err, boolean interactive) throws Exception{ Interpreter interpreter = new Interpreter( new BufferedReader(new InputStreamReader(in)), new PrintStream(out), new PrintStream(err), interactive); - if(interactive){ + if (interactive) { interpreter.eval("show();"); } return interpreter; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-04-27 13:13:13
|
Revision: 4031 http://jnode.svn.sourceforge.net/jnode/?rev=4031&view=rev Author: crawley Date: 2008-04-27 06:13:10 -0700 (Sun, 27 Apr 2008) Log Message: ----------- Converted DebugCommand. (It doesn't work though: see issue 2592) Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.debug.xml trunk/shell/src/shell/org/jnode/shell/command/debug/DebugCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.debug.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.debug.xml 2008-04-27 11:29:40 UTC (rev 4030) +++ trunk/shell/descriptors/org.jnode.shell.command.debug.xml 2008-04-27 13:13:10 UTC (rev 4031) @@ -23,6 +23,14 @@ <alias name="debug" class="org.jnode.shell.command.debug.DebugCommand"/> </extension> + <extension point="org.jnode.shell.syntaxes"> + <syntax alias="debug"> + <optional description="Run a JDWP listener to enable remote debugging"> + <option argLabel="port" shortName="p" description="The port for the debugger to connect to"/> + </optional> + </syntax> + </extension> + <extension point="org.jnode.security.permissions"> <permission class="java.lang.RuntimePermission" name="modifyThreadGroup"/> <permission class="java.lang.RuntimePermission" name="setIO"/> Modified: trunk/shell/src/shell/org/jnode/shell/command/debug/DebugCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/debug/DebugCommand.java 2008-04-27 11:29:40 UTC (rev 4030) +++ trunk/shell/src/shell/org/jnode/shell/command/debug/DebugCommand.java 2008-04-27 13:13:10 UTC (rev 4031) @@ -6,30 +6,40 @@ import gnu.classpath.jdwp.JNodeSocketTransport; import gnu.classpath.jdwp.Jdwp; -import org.jnode.shell.help.Help; -import org.jnode.shell.help.Parameter; -import org.jnode.shell.help.ParsedArguments; -import org.jnode.shell.help.argument.IntegerArgument; +import java.io.InputStream; +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.IntegerArgument; + /** - * Starts up the remote debugger under JNode. + * Starts up a JDWP remote debugger listener for this JNode instance. * * @author Levente S\u00e1ntha */ -public class DebugCommand { +public class DebugCommand extends AbstractCommand { private static final int DEFAULT_PORT = 6789; - private static boolean up = true; - static final IntegerArgument ARG_PORT = new IntegerArgument("port", "the port to listen to"); + private boolean up = true; + private final IntegerArgument ARG_PORT = + new IntegerArgument("port", Argument.OPTIONAL, "the port to listen to"); - public static Help.Info HELP_INFO = new Help.Info("debug", "Start the remote debugger server.", new Parameter(ARG_PORT, Parameter.OPTIONAL)); - - public static void main(String[] argv) throws Exception { - ParsedArguments cmdLine = HELP_INFO.parse(argv); - - int port = DEFAULT_PORT; - if(argv.length > 0) - port = ARG_PORT.getInteger(cmdLine); - + public DebugCommand() { + super("Listen for connections from a remote debugger"); + registerArguments(ARG_PORT); + } + + public static void main(String[] args) throws Exception { + new DebugCommand().execute(args); + } + + @Override + public void execute(CommandLine commandLine, InputStream in, + PrintStream out, PrintStream err) throws Exception { + int port = ARG_PORT.isSet() ? ARG_PORT.getValue() : DEFAULT_PORT; + + // FIXME - in the even of internal exceptions, JDWP writes to System.out. final String ps = "transport=dt_socket,suspend=n,address=" + port + ",server=y"; Thread t = new Thread(new Runnable() { public void run() { @@ -40,24 +50,26 @@ jdwp.waitToFinish(); jdwp.shutdown(); } - //workaround for the restricted capabilities of JDWP support in GNU Classpath. + // workaround for the restricted capabilities of JDWP support in GNU Classpath. JNodeSocketTransport.ServerSocketHolder.close(); - up = true; } }); t.start(); - while (System.in.read() != 'q') { - System.out.println("Type 'q' for exitting."); + while (in.read() != 'q') { + out.println("Type 'q' to exit"); } + // FIXME - this just stops the 'debug' command. The listener will keep running + // until the remote debugger disconnects. We should have a way to disconnect at + // this end. down(); } - public static synchronized boolean up() { + public synchronized boolean up() { return up; } - public static synchronized void down() { + public synchronized void down() { up = false; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-05-02 14:34:13
|
Revision: 4040 http://jnode.svn.sourceforge.net/jnode/?rev=4040&view=rev Author: crawley Date: 2008-05-02 07:34:11 -0700 (Fri, 02 May 2008) Log Message: ----------- Overhaul 'udpout' (now 'remoteout') to support TCP and to work without messing with System.out,err ... which can be problematic. Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.debug.xml Added Paths: ----------- trunk/shell/src/shell/org/jnode/shell/command/debug/RemoteOutputCommand.java Removed Paths: ------------- trunk/shell/src/shell/org/jnode/shell/command/debug/UDPOutputCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.debug.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.debug.xml 2008-05-02 14:32:13 UTC (rev 4039) +++ trunk/shell/descriptors/org.jnode.shell.command.debug.xml 2008-05-02 14:34:11 UTC (rev 4040) @@ -29,12 +29,19 @@ <option argLabel="port" shortName="p" description="The port for the debugger to connect to"/> </optional> </syntax> + <syntax alias="remoteout"> + <optionSet description="Redirect output and logging to a remote receiver"> + <option argLabel="host" shortName="h" longName="host" description="The host for the remote receiver"/> + <option argLabel="port" shortName="p" longName="port" description="The port for the remote receiver"/> + <option argLabel="udp" shortName="u" longName="udp" description="If set use UDP, otherwise use TCP"/> + </optionSet> + </syntax> </extension> <extension point="org.jnode.security.permissions"> <permission class="java.lang.RuntimePermission" name="modifyThreadGroup"/> <permission class="java.lang.RuntimePermission" name="setIO"/> - <permission class="java.net.SocketPermission" name="*:1-" actions="resolve,listen"/> + <permission class="java.net.SocketPermission" name="*:1-" actions="resolve,listen,connect"/> </extension> </plugin> \ No newline at end of file Added: trunk/shell/src/shell/org/jnode/shell/command/debug/RemoteOutputCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/debug/RemoteOutputCommand.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/command/debug/RemoteOutputCommand.java 2008-05-02 14:34:11 UTC (rev 4040) @@ -0,0 +1,110 @@ +/* + * $Id: UDPOutputCommand.java 4032 2008-04-27 13:53:11Z crawley $ + * + * 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.command.debug; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintStream; +import java.net.ConnectException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.net.SocketAddress; +import java.net.UnknownHostException; + +import org.apache.log4j.Logger; +import org.jnode.debug.RemoteReceiver; +import org.jnode.debug.RemoteAppender; +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; +import org.jnode.shell.syntax.HostNameArgument; +import org.jnode.shell.syntax.IntegerArgument; + +/** + * @author Ewout Prangsma (ep...@us...) + * @author Martin Husted Hartvig (ha...@jn...) + * @author cr...@jn... + */ +public class RemoteOutputCommand extends AbstractCommand { + public static int DEFAULT_PORT = RemoteReceiver.DEFAULT_PORT; + + private final HostNameArgument ARG_ADDRESS = + new HostNameArgument("host", Argument.MANDATORY, "remote host running the receiver"); + + private final IntegerArgument ARG_PORT = + new IntegerArgument("port", Argument.OPTIONAL, "remote port for the receiver"); + + private final FlagArgument FLAG_UDP = + new FlagArgument("udp", Argument.OPTIONAL, "if set use udp, otherwise use tcp"); + + public RemoteOutputCommand() { + super("send data from System.out, System.err and the logger to a remote receiver"); + registerArguments(ARG_ADDRESS, ARG_PORT, FLAG_UDP); + } + + public void execute(CommandLine commandLine, InputStream in, + PrintStream out, PrintStream err) + throws Exception { + try { + final int port = ARG_PORT.isSet() ? ARG_PORT.getValue() : DEFAULT_PORT; + final InetAddress addr = ARG_ADDRESS.getAsInetAddress(); + final SocketAddress sockAddr = new InetSocketAddress(addr, port); + final boolean udp = FLAG_UDP.isSet(); + OutputStream remoteOut = udp ? new UDPOutputStream(sockAddr) : + createTCPOutputStream(addr, port); + + try { + ShellUtils.getCurrentShell().addConsoleOuputRecorder(remoteOut); + } + catch (UnsupportedOperationException ex) { + err.println("Cannot capture output from the current shell"); + remoteOut.close(); + exit(2); + } + // FIXME ... we cannot do this for TCP because it triggers a + // kernel panic. I suspect that this is something to do with + // the TCP protocol stack itself trying to log debug messages. + if (udp) { + final Logger root = Logger.getRootLogger(); + root.addAppender(new RemoteAppender(remoteOut, null)); + } + } + catch (ConnectException ex) { + err.println("Connection failed: " + ex.getMessage()); + exit(1); + } + catch (UnknownHostException ex) { + err.println("Unknown host: " + ex.getMessage()); + exit(1); + } + } + + private OutputStream createTCPOutputStream(InetAddress addr, int port) throws IOException { + Socket socket = new Socket(addr, port); + return socket.getOutputStream(); + } +} Deleted: trunk/shell/src/shell/org/jnode/shell/command/debug/UDPOutputCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/debug/UDPOutputCommand.java 2008-05-02 14:32:13 UTC (rev 4039) +++ trunk/shell/src/shell/org/jnode/shell/command/debug/UDPOutputCommand.java 2008-05-02 14:34:11 UTC (rev 4040) @@ -1,155 +0,0 @@ -/* - * $Id$ - * - * 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.command.debug; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintStream; -import java.net.InetSocketAddress; -import java.net.SocketAddress; - -import org.apache.log4j.Logger; -import org.jnode.debug.UDPAppender; -import org.jnode.debug.UDPOutputStream; -import org.jnode.shell.AbstractCommand; -import org.jnode.shell.CommandLine; -import org.jnode.shell.help.Help; -import org.jnode.shell.help.Parameter; -import org.jnode.shell.help.ParsedArguments; -import org.jnode.shell.help.argument.InetAddressArgument; -import org.jnode.shell.help.argument.IntegerArgument; - -/** - * @author Ewout Prangsma (ep...@us...) - * @author Martin Husted Hartvig (ha...@jn...) - */ -public class UDPOutputCommand extends AbstractCommand { - - private static final InetAddressArgument ARG_ADDRESS = - new InetAddressArgument("host", "connect host to the udpreceiver"); - - private static final IntegerArgument ARG_PORT = - new IntegerArgument("port", "port to connect on"); - - private static final Parameter PARAM_ADDRESS = - new Parameter(ARG_ADDRESS, Parameter.MANDATORY); - - private static final Parameter PARAM_PORT = - new Parameter(ARG_PORT, Parameter.OPTIONAL); - - public static Help.Info HELP_INFO = - new Help.Info("udpout", - "send data from System.out and System.err to remote host", - new Parameter[] { PARAM_ADDRESS, PARAM_PORT }); - - public void execute(CommandLine commandLine, InputStream in, - PrintStream out, PrintStream err) throws Exception { - - final ParsedArguments args = HELP_INFO.parse(commandLine); - - final int port; - - if (PARAM_PORT.isSet(args)) { - port = ARG_PORT.getInteger(args); - } else { - port = 5612; - } - - final SocketAddress address = - new InetSocketAddress(ARG_ADDRESS.getAddress(args), port); - UDPOutputStream udpOut = new UDPOutputStream(address); - - DupOutputStream dupOut = new DupOutputStream(System.out, udpOut); - PrintStream ps = new PrintStream(dupOut); - System.setOut(ps); - System.setErr(ps); - - final Logger root = Logger.getRootLogger(); - root.addAppender(new UDPAppender(udpOut, null)); - } - - static class DupOutputStream extends OutputStream { - - private final OutputStream os1; - private final OutputStream os2; - - public DupOutputStream(OutputStream os1, OutputStream os2) { - this.os1 = os1; - this.os2 = os2; - } - - /** - * @see java.io.OutputStream#close() - * @throws IOException - */ - public void close() throws IOException { - os1.close(); - os2.close(); - } - - /** - * @see java.io.OutputStream#flush() - * @throws IOException - */ - public void flush() throws IOException { - os1.flush(); - os2.flush(); - } - - /** - * @param b - * @param off - * @param len - * @see java.io.OutputStream#write(byte[], int, int) - * @throws IOException - * @throws NullPointerException - * @throws IndexOutOfBoundsException - */ - public void write(byte[] b, int off, int len) throws IOException, - NullPointerException, IndexOutOfBoundsException { - os1.write(b, off, len); - os2.write(b, off, len); - } - - /** - * @param b - * @see java.io.OutputStream#write(byte[]) - * @throws IOException - * @throws NullPointerException - */ - public void write(byte[] b) throws IOException, NullPointerException { - os1.write(b); - os2.write(b); - } - - /** - * @param b - * @see java.io.OutputStream#write(int) - * @throws IOException - */ - public void write(int b) throws IOException { - os1.write(b); - os2.write(b); - } - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-05-03 07:58:29
|
Revision: 4044 http://jnode.svn.sourceforge.net/jnode/?rev=4044&view=rev Author: crawley Date: 2008-05-03 00:58:28 -0700 (Sat, 03 May 2008) Log Message: ----------- Converted DeviceCommand Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.driver.xml trunk/shell/src/shell/org/jnode/shell/command/driver/DeviceCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.driver.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.driver.xml 2008-05-03 07:57:28 UTC (rev 4043) +++ trunk/shell/descriptors/org.jnode.shell.command.driver.xml 2008-05-03 07:58:28 UTC (rev 4044) @@ -22,6 +22,17 @@ <alias name="device" class="org.jnode.shell.command.driver.DeviceCommand"/> </extension> + <extension point="org.jnode.shell.syntaxes"> + <syntax alias="device"> + <empty description="Show all devices"/> + <argument argLabel="device" description="Show a specific device"/> + <sequence description="Perform an action on a device"> + <argument argLabel="action"/> + <argument argLabel="device"/> + </sequence> + </syntax> + </extension> + <extension point="org.jnode.security.permissions"> <permission class="java.util.PropertyPermission" name="user.dir" actions="read"/> </extension> Modified: trunk/shell/src/shell/org/jnode/shell/command/driver/DeviceCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/driver/DeviceCommand.java 2008-05-03 07:57:28 UTC (rev 4043) +++ trunk/shell/src/shell/org/jnode/shell/command/driver/DeviceCommand.java 2008-05-03 07:58:28 UTC (rev 4044) @@ -21,6 +21,7 @@ package org.jnode.shell.command.driver; +import java.io.InputStream; import java.io.PrintStream; import java.io.PrintWriter; import java.util.TreeMap; @@ -35,128 +36,139 @@ import org.jnode.driver.DeviceNotFoundException; import org.jnode.driver.DriverException; import org.jnode.naming.InitialNaming; -import org.jnode.shell.help.Help; -import org.jnode.shell.help.Parameter; -import org.jnode.shell.help.ParsedArguments; -import org.jnode.shell.help.Syntax; -import org.jnode.shell.help.argument.DeviceArgument; -import org.jnode.shell.help.argument.OptionArgument; +import org.jnode.shell.AbstractCommand; +import org.jnode.shell.CommandLine; +import org.jnode.shell.syntax.*; /** * @author epr + * @author cr...@jn... */ -public class DeviceCommand { +public class DeviceCommand extends AbstractCommand { + private static final int START = 0; + private static final int STOP = 1; + private static final int RESTART = 2; + private static final int REMOVE = 3; + + private static enum Action { + start(START), stop(STOP), restart(RESTART), remove(REMOVE); + + public final int no; + + Action(int no) { + this.no = no; + } + } + + private static class ActionArgument extends EnumArgument<Action> { + public ActionArgument() { + super("action", Argument.OPTIONAL, Action.class, "action to be performed on device"); + } - static final OptionArgument ARG_ACTION = - new OptionArgument( - "action", - "action to do on the device", - new OptionArgument.Option[] { - new OptionArgument.Option("restart", "Restart device"), - new OptionArgument.Option("stop", "Stop device"), - new OptionArgument.Option("start", "Start device"), - new OptionArgument.Option("remove", "Remove a device")}); + @Override + protected String argumentKind() { + return "{start,stop,restart,remove}"; + } + } + + private static ActionArgument ARG_ACTION = new ActionArgument(); - static final DeviceArgument ARG_DEVICE = new DeviceArgument("device-id", "the device to print informations about"); - static final Parameter PARAM_ACTION = new Parameter(ARG_ACTION, Parameter.MANDATORY); + private final DeviceArgument ARG_DEVICE = + new DeviceArgument("device", Argument.OPTIONAL, "the target device"); + + public DeviceCommand() { + super("Examine or manage a device"); + registerArguments(ARG_ACTION, ARG_DEVICE); + } - static final Parameter PARAM_DEVICE = new Parameter(ARG_DEVICE, Parameter.MANDATORY); - - public static Help.Info HELP_INFO = - new Help.Info( - "device", - new Syntax[] { - new Syntax("Print information about all devices"), - new Syntax("Print information about a specific device", new Parameter[] { PARAM_DEVICE }), - new Syntax("Execute a command on a device", new Parameter[] { PARAM_ACTION, PARAM_DEVICE }) - }); - public static void main(String[] args) throws Exception { - ParsedArguments cmdLine = HELP_INFO.parse(args); + new DeviceCommand().execute(args); + } - if (PARAM_ACTION.isSet(cmdLine)) { - String action = ARG_ACTION.getValue(cmdLine); - if (action.compareTo("restart") == 0) { - restartDevice(ARG_DEVICE.getDevice(cmdLine)); - } else if (action.compareTo("start") == 0) { - startDevice(ARG_DEVICE.getDevice(cmdLine)); - } else if (action.compareTo("stop") == 0) { - stopDevice(ARG_DEVICE.getDevice(cmdLine)); - } else if (action.compareTo("remove") == 0) { - removeDevice(ARG_DEVICE.getDevice(cmdLine)); - } - return; - } - - if (!PARAM_DEVICE.isSet(cmdLine)) { - showDevices(System.out); - } else { - showDevice(System.out, ARG_DEVICE.getDevice(cmdLine)); - } + @Override + public void execute(CommandLine commandLine, InputStream in, + PrintStream out, PrintStream err) throws Exception { + if (ARG_ACTION.isSet()) { + if (!ARG_DEVICE.isSet()) { + err.println("No target device specified"); + exit(1); + } + switch (ARG_ACTION.getValue().no) { + case RESTART: + restartDevice(ARG_DEVICE.getValue()); + break; + case START: + startDevice(ARG_DEVICE.getValue()); + break; + case STOP: + stopDevice(ARG_DEVICE.getValue()); + break; + case REMOVE: + removeDevice(ARG_DEVICE.getValue()); + break; + } + } + else if (ARG_DEVICE.isSet()) { + showDevice(System.out, ARG_DEVICE.getValue()); + } + else { + showDevices(System.out); + } } /** + * Stop the given device. * @param device + * @throws DriverException + * @throws DeviceNotFoundException */ - private static void stopDevice(Device device) { - try { - device.getManager().stop(device); - } catch (DriverException e) { - e.printStackTrace(); - } catch (DeviceNotFoundException ex) { - ex.printStackTrace(); - } + private void stopDevice(Device device) + throws DeviceNotFoundException, DriverException { + device.getManager().stop(device); } /** * Stop and Remove the given device. * @param device + * @throws DriverException + * @throws DeviceNotFoundException */ - private static void removeDevice(Device device) { - try { - device.getManager().stop(device); - device.getManager().unregister(device); - } catch (DriverException e) { - e.printStackTrace(); - } catch (DeviceNotFoundException ex) { - ex.printStackTrace(); - } + private void removeDevice(Device device) + throws DeviceNotFoundException, DriverException { + device.getManager().stop(device); + device.getManager().unregister(device); } /** + * Start the given device * @param device + * @throws DriverException + * @throws DeviceNotFoundException */ - private static void startDevice(Device device) { - try { - device.getManager().start(device); - } catch (DriverException e) { - e.printStackTrace(); - } catch (DeviceNotFoundException ex) { - ex.printStackTrace(); - } + private void startDevice(Device device) + throws DeviceNotFoundException, DriverException { + device.getManager().start(device); } /** + * Stop and start the given device. * @param device + * @throws DriverException + * @throws DeviceNotFoundException */ - private static void restartDevice(Device device) { - try { - device.getManager().stop(device); - device.getManager().start(device); - } catch (DriverException e) { - e.printStackTrace(); - } catch (DeviceNotFoundException ex) { - ex.printStackTrace(); - } + private void restartDevice(Device device) + throws DeviceNotFoundException, DriverException { + device.getManager().stop(device); + device.getManager().start(device); } /** - * Show all info of the device with a given name + * Display information about a given device * * @param out * @param dev */ - protected static void showDevice(PrintStream out, Device dev) { + protected void showDevice(PrintStream out, Device dev) { final String prefix = " "; out.println("Device: " + dev.getId()); final String drvClassName = dev.getDriverClassName(); @@ -190,12 +202,12 @@ } /** - * Show all devices + * Display information about all devices * * @param out * @throws NameNotFoundException */ - protected static void showDevices(PrintStream out) throws NameNotFoundException { + protected void showDevices(PrintStream out) throws NameNotFoundException { // Create a sorted list final TreeMap<String, Device> tm = new TreeMap<String, Device>(); final DeviceManager dm = InitialNaming.lookup(DeviceManager.NAME); @@ -219,5 +231,4 @@ out.println(); } } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-05-03 14:37:31
|
Revision: 4047 http://jnode.svn.sourceforge.net/jnode/?rev=4047&view=rev Author: crawley Date: 2008-05-03 07:37:29 -0700 (Sat, 03 May 2008) Log Message: ----------- Converted ClearConsoleCommand Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.driver.console.xml trunk/shell/src/shell/org/jnode/shell/command/driver/console/ClearConsoleCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.driver.console.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.driver.console.xml 2008-05-03 14:26:33 UTC (rev 4046) +++ trunk/shell/descriptors/org.jnode.shell.command.driver.console.xml 2008-05-03 14:37:29 UTC (rev 4047) @@ -22,6 +22,12 @@ <alias name="console" class="org.jnode.shell.command.driver.console.ConsoleCommand"/> <alias name="clear" class="org.jnode.shell.command.driver.console.ClearConsoleCommand"/> </extension> + + <extension point="org.jnode.shell.syntaxes"> + <syntax alias="clear"> + <empty description="Clear the console"/> + </syntax> + </extension> <extension point="org.jnode.security.permissions"> <permission class="java.io.FilePermission" name="<<ALL FILES>>" actions="read,write"/> 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-05-03 14:26:33 UTC (rev 4046) +++ trunk/shell/src/shell/org/jnode/shell/command/driver/console/ClearConsoleCommand.java 2008-05-03 14:37:29 UTC (rev 4047) @@ -21,34 +21,40 @@ package org.jnode.shell.command.driver.console; -import javax.naming.NameNotFoundException; +import java.io.InputStream; +import java.io.PrintStream; import org.jnode.driver.console.TextConsole; -import org.jnode.naming.InitialNaming; -import org.jnode.shell.ShellException; -import org.jnode.shell.ShellManager; -import org.jnode.shell.help.Help; -import org.jnode.shell.help.Parameter; -import org.jnode.shell.help.Syntax; +import org.jnode.shell.AbstractCommand; +import org.jnode.shell.CommandLine; +import org.jnode.shell.Shell; +import org.jnode.shell.ShellUtils; /** + * This command clears the console. + * * @author Jacob Kofod */ -public class ClearConsoleCommand { +public class ClearConsoleCommand extends AbstractCommand { - public static Help.Info HELP_INFO = - new Help.Info("clear", new Syntax[] { new Syntax("Clear console screen", new Parameter[] {}), } - ); + public ClearConsoleCommand() { + super("Clear console screen"); + } /** * Clear console screen * * @param args no arguments. */ - public static void main(String[] args) - throws NameNotFoundException, ShellException { - final ShellManager sm = InitialNaming.lookup(ShellManager.NAME); - TextConsole tc = (TextConsole) sm.getCurrentShell().getConsole(); + public static void main(String[] args) throws Exception { + new ClearConsoleCommand().execute(args); + } + + @Override + public void execute(CommandLine commandLine, InputStream in, + PrintStream out, PrintStream err) throws Exception { + final Shell shell = ShellUtils.getCurrentShell(); + TextConsole tc = (TextConsole) shell.getConsole(); tc.clear(); tc.setCursor(0, 0); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-05-03 15:37:06
|
Revision: 4049 http://jnode.svn.sourceforge.net/jnode/?rev=4049&view=rev Author: crawley Date: 2008-05-03 08:37:04 -0700 (Sat, 03 May 2008) Log Message: ----------- Converted ConsoleCommand Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.driver.console.xml trunk/shell/src/shell/org/jnode/shell/command/driver/console/ConsoleCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.driver.console.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.driver.console.xml 2008-05-03 14:41:25 UTC (rev 4048) +++ trunk/shell/descriptors/org.jnode.shell.command.driver.console.xml 2008-05-03 15:37:04 UTC (rev 4049) @@ -27,6 +27,14 @@ <syntax alias="clear"> <empty description="Clear the console"/> </syntax> + <syntax alias="console"> + <option argLabel="list" shortName="l" longName="list" description="List the registered consoles"/> + <sequence description="Start a new console"> + <option argLabel="new" shortName="n" longName="new"/> + <optional><option argLabel="isolated" shortName="i" longName="isolated"/></optional> + </sequence> + <option argLabel="test" shortName="t" longName="test" description="Start a raw text console (test)"/> + </syntax> </extension> <extension point="org.jnode.security.permissions"> 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-05-03 14:41:25 UTC (rev 4048) +++ trunk/shell/src/shell/org/jnode/shell/command/driver/console/ConsoleCommand.java 2008-05-03 15:37:04 UTC (rev 4049) @@ -21,6 +21,7 @@ package org.jnode.shell.command.driver.console; +import java.io.InputStream; import java.io.PrintStream; import javax.isolate.Isolate; @@ -30,83 +31,80 @@ import org.jnode.driver.console.ConsoleManager; 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; -import org.jnode.shell.help.Argument; -import org.jnode.shell.help.Help; -import org.jnode.shell.help.Parameter; -import org.jnode.shell.help.Syntax; +import org.jnode.shell.syntax.*; /** + * ConsoleCommand starts a new console. + * * @author vali + * @author cr...@jn... */ -public class ConsoleCommand { +public class ConsoleCommand extends AbstractCommand { - private static Parameter ListParameter = new Parameter(new Argument("-l", - "list all registered consoles", false), Parameter.OPTIONAL); + private final FlagArgument FLAG_LIST = + new FlagArgument("list", Argument.OPTIONAL, + "if set, list all registered consoles"); + + private final FlagArgument FLAG_NEW = + new FlagArgument("new", Argument.OPTIONAL, + "if set, create a new console"); - private static Parameter NewUserConsoleParameter = new Parameter( - new Argument("-n", "create new Shell Console", false), - Parameter.OPTIONAL); + private final FlagArgument FLAG_ISOLATED = + new FlagArgument("isolated", Argument.OPTIONAL, + "if set, create the new console in an isolate"); + + private final FlagArgument FLAG_TEST = + new FlagArgument("test", Argument.OPTIONAL, + "if set, create a raw text console (test)"); - private static Parameter IsolateNewConsoleParameter = new Parameter( - new Argument("-i", "Isolate new Shell Console", false), - Parameter.OPTIONAL); + public ConsoleCommand() { + super("Console administration"); + registerArguments(FLAG_ISOLATED, FLAG_LIST, FLAG_NEW, FLAG_TEST); + } - public static Help.Info HELP_INFO = new Help.Info("console", - new Syntax[] { new Syntax("Console administration", - new Parameter[] { ListParameter, NewUserConsoleParameter, - IsolateNewConsoleParameter }), }); + public static void main(String[] args) throws Exception { + new ConsoleCommand().execute(args); + } - /** - * Displays the system date - * - * @param args - * No arguments. - */ - public static void main(String[] args) throws NameNotFoundException, - ShellException { + @Override + public void execute(CommandLine commandLine, InputStream in, + PrintStream out, PrintStream err) + throws NameNotFoundException, IsolateStartupException, ShellException { final ShellManager sm = InitialNaming.lookup(ShellManager.NAME); final ConsoleManager conMgr = sm.getCurrentShell().getConsole().getManager(); - boolean listConsoles = false; - boolean newConsole = false; - boolean isolateNewConsole = false; + boolean listConsoles = FLAG_LIST.isSet(); + boolean newConsole = FLAG_NEW.isSet(); + boolean isolateNewConsole = FLAG_ISOLATED.isSet(); + boolean test = FLAG_TEST.isSet(); - System.out.print("args: "); - for (String arg : args) { - System.out.print(arg); - if (arg.equals("-l")) { - listConsoles = true; - } else if (arg.equals("-n")) { - newConsole = true; - } else if (arg.equals("-i")) { - isolateNewConsole = true; - } - } - System.out.println(); - if (listConsoles) { conMgr.printConsoles(System.out); - } else if (newConsole) { + } + else if (newConsole) { if (isolateNewConsole) { try { Isolate newIsolate = new Isolate( ConsoleCommand.IsolatedConsole.class.getName(), new String[0]); newIsolate.start(); - System.out.println("Started new isolated console"); + out.println("Started new isolated console"); } catch (IsolateStartupException ex) { - System.out.println("Failed to start new isolated console"); - ex.printStackTrace(System.err); + out.println("Failed to start new isolated console"); + throw ex; } } else { - createConsoleWithShell(conMgr); + createConsoleWithShell(conMgr, out); } - } else { - System.out.println("test RawTextConsole"); + } + else if (test) { + out.println("test RawTextConsole"); final TextConsole console = (TextConsole) conMgr.createConsole( null, ConsoleManager.CreateOptions.TEXT | ConsoleManager.CreateOptions.NO_LINE_EDITTING); conMgr.registerConsole(console); @@ -116,12 +114,15 @@ } private static class IsolatedConsole { - + /** + * This will be the entry point for the isolate. + * @param args + */ public static void main(String[] args) { try { final ShellManager sm = InitialNaming.lookup(ShellManager.NAME); final ConsoleManager conMgr = sm.getCurrentShell().getConsole().getManager(); - TextConsole console = createConsoleWithShell(conMgr); + TextConsole console = createConsoleWithShell(conMgr, System.out); System.setIn(console.getIn()); System.setOut(new PrintStream(console.getOut())); System.setErr(new PrintStream(console.getErr())); @@ -134,16 +135,14 @@ } } - private static TextConsole createConsoleWithShell(final ConsoleManager conMgr) + private static TextConsole createConsoleWithShell(final ConsoleManager conMgr, PrintStream out) throws ShellException { - final TextConsole console = (TextConsole) conMgr.createConsole( - null, ConsoleManager.CreateOptions.TEXT - | ConsoleManager.CreateOptions.SCROLLABLE); + final TextConsole console = (TextConsole) conMgr.createConsole(null, + ConsoleManager.CreateOptions.TEXT | ConsoleManager.CreateOptions.SCROLLABLE); CommandShell commandShell = new CommandShell(console); new Thread(commandShell, "command-shell").start(); - System.out.println("New console created with name: " - + console.getConsoleName()); + out.println("New console created with name: " + console.getConsoleName()); // FIXME we shouldn't be setting the invoker (and interpreter) via the System Properties // object because it is "global" in some operation modes, and we want to be able to This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-05-04 05:21:56
|
Revision: 4051 http://jnode.svn.sourceforge.net/jnode/?rev=4051&view=rev Author: crawley Date: 2008-05-03 22:21:52 -0700 (Sat, 03 May 2008) Log Message: ----------- Converted AcpiCommand. (Seems to work, but ACPI is not fully implemented.) Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.driver.system.acpi.xml trunk/shell/src/shell/org/jnode/shell/command/driver/system/acpi/AcpiCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.driver.system.acpi.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.driver.system.acpi.xml 2008-05-03 18:17:04 UTC (rev 4050) +++ trunk/shell/descriptors/org.jnode.shell.command.driver.system.acpi.xml 2008-05-04 05:21:52 UTC (rev 4051) @@ -24,4 +24,13 @@ <alias name="smbus" class="org.jnode.shell.command.driver.system.acpi.SMBusCommand"/> </extension> + <extension point="org.jnode.shell.syntaxes"> + <syntax alias="acpi"> + <empty description="Print a summary of each ACPI device"/> + <option argLabel="dump" shortName="d" longName="dump" + description="Produce a full dump for each ACPI device"/> + <option argLabel="battery" shortName="b" longName="battery" + description="Display battery information for each ACPI device"/> + </syntax> + </extension> </plugin> \ No newline at end of file Modified: trunk/shell/src/shell/org/jnode/shell/command/driver/system/acpi/AcpiCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/driver/system/acpi/AcpiCommand.java 2008-05-03 18:17:04 UTC (rev 4050) +++ trunk/shell/src/shell/org/jnode/shell/command/driver/system/acpi/AcpiCommand.java 2008-05-04 05:21:52 UTC (rev 4051) @@ -21,68 +21,69 @@ package org.jnode.shell.command.driver.system.acpi; +import java.io.InputStream; +import java.io.PrintStream; import java.io.PrintWriter; import java.util.Collection; +import org.jnode.driver.ApiNotFoundException; import org.jnode.driver.Device; import org.jnode.driver.DeviceUtils; import org.jnode.driver.system.acpi.AcpiAPI; -import org.jnode.shell.help.Help; -import org.jnode.shell.help.Parameter; -import org.jnode.shell.help.ParsedArguments; -import org.jnode.shell.help.Syntax; -import org.jnode.shell.help.argument.OptionArgument; +import org.jnode.shell.AbstractCommand; +import org.jnode.shell.CommandLine; +import org.jnode.shell.syntax.Argument; +import org.jnode.shell.syntax.FlagArgument; /** - * ACPI command. + * ACPI display and management command. * * @author Ewout Prangsma (ep...@us...) + * @author cr...@jn... */ -public class AcpiCommand { +public class AcpiCommand extends AbstractCommand { + private final FlagArgument FLAG_DUMP = + new FlagArgument("dump", Argument.OPTIONAL, + "lists all devices that can be discovered and controlled through ACPI"); + + private final FlagArgument FLAG_BATTERY = + new FlagArgument("battery", Argument.OPTIONAL, + "displays information about installed batteries"); + public AcpiCommand() { + super("display and (in the future) manage the ACPI system"); + registerArguments(FLAG_BATTERY, FLAG_DUMP); } - static final String FUNC_DUMP = "dump"; - - static final String FUNC_BATTERY = "battery"; - - static final OptionArgument ARG_FUNCTION = new OptionArgument( - "function", - "the function to perform", - new OptionArgument.Option[] { - new OptionArgument.Option(FUNC_DUMP, - "lists all devices that can be discovered and controlled through ACPI"), - new OptionArgument.Option(FUNC_BATTERY, - "displays information about installed batteries") }); - - public static Help.Info HELP_INFO = new Help.Info("acpi", new Syntax[] { - new Syntax("displays ACPI details"), - new Syntax("manage ACPI system", new Parameter[] { new Parameter( - ARG_FUNCTION, Parameter.OPTIONAL) }) }); - public static void main(String[] args) throws Exception { - - ParsedArguments cmdLine = HELP_INFO.parse(args); - + new AcpiCommand().execute(args); + } + + @Override + public void execute(CommandLine commandLine, InputStream in, + PrintStream out, PrintStream err) throws ApiNotFoundException { final Collection<Device> acpiDevs = DeviceUtils.getDevicesByAPI(AcpiAPI.class); if (acpiDevs.isEmpty()) { - System.out.println("Could not connect to ACPI"); - } else { - final Device dev = (Device)acpiDevs.iterator().next(); - final AcpiAPI api = (AcpiAPI)dev.getAPI(AcpiAPI.class); + out.println("No ACPI devices are registered"); + exit(1); + } + else { + for (Device dev : acpiDevs) { + final AcpiAPI api = (AcpiAPI) dev.getAPI(AcpiAPI.class); - if (cmdLine.size() == 0) { - System.out.println(api.toDetailedString()); - } else { - String func = ARG_FUNCTION.getValue(cmdLine); - if (func.equalsIgnoreCase(FUNC_DUMP)) { - api.dump(new PrintWriter(System.out)); - } else if (func.equalsIgnoreCase(FUNC_BATTERY)) { - System.out.println("Temporary disabled; TODO fix me"); + if (FLAG_DUMP.isSet()) { + api.dump(new PrintWriter(out)); + } + else if (FLAG_BATTERY.isSet()) { + // TODO fix this + out.println("The '--battery' option is temporary disabled"); //api.dumpBattery(); } + else { + out.println(api.toDetailedString()); + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-05-04 13:58:01
|
Revision: 4053 http://jnode.svn.sourceforge.net/jnode/?rev=4053&view=rev Author: crawley Date: 2008-05-04 06:57:57 -0700 (Sun, 04 May 2008) Log Message: ----------- Converted and enhanced Log4jCommand Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.log4j.xml trunk/shell/src/shell/org/jnode/shell/command/log4j/Log4jCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.log4j.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.log4j.xml 2008-05-04 06:19:17 UTC (rev 4052) +++ trunk/shell/descriptors/org.jnode.shell.command.log4j.xml 2008-05-04 13:57:57 UTC (rev 4053) @@ -21,6 +21,20 @@ <extension point="org.jnode.shell.aliases"> <alias name="log4j" class="org.jnode.shell.command.log4j.Log4jCommand"/> </extension> + + <extension point="org.jnode.shell.syntaxes"> + <syntax alias="log4j"> + <option argLabel="list" shortName="l" longName="list" description="List all existing loggers"/> + <sequence description="Set the logging level for a logger"> + <option argLabel="setLevel" shortName="s" longName="setLevel"/> + <argument argLabel="logger"/> + <argument argLabel="level"/> + </sequence> + <option argLabel="url" shortName="u" longName="url" description="Load log4j configuration from a URL"/> + <argument argLabel="file" description="Load log4j configuration from a file"/> + </syntax> + </extension> + <extension point="org.jnode.security.permissions"> <permission class="java.io.FilePermission" name="<<ALL FILES>>" actions="read"/> Modified: trunk/shell/src/shell/org/jnode/shell/command/log4j/Log4jCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/log4j/Log4jCommand.java 2008-05-04 06:19:17 UTC (rev 4052) +++ trunk/shell/src/shell/org/jnode/shell/command/log4j/Log4jCommand.java 2008-05-04 13:57:57 UTC (rev 4053) @@ -23,89 +23,144 @@ import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; +import java.io.PrintStream; +import java.net.MalformedURLException; import java.net.URL; +import java.util.Enumeration; import java.util.Properties; import org.apache.log4j.Level; +import org.apache.log4j.LogManager; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; -import org.jnode.shell.help.Help; -import org.jnode.shell.help.Parameter; -import org.jnode.shell.help.ParsedArguments; -import org.jnode.shell.help.Syntax; -import org.jnode.shell.help.SyntaxErrorException; -import org.jnode.shell.help.argument.FileArgument; -import org.jnode.shell.help.argument.OptionArgument; -import org.jnode.shell.help.argument.StringArgument; -import org.jnode.shell.help.argument.URLArgument; +import org.jnode.shell.AbstractCommand; +import org.jnode.shell.CommandLine; +import org.jnode.shell.syntax.Argument; +import org.jnode.shell.syntax.EnumArgument; +import org.jnode.shell.syntax.FileArgument; +import org.jnode.shell.syntax.FlagArgument; +import org.jnode.shell.syntax.StringArgument; +import org.jnode.shell.syntax.URLArgument; /** + * This command manages log4j logging. + * * @author Ewout Prangsma (ep...@us...) * @author Fabien DUMINY (fd...@jn...) + * @author cr...@jn... */ -public class Log4jCommand { - static final OptionArgument ARG_ACTION = new OptionArgument("action", - "action to do on log4j", - new OptionArgument.Option("level", "Change the level of a logger"), - new OptionArgument.Option("url", "Configure log4j from an url"), - new OptionArgument.Option("file", "Configure log4j from a file")); +public class Log4jCommand extends AbstractCommand { + // FIXME ... turn the following into a free standing class that accepts + // the log level in a case-insensitive fashion. + private enum LevelEnum { + all(Level.ALL), + // trace(Level.TRACE), // introduced in log4j 1.2.12 + debug(Level.DEBUG), + info(Level.INFO), + warn(Level.WARN), + error(Level.ERROR), + fatal(Level.FATAL), + off(Level.OFF); + + public final Level level; + LevelEnum(Level level) { + this.level = level; + } + }; - static final OptionArgument ARG_LEVEL = - new OptionArgument( - "level", - "minimum level", - new OptionArgument.Option[] { - new OptionArgument.Option("debug", "Debug"), - new OptionArgument.Option("info", "Info"), - new OptionArgument.Option("warn", "Warning"), - new OptionArgument.Option("error", "Error"), - new OptionArgument.Option("fatal", "Fatal")}); - - static final StringArgument ARG_LOGGER = new StringArgument("logger", "the name of the logger"); + private class LogLevelArgument extends EnumArgument<LevelEnum> { + public LogLevelArgument() { + super("level", Argument.OPTIONAL, LevelEnum.class, "the logging level"); + } + + @Override + protected String argumentKind() { + return "logging level"; + } + } - static final FileArgument ARG_CFG_FILE = new FileArgument("configFile", "the configuration file"); - static final URLArgument ARG_CFG_URL = new URLArgument("configURL", "the configuration URL"); + private final FlagArgument FLAG_LIST = + new FlagArgument("list", Argument.OPTIONAL, "List current loggers"); - static final Parameter PARAM_ACTION = new Parameter(ARG_ACTION); - static final Parameter PARAM_LOGGER = new Parameter(ARG_LOGGER, Parameter.MANDATORY); - static final Parameter PARAM_LEVEL = new Parameter(ARG_LEVEL, Parameter.MANDATORY); + private final FlagArgument FLAG_SET_LEVEL = + new FlagArgument("setLevel", Argument.OPTIONAL, "Set the Level of a logger"); - static final Parameter PARAM_CFG_FILE = new Parameter(ARG_CFG_FILE, Parameter.MANDATORY); - static final Parameter PARAM_CFG_URL = new Parameter(ARG_CFG_URL, Parameter.MANDATORY); + private final FileArgument ARG_FILE = + new FileArgument("file", Argument.OPTIONAL, "log4j configuration file"); + + private final URLArgument ARG_URL = + new URLArgument("url", Argument.OPTIONAL, "URL for log4j configuration file"); + + private final LogLevelArgument ARG_LEVEL = new LogLevelArgument(); + + // FIXME this should have a custom Argument class so that it can do completion. + private final StringArgument ARG_LOGGER = + new StringArgument("logger", Argument.OPTIONAL, "the name of the logger"); + + public Log4jCommand() { + super("manage log4j logging"); + registerArguments(FLAG_SET_LEVEL, FLAG_LIST, ARG_FILE, ARG_LEVEL, ARG_LOGGER, ARG_URL); + } - public static Help.Info HELP_INFO = new Help.Info("log4j", new Syntax[] - { - new Syntax("Set the level for a logger", new Parameter[] { PARAM_LOGGER, PARAM_LEVEL }), - new Syntax("Set the configuration from a file", new Parameter[] { PARAM_CFG_FILE }), - new Syntax("Set the configuration from an url", new Parameter[] { PARAM_CFG_URL }) - }); - - public static void main(String[] args) throws SyntaxErrorException, IOException { - final ParsedArguments cmdLine = HELP_INFO.parse(args); - - if(PARAM_CFG_FILE.isSet(cmdLine)) - { - final File configFile = ARG_CFG_FILE.getFile(cmdLine); - final Properties props = new Properties(); - final FileInputStream fis = new FileInputStream(configFile); - props.load(fis); - PropertyConfigurator.configure(props); - fis.close(); + public static void main(String[] args) throws Exception { + new Log4jCommand().execute(args); + } + + @Override + public void execute(CommandLine commandLine, InputStream in, + PrintStream out, PrintStream err) throws IOException { + if (ARG_FILE.isSet()) { + // Set configuration from a file + final File configFile = ARG_FILE.getValue(); + final Properties props = new Properties(); + FileInputStream fis = null; + try { + fis = new FileInputStream(configFile); + props.load(fis); + PropertyConfigurator.configure(props); + } + catch (FileNotFoundException ex) { + err.println("Cannot open configuration file '" + + configFile + "': " + ex.getMessage()); + exit(1); + } + finally { + if (fis != null) { + fis.close(); + } + } + } + else if (ARG_URL.isSet()) { + // Set configuration from a URL + try { + final URL configURL = new URL(ARG_URL.getValue()); + PropertyConfigurator.configure(configURL); + } + catch (MalformedURLException ex) { + err.println("Malformed configuration URL: " + ex.getMessage()); + exit(1); + } } - else if(PARAM_CFG_URL.isSet(cmdLine)) - { - final URL configURL = ARG_CFG_URL.getURL(cmdLine); - PropertyConfigurator.configure(configURL); + else if (FLAG_LIST.isSet()) { + Enumeration<?> en = LogManager.getCurrentLoggers(); + while (en.hasMoreElements()) { + Logger logger = (Logger) en.nextElement(); + String level = (logger.getLevel() == null) ? + ("(" + logger.getEffectiveLevel().toString() + ")") : + logger.getLevel().toString(); + out.println(logger.getName() + ": " + level); + } } - else - { - final String loggerName = ARG_LOGGER.getValue(cmdLine); - final String levelName = ARG_LEVEL.getValue(cmdLine); + else if (FLAG_SET_LEVEL.isSet()){ + // Change the logging level for a specified logger + // FIXME support changing the root logger's level + final String loggerName = ARG_LOGGER.getValue(); + final LevelEnum level = ARG_LEVEL.getValue(); final Logger log = Logger.getLogger(loggerName); - final Level level = Level.toLevel(levelName.toUpperCase()); - - log.setLevel(level); + log.setLevel(level.level); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-05-05 04:14:04
|
Revision: 4056 http://jnode.svn.sourceforge.net/jnode/?rev=4056&view=rev Author: crawley Date: 2008-05-04 21:14:02 -0700 (Sun, 04 May 2008) Log Message: ----------- More improvements to Log4jCommand. Level arguments are now case insensitive, Logger arguments now have completion, and the command can now change the Level for the root logger. Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.log4j.xml trunk/shell/src/shell/org/jnode/shell/command/log4j/Log4jCommand.java Added Paths: ----------- trunk/shell/src/shell/org/jnode/shell/syntax/Log4jLevelArgument.java trunk/shell/src/shell/org/jnode/shell/syntax/Log4jLoggerArgument.java Modified: trunk/shell/descriptors/org.jnode.shell.command.log4j.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.log4j.xml 2008-05-05 04:09:59 UTC (rev 4055) +++ trunk/shell/descriptors/org.jnode.shell.command.log4j.xml 2008-05-05 04:14:02 UTC (rev 4056) @@ -27,8 +27,8 @@ <option argLabel="list" shortName="l" longName="list" description="List all existing loggers"/> <sequence description="Set the logging level for a logger"> <option argLabel="setLevel" shortName="s" longName="setLevel"/> - <argument argLabel="logger"/> <argument argLabel="level"/> + <optional><argument argLabel="logger"/></optional> </sequence> <option argLabel="url" shortName="u" longName="url" description="Load log4j configuration from a URL"/> <argument argLabel="file" description="Load log4j configuration from a file"/> Modified: trunk/shell/src/shell/org/jnode/shell/command/log4j/Log4jCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/log4j/Log4jCommand.java 2008-05-05 04:09:59 UTC (rev 4055) +++ trunk/shell/src/shell/org/jnode/shell/command/log4j/Log4jCommand.java 2008-05-05 04:14:02 UTC (rev 4056) @@ -18,7 +18,6 @@ * 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.command.log4j; import java.io.File; @@ -39,49 +38,21 @@ import org.jnode.shell.AbstractCommand; import org.jnode.shell.CommandLine; import org.jnode.shell.syntax.Argument; -import org.jnode.shell.syntax.EnumArgument; import org.jnode.shell.syntax.FileArgument; import org.jnode.shell.syntax.FlagArgument; -import org.jnode.shell.syntax.StringArgument; +import org.jnode.shell.syntax.Log4jLevelArgument; +import org.jnode.shell.syntax.Log4jLoggerArgument; import org.jnode.shell.syntax.URLArgument; /** - * This command manages log4j logging. + * This command class shows and manages log4j logging. * * @author Ewout Prangsma (ep...@us...) * @author Fabien DUMINY (fd...@jn...) * @author cr...@jn... */ public class Log4jCommand extends AbstractCommand { - // FIXME ... turn the following into a free standing class that accepts - // the log level in a case-insensitive fashion. - private enum LevelEnum { - all(Level.ALL), - // trace(Level.TRACE), // introduced in log4j 1.2.12 - debug(Level.DEBUG), - info(Level.INFO), - warn(Level.WARN), - error(Level.ERROR), - fatal(Level.FATAL), - off(Level.OFF); - - public final Level level; - LevelEnum(Level level) { - this.level = level; - } - }; - private class LogLevelArgument extends EnumArgument<LevelEnum> { - public LogLevelArgument() { - super("level", Argument.OPTIONAL, LevelEnum.class, "the logging level"); - } - - @Override - protected String argumentKind() { - return "logging level"; - } - } - private final FlagArgument FLAG_LIST = new FlagArgument("list", Argument.OPTIONAL, "List current loggers"); @@ -94,11 +65,11 @@ private final URLArgument ARG_URL = new URLArgument("url", Argument.OPTIONAL, "URL for log4j configuration file"); - private final LogLevelArgument ARG_LEVEL = new LogLevelArgument(); + private final Log4jLevelArgument ARG_LEVEL = + new Log4jLevelArgument("level", Argument.OPTIONAL, "the logging level"); - // FIXME this should have a custom Argument class so that it can do completion. - private final StringArgument ARG_LOGGER = - new StringArgument("logger", Argument.OPTIONAL, "the name of the logger"); + private final Log4jLoggerArgument ARG_LOGGER = + new Log4jLoggerArgument("logger", Argument.OPTIONAL, "the logger"); public Log4jCommand() { super("manage log4j logging"); @@ -145,6 +116,8 @@ } } else if (FLAG_LIST.isSet()) { + // List current loggers and their levels. Effective levels are shown + // in parentheses. Enumeration<?> en = LogManager.getCurrentLoggers(); while (en.hasMoreElements()) { Logger logger = (Logger) en.nextElement(); @@ -155,12 +128,11 @@ } } else if (FLAG_SET_LEVEL.isSet()){ - // Change the logging level for a specified logger - // FIXME support changing the root logger's level - final String loggerName = ARG_LOGGER.getValue(); - final LevelEnum level = ARG_LEVEL.getValue(); - final Logger log = Logger.getLogger(loggerName); - log.setLevel(level.level); + // Change the logging level for a specified logger or the root logger + final Level level = ARG_LEVEL.getValue(); + final Logger log = ARG_LOGGER.isSet() ? + ARG_LOGGER.getValue() : Logger.getRootLogger(); + log.setLevel(level); } } } Added: trunk/shell/src/shell/org/jnode/shell/syntax/Log4jLevelArgument.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/syntax/Log4jLevelArgument.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/syntax/Log4jLevelArgument.java 2008-05-05 04:14:02 UTC (rev 4056) @@ -0,0 +1,55 @@ +/* + * $Id: Log4jCommand.java 4053 2008-05-04 13:57:57Z crawley $ + * + * 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.syntax; + +import java.util.HashMap; + +import org.apache.log4j.Level; + +/** + * This Argument class accepts and completes (case insensitive) log4j logging levels. + * + * @author cr...@jn... + */ +public class Log4jLevelArgument extends MappedArgument<Level> { + private static HashMap<String, Level> LEVEL_MAP = new HashMap<String, Level>(); + + static { + LEVEL_MAP.put("all", Level.ALL); + // LEVEL_MAP.put("trace", Level.TRACE); // introduce in log4j 1.2.12 + LEVEL_MAP.put("debug", Level.DEBUG); + LEVEL_MAP.put("info", Level.INFO); + LEVEL_MAP.put("warn", Level.WARN); + LEVEL_MAP.put("error", Level.ERROR); + LEVEL_MAP.put("fatal", Level.FATAL); + LEVEL_MAP.put("off", Level.OFF); + } + + public Log4jLevelArgument(String label, int flags, String description) { + super(label, flags, new Level[0], LEVEL_MAP, true, description); + } + + @Override + protected String argumentKind() { + return "logging level"; + } + +} Added: trunk/shell/src/shell/org/jnode/shell/syntax/Log4jLoggerArgument.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/syntax/Log4jLoggerArgument.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/syntax/Log4jLoggerArgument.java 2008-05-05 04:14:02 UTC (rev 4056) @@ -0,0 +1,49 @@ +package org.jnode.shell.syntax; + +import java.util.Enumeration; + +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; + +import org.jnode.driver.console.CompletionInfo; +import org.jnode.shell.CommandLine.Token; + +/** + * This Argument class captures log4j logger names, and completes them against + * the set of logger names that are already defined. + * + * @author cr...@jn... + */ +public class Log4jLoggerArgument extends Argument<Logger> { + + public Log4jLoggerArgument(String label, int flags, String description) { + super(label, flags, new Logger[0], description); + } + + @Override + protected String argumentKind() { + return "logger"; + } + + /** + * Any token is an acceptable Logger name. + */ + @Override + protected void doAccept(Token value) throws CommandSyntaxException { + addValue(Logger.getLogger(value.token)); + } + + /** + * Complete against existing logger names. + */ + @Override + public void complete(CompletionInfo completion, String partial) { + Enumeration<?> en = LogManager.getCurrentLoggers(); + while (en.hasMoreElements()) { + String loggerName = ((Logger) en.nextElement()).getName(); + if (loggerName.startsWith(partial)) { + completion.addCompletion(loggerName); + } + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-05-05 04:54:07
|
Revision: 4057 http://jnode.svn.sourceforge.net/jnode/?rev=4057&view=rev Author: crawley Date: 2008-05-04 21:54:03 -0700 (Sun, 04 May 2008) Log Message: ----------- Converted HaltCommand and RebootCommand Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.plugin.xml trunk/shell/src/shell/org/jnode/shell/command/plugin/HaltCommand.java trunk/shell/src/shell/org/jnode/shell/command/plugin/RebootCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.plugin.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.plugin.xml 2008-05-05 04:14:02 UTC (rev 4056) +++ trunk/shell/descriptors/org.jnode.shell.command.plugin.xml 2008-05-05 04:54:03 UTC (rev 4057) @@ -22,6 +22,13 @@ <alias name="plugin" class="org.jnode.shell.command.plugin.PluginCommand"/> <alias name="reboot" class="org.jnode.shell.command.plugin.RebootCommand"/> </extension> + + <extension point="org.jnode.shell.syntaxes"> + <syntax alias="halt" + description="Shutdown all services and devices so that the computer can be powered off"/> + <syntax alias="reboot" + description="Shutdown all services and devices then reboot the computer"/> + </extension> <extension point="org.jnode.security.permissions"> <permission class="org.jnode.security.JNodePermission" name="createPluginLoader"/> Modified: trunk/shell/src/shell/org/jnode/shell/command/plugin/HaltCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/plugin/HaltCommand.java 2008-05-05 04:14:02 UTC (rev 4056) +++ trunk/shell/src/shell/org/jnode/shell/command/plugin/HaltCommand.java 2008-05-05 04:54:03 UTC (rev 4057) @@ -21,20 +21,31 @@ package org.jnode.shell.command.plugin; -import org.jnode.shell.help.Help; +import java.io.InputStream; +import java.io.PrintStream; + +import org.jnode.shell.AbstractCommand; +import org.jnode.shell.CommandLine; import org.jnode.vm.VmSystem; /** * Halts the system * - * @author epr + * @author Ewout Prangsma (ep...@us...) */ -public class HaltCommand { +public class HaltCommand extends AbstractCommand { - public static Help.Info HELP_INFO = new Help.Info("halt", - "Stop all services and devices, so the computer can be turned off"); + public HaltCommand() { + super("Stop all services and devices, so that the computer can be turned off"); + } public static void main(String[] args) throws Exception { + new HaltCommand().execute(args); + } + + @Override + public void execute(CommandLine commandLine, InputStream in, + PrintStream out, PrintStream err) { VmSystem.halt(false); } } Modified: trunk/shell/src/shell/org/jnode/shell/command/plugin/RebootCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/plugin/RebootCommand.java 2008-05-05 04:14:02 UTC (rev 4056) +++ trunk/shell/src/shell/org/jnode/shell/command/plugin/RebootCommand.java 2008-05-05 04:54:03 UTC (rev 4057) @@ -21,18 +21,29 @@ package org.jnode.shell.command.plugin; -import org.jnode.shell.help.Help; +import java.io.InputStream; +import java.io.PrintStream; + +import org.jnode.shell.AbstractCommand; +import org.jnode.shell.CommandLine; import org.jnode.vm.VmSystem; /** * @author Ewout Prangsma (ep...@us...) */ -public class RebootCommand { +public class RebootCommand extends AbstractCommand { - public static Help.Info HELP_INFO = new Help.Info("reboot", - "Stop all services and devices and reset the computer"); + public RebootCommand() { + super("Stop all services and devices and then reboot the computer"); + } public static void main(String[] args) throws Exception { + new RebootCommand().execute(args); + } + + @Override + public void execute(CommandLine commandLine, InputStream in, + PrintStream out, PrintStream err) { VmSystem.halt(true); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-05-05 08:05:12
|
Revision: 4058 http://jnode.svn.sourceforge.net/jnode/?rev=4058&view=rev Author: crawley Date: 2008-05-05 01:05:07 -0700 (Mon, 05 May 2008) Log Message: ----------- Converted PluginCommand ... but I cannot figure out how to use it. Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.plugin.xml trunk/shell/src/shell/org/jnode/shell/command/plugin/PluginCommand.java Added Paths: ----------- trunk/shell/src/shell/org/jnode/shell/syntax/PluginArgument.java Modified: trunk/shell/descriptors/org.jnode.shell.command.plugin.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.plugin.xml 2008-05-05 04:54:03 UTC (rev 4057) +++ trunk/shell/descriptors/org.jnode.shell.command.plugin.xml 2008-05-05 08:05:07 UTC (rev 4058) @@ -26,6 +26,25 @@ <extension point="org.jnode.shell.syntaxes"> <syntax alias="halt" description="Shutdown all services and devices so that the computer can be powered off"/> + <syntax alias="plugin"> + <empty description="list all plugins"/> + <argument argLabel="plugin" description="list a the given plugin"/> + <sequence description="load the given plugin"> + <option argLabel="load" longName="load" shortName="l"/> + <argument argLabel="plugin"/> + <optional><argument argLabel="version"/></optional> + </sequence> + <sequence description="reload the given plugin"> + <option argLabel="reload" longName="reload" shortName="r"/> + <argument argLabel="plugin"/> + <optional><argument argLabel="version"/></optional> + </sequence> + <sequence description="unload the given plugin"> + <option argLabel="unload" longName="unload" shortName="u"/> + <argument argLabel="plugin"/> + </sequence> + <option argLabel="loader" longName="addLoader" shortName="a" description="add a new plugin loader"/> + </syntax> <syntax alias="reboot" description="Shutdown all services and devices then reboot the computer"/> </extension> Modified: trunk/shell/src/shell/org/jnode/shell/command/plugin/PluginCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/plugin/PluginCommand.java 2008-05-05 04:54:03 UTC (rev 4057) +++ trunk/shell/src/shell/org/jnode/shell/command/plugin/PluginCommand.java 2008-05-05 08:05:07 UTC (rev 4058) @@ -26,11 +26,14 @@ import java.net.MalformedURLException; import java.net.URL; import java.security.AccessController; +import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import javax.naming.NameNotFoundException; + import org.jnode.naming.InitialNaming; import org.jnode.plugin.PluginDescriptor; import org.jnode.plugin.PluginException; @@ -38,136 +41,129 @@ import org.jnode.plugin.PluginReference; import org.jnode.plugin.PluginRegistry; import org.jnode.plugin.URLPluginLoader; -import org.jnode.shell.help.Argument; -import org.jnode.shell.help.Help; -import org.jnode.shell.help.Parameter; -import org.jnode.shell.help.ParsedArguments; -import org.jnode.shell.help.Syntax; -import org.jnode.shell.help.argument.OptionArgument; -import org.jnode.shell.help.argument.PluginArgument; -import org.jnode.shell.help.argument.URLArgument; +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.PluginArgument; +import org.jnode.shell.syntax.StringArgument; +import org.jnode.shell.syntax.SyntaxMultiplicityException; +import org.jnode.shell.syntax.URLArgument; import org.jnode.vm.Vm; /** * @author epr */ -public class PluginCommand { +public class PluginCommand extends AbstractCommand { - static final OptionArgument ARG_LOADER = new OptionArgument("loader", - "Loader management", - new OptionArgument.Option("addloader", "Add plugin loader")); + private final FlagArgument FLAG_LOAD = + new FlagArgument("load", Argument.OPTIONAL, "Load the plugin"); + + private final FlagArgument FLAG_RELOAD = + new FlagArgument("reload", Argument.OPTIONAL, "Reload the plugin"); + + private final FlagArgument FLAG_UNLOAD = + new FlagArgument("unload", Argument.OPTIONAL, "Unload the plugin"); - static final OptionArgument ARG_ACTION = new OptionArgument("action", - "action to do on the plugin", - new OptionArgument.Option("load", "Load the plugin"), - new OptionArgument.Option("reload", "Reload the plugin"), - new OptionArgument.Option("unload", "Unload the plugin")); + private final URLArgument ARG_LOADER_URL = + new URLArgument("loader", Argument.OPTIONAL, "loader location"); - static final URLArgument ARG_URL = new URLArgument("url", "plugin location"); - - static final PluginArgument ARG_ACTION_ID = new PluginArgument("plugin", - "plugin identifier"); - - static final PluginArgument ARG_LIST_ID = new PluginArgument("plugin", - "plugin identifier"); + private final PluginArgument ARG_PLUGIN_ID = + new PluginArgument("plugin", Argument.OPTIONAL, "plugin identifier"); - static final Argument ARG_VERSION = new Argument("version", "plugin version"); + private final StringArgument ARG_VERSION = + new StringArgument("version", Argument.OPTIONAL, "plugin version"); + + private PrintStream out, err; + private PluginManager mgr; + + public PluginCommand() { + super("List and manage plugins and plugin loaders"); + registerArguments(ARG_PLUGIN_ID, FLAG_LOAD, FLAG_RELOAD, FLAG_UNLOAD, + ARG_LOADER_URL, ARG_VERSION); + } - static final Parameter PARAM_LOADER = new Parameter(ARG_LOADER); +// public static Help.Info HELP_INFO = new Help.Info( +// "plugin", +// new Syntax[] { +// new Syntax("Print name and state of all loaded plugins"), +// new Syntax("Plugin loader management", PARAM_LOADER, PARAM_URL), +// new Syntax("Load/Unload the plugin", PARAM_ACTION, +// PARAM_ACTION_ID, PARAM_VERSION), +// new Syntax("Print name and state of plugin", PARAM_LIST_ID)}); - static final Parameter PARAM_ACTION = new Parameter(ARG_ACTION); - - static final Parameter PARAM_ACTION_ID = new Parameter(ARG_ACTION_ID); - - static final Parameter PARAM_LIST_ID = new Parameter(ARG_LIST_ID); - - static final Parameter PARAM_URL = new Parameter(ARG_URL); - static final Parameter PARAM_VERSION = new Parameter(ARG_VERSION, Parameter.OPTIONAL); - - public static Help.Info HELP_INFO = new Help.Info( - "plugin", - new Syntax[] { - new Syntax("Print name and state of all loaded plugins"), - new Syntax("Plugin loader management", PARAM_LOADER, PARAM_URL), - new Syntax("Load/Unload the plugin", PARAM_ACTION, - PARAM_ACTION_ID, PARAM_VERSION), - new Syntax("Print name and state of plugin", PARAM_LIST_ID)}); - public static void main(final String[] args) throws Exception { - AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { - public Object run() throws Exception { - new PluginCommand().execute(args, System.in, System.out, System.err); - return null; - }}); + new PluginCommand().execute(args); } /** * Execute this command */ - public void execute(String[] args, InputStream in, PrintStream out, + public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception { - - final ParsedArguments cmdLine = HELP_INFO.parse(args); - final PluginManager mgr = (PluginManager) InitialNaming - .lookup(PluginManager.NAME); - - if (PARAM_LOADER.isSet(cmdLine)) { - final String action = ARG_LOADER.getValue(cmdLine); - if (action.equals("addloader")) { - addPluginLoader(out, mgr, ARG_URL.getURL(cmdLine)); - } else { - out.println("Unknown load action " + action); + this.out = out; + this.err = err; + try { + AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { + public Object run() throws Exception { + doRun(); + return null; + }}); + } + catch (PrivilegedActionException ex) { + throw ex.getException(); + } + } + + private void doRun() + throws NameNotFoundException, SyntaxMultiplicityException, PluginException { + mgr = (PluginManager) InitialNaming.lookup(PluginManager.NAME); + final String version = ARG_VERSION.isSet() ? + ARG_VERSION.getValue() : Vm.getVm().getVersion(); + final String pluginId = ARG_PLUGIN_ID.getValue(); + if (ARG_LOADER_URL.isSet()) { + try { + final URL url = new URL(ARG_LOADER_URL.getValue()); + addPluginLoader(url); } - } else if (PARAM_ACTION.isSet(cmdLine)) { - final String action = ARG_ACTION.getValue(cmdLine); - if (action.equals("load")) { - final String version; - if (PARAM_VERSION.isSet(cmdLine)) { - version = ARG_VERSION.getValue(cmdLine); - } else { - version = Vm.getVm().getVersion(); - } - loadPlugin(out, mgr, ARG_ACTION_ID.getValue(cmdLine), version); - } else if (action.equals("reload")) { - final String version; - if (PARAM_VERSION.isSet(cmdLine)) { - version = ARG_VERSION.getValue(cmdLine); - } else { - version = Vm.getVm().getVersion(); - } - final String id = ARG_ACTION_ID.getValue(cmdLine); - reloadPlugin(out, mgr, id, version); - } else if (action.equals("unload")) { - unloadPlugin(out, mgr, ARG_ACTION_ID.getValue(cmdLine)); - } else { - out.println("Unknown action " + action); + catch (MalformedURLException ex) { + err.println("Malformed plugin loader URL"); + exit(1); } - } else if (PARAM_LIST_ID.isSet(cmdLine)) { - listPlugin(out, mgr, ARG_LIST_ID.getValue(cmdLine)); - } else { - listPlugins(out, mgr); + } + else if (FLAG_LOAD.isSet()) { + loadPlugin(pluginId, version); } + else if (FLAG_RELOAD.isSet()) { + reloadPlugin(pluginId, version); + } + else if (FLAG_UNLOAD.isSet()) { + unloadPlugin(pluginId); + } + else if (pluginId != null) { + listPlugin(pluginId); + } + else { + listPlugins(); + } } - private void addPluginLoader(PrintStream out, PluginManager mgr, URL url) - throws PluginException, MalformedURLException { + private void addPluginLoader(URL url) + throws PluginException, MalformedURLException { final String ext = url.toExternalForm(); if (!ext.endsWith("/")) { url = new URL(ext + "/"); } - out.println("Adding loader for " + url); mgr.getLoaderManager().addPluginLoader(new URLPluginLoader(url)); + out.println("Added plugin loader for " + url); } - private void loadPlugin(PrintStream out, PluginManager mgr, String id, String version) - throws PluginException { - out.println("Loading " + id); + private void loadPlugin(String id, String version) throws PluginException { mgr.getRegistry().loadPlugin(mgr.getLoaderManager(), id, version); + out.println("Loaded plugin " + id + " version " + version); } - private void reloadPlugin(PrintStream out, PluginManager mgr, String id, - String version) throws PluginException { - out.println("Reloading " + id); + private void reloadPlugin(String id, String version) throws PluginException { final PluginRegistry reg = mgr.getRegistry(); final List<PluginReference> refs = reg.unloadPlugin(id); for (PluginReference ref : refs) { @@ -178,22 +174,21 @@ if (reg.getPluginDescriptor(id) == null) { reg.loadPlugin(mgr.getLoaderManager(), id, version); } + out.println("Reloaded plugin " + id + " version " + version); } - private void unloadPlugin(PrintStream out, PluginManager mgr, String id) - throws PluginException { + private void unloadPlugin(String id) throws PluginException { mgr.getRegistry().unloadPlugin(id); - out.println("Unloaded " + id); + out.println("Unloaded plugin " + id); } - private void listPlugins(PrintStream out, PluginManager mgr) - throws PluginException { + private void listPlugins() throws PluginException { final ArrayList<String> rows = new ArrayList<String>(); for (PluginDescriptor descr : mgr.getRegistry()) { StringBuilder sb = new StringBuilder(); sb.append(descr.getId()); sb.append("; state "); - sb.append((descr.getPlugin().isActive())?"active":"inactive"); + sb.append((descr.getPlugin().isActive()) ? "active" : "inactive"); sb.append("; version "); sb.append(descr.getPlugin().getDescriptor().getVersion()); rows.add(sb.toString()); @@ -204,14 +199,13 @@ } } - private void listPlugin(PrintStream out, PluginManager mgr, String id) - throws PluginException { + private void listPlugin(String id) throws PluginException { final PluginDescriptor descr = mgr.getRegistry() .getPluginDescriptor(id); if (descr != null) { out.print(descr.getId()); out.print("; state "); - out.print((descr.getPlugin().isActive())?"active":"inactive"); + out.print((descr.getPlugin().isActive()) ? "active" : "inactive"); out.println("; version " + descr.getPlugin().getDescriptor().getVersion()); } else { out.println("Plugin " + id + " not found"); Added: trunk/shell/src/shell/org/jnode/shell/syntax/PluginArgument.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/syntax/PluginArgument.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/syntax/PluginArgument.java 2008-05-05 08:05:07 UTC (rev 4058) @@ -0,0 +1,72 @@ +/* + * $Id$ + * + * JNode.org + * Copyright (C) 2007-2008 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.syntax; + +import javax.naming.NameNotFoundException; + +import org.jnode.driver.console.CompletionInfo; +import org.jnode.naming.InitialNaming; +import org.jnode.plugin.PluginDescriptor; +import org.jnode.plugin.PluginManager; + +/** + * This class captures plugin id argument values. + * + * @author Ewout Prangsma (ep...@us...) + * @author cr...@jn... + */ +public class PluginArgument extends StringArgument { + + public PluginArgument(String label, int flags, String description) { + super(label, flags, description); + } + + @Override + public void complete(CompletionInfo completion, String partial) { + try { + // get the plugin manager + final PluginManager piMgr = (PluginManager) InitialNaming + .lookup(PluginManager.NAME); + + // collect matching plugin id's + for (PluginDescriptor descr : piMgr.getRegistry()) { + final String id = descr.getId(); + if (id.startsWith(partial)) { + completion.addCompletion(id); + } + } + } catch (NameNotFoundException ex) { + // should not happen! + return; + } + } + + @Override + public String toString() { + return "PluginArgument{" + super.toString() + "}"; + } + + @Override + protected String argumentKind() { + return "plugin id"; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-05-05 10:48:37
|
Revision: 4059 http://jnode.svn.sourceforge.net/jnode/?rev=4059&view=rev Author: crawley Date: 2008-05-05 03:48:34 -0700 (Mon, 05 May 2008) Log Message: ----------- Converted KdbCommand Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.system.xml trunk/shell/src/shell/org/jnode/shell/command/system/KdbCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.system.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.system.xml 2008-05-05 08:05:07 UTC (rev 4058) +++ trunk/shell/descriptors/org.jnode.shell.command.system.xml 2008-05-05 10:48:34 UTC (rev 4059) @@ -26,6 +26,11 @@ <extension point="org.jnode.shell.syntaxes"> <syntax alias="cpuid" description="dump the system's CPU ID information"/> + <syntax alias="kdb"> + <empty description="show current kernel debugging state"/> + <option argLabel="off" longName="off" description="Turn kernel debugging off"/> + <option argLabel="on" longName="on" description="Turn kernel debugging on"/> + </syntax> </extension> </plugin> Modified: trunk/shell/src/shell/org/jnode/shell/command/system/KdbCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/system/KdbCommand.java 2008-05-05 08:05:07 UTC (rev 4058) +++ trunk/shell/src/shell/org/jnode/shell/command/system/KdbCommand.java 2008-05-05 10:48:34 UTC (rev 4059) @@ -21,42 +21,55 @@ package org.jnode.shell.command.system; -import org.jnode.shell.help.Help; -import org.jnode.shell.help.Parameter; -import org.jnode.shell.help.ParsedArguments; -import org.jnode.shell.help.Syntax; -import org.jnode.shell.help.argument.OptionArgument; +import java.io.InputStream; +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.FlagArgument; import org.jnode.vm.Unsafe; /** + * This command turns kernel debug print capture on and off. When "on", + * messages from calls to org.jnode.vm.Unsafe.debug(...) get copied to + * the serial port. + * * @author Ewout Prangsma (ep...@us...) + * @author cr...@jn... */ -public class KdbCommand { - static final OptionArgument ARG_ACTION = new OptionArgument("action", - "action to do on the kernel debugger", new OptionArgument.Option( - "on", "Enable the kernel debugger"), - new OptionArgument.Option("off", "Disable the kernel debugger")); +public class KdbCommand extends AbstractCommand { + private final FlagArgument FLAG_ON = + new FlagArgument("on", Argument.OPTIONAL, "Enable the kernel debugger"); + + private final FlagArgument FLAG_OFF = + new FlagArgument("off", Argument.OPTIONAL, "Disable the kernel debugger"); - static final Parameter PARAM_ACTION = new Parameter(ARG_ACTION); + public KdbCommand() { + super("Control kernel debugging"); + registerArguments(FLAG_OFF, FLAG_ON); + } - public static Help.Info HELP_INFO = new Help.Info("kdb", new Syntax[] { - new Syntax("Print the state of the kernel debugger"), - new Syntax("En/Disable the kernel debugger", PARAM_ACTION) }); - public static void main(String[] args) throws Exception { - final ParsedArguments cmdLine = HELP_INFO.parse(args); - - if (PARAM_ACTION.isSet(cmdLine)) { - final String action = ARG_ACTION.getValue(cmdLine); - if (action.equals("on")) { - Unsafe.setKdbEnabled(true); - } else { - Unsafe.setKdbEnabled(false); - } - } else { + new KdbCommand().execute(args); + } + + @Override + public void execute(CommandLine commandLine, InputStream in, + PrintStream out, PrintStream err) { + if (FLAG_OFF.isSet()) { + Unsafe.setKdbEnabled(false); + out.println("KDB disabled"); + } + else if (FLAG_ON.isSet()) { + Unsafe.setKdbEnabled(true); + out.println("KDB enabled"); + } + else { + // FIXME ... we shouldn't have to do this ... final boolean state = Unsafe.setKdbEnabled(false); Unsafe.setKdbEnabled(state); - System.out.println("KDB is " + (state ? "enabled" : "disabled")); + out.println("KDB is " + (state ? "enabled" : "disabled")); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-05-06 10:49:06
|
Revision: 4064 http://jnode.svn.sourceforge.net/jnode/?rev=4064&view=rev Author: crawley Date: 2008-05-06 03:48:39 -0700 (Tue, 06 May 2008) Log Message: ----------- Converted LsIRQCommand (was LsIRQ) Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.system.xml Added Paths: ----------- trunk/shell/src/shell/org/jnode/shell/command/system/LsIRQCommand.java Removed Paths: ------------- trunk/shell/src/shell/org/jnode/shell/command/system/LsIRQ.java Modified: trunk/shell/descriptors/org.jnode.shell.command.system.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.system.xml 2008-05-05 14:33:15 UTC (rev 4063) +++ trunk/shell/descriptors/org.jnode.shell.command.system.xml 2008-05-06 10:48:39 UTC (rev 4064) @@ -20,7 +20,7 @@ <extension point="org.jnode.shell.aliases"> <alias name="cpuid" class="org.jnode.shell.command.system.CpuIDCommand"/> <alias name="kdb" class="org.jnode.shell.command.system.KdbCommand"/> - <alias name="lsirq" class="org.jnode.shell.command.system.LsIRQ"/> + <alias name="lsirq" class="org.jnode.shell.command.system.LsIRQCommand"/> <alias name="vminfo" class="org.jnode.vm.Vm"/> </extension> @@ -31,6 +31,7 @@ <option argLabel="off" longName="off" description="Turn kernel debugging off"/> <option argLabel="on" longName="on" description="Turn kernel debugging on"/> </syntax> + <syntax alias="lsirq" description="dump IRQ handler information"/> </extension> </plugin> Deleted: trunk/shell/src/shell/org/jnode/shell/command/system/LsIRQ.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/system/LsIRQ.java 2008-05-05 14:33:15 UTC (rev 4063) +++ trunk/shell/src/shell/org/jnode/shell/command/system/LsIRQ.java 2008-05-06 10:48:39 UTC (rev 4064) @@ -1,41 +0,0 @@ -/* - * $Id$ - * - * 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.command.system; - -import org.jnode.vm.scheduler.IRQManager; -import org.jnode.vm.scheduler.VmProcessor; - -/** - * @author Ewout Prangsma (ep...@us...) - */ -public class LsIRQ { - - public static void main(String[] args) { - final VmProcessor proc = VmProcessor.current(); - final IRQManager irqMgr = proc.getIRQManager(); - final int max = irqMgr.getNumIRQs(); - for (int i = 0; i < max; i++) { - System.out.println("IRQ" + i + "\t" + irqMgr.getIrqCount(i) + "\t" - + irqMgr.getHandlerInfo(i)); - } - } -} Added: trunk/shell/src/shell/org/jnode/shell/command/system/LsIRQCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/system/LsIRQCommand.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/command/system/LsIRQCommand.java 2008-05-06 10:48:39 UTC (rev 4064) @@ -0,0 +1,56 @@ +/* + * $Id: LsIRQ.java 2491 2006-04-23 11:31:22Z 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.command.system; + +import java.io.InputStream; +import java.io.PrintStream; + +import org.jnode.shell.AbstractCommand; +import org.jnode.shell.CommandLine; +import org.jnode.vm.scheduler.IRQManager; +import org.jnode.vm.scheduler.VmProcessor; + +/** + * @author Ewout Prangsma (ep...@us...) + */ +public class LsIRQCommand extends AbstractCommand { + + public LsIRQCommand() { + super("prints IRQ handler info"); + } + + public static void main(String[] args) throws Exception { + new LsIRQCommand().execute(args); + } + + @Override + public void execute(CommandLine commandLine, InputStream in, + PrintStream out, PrintStream err) { + final VmProcessor proc = VmProcessor.current(); + final IRQManager irqMgr = proc.getIRQManager(); + final int max = irqMgr.getNumIRQs(); + for (int i = 0; i < max; i++) { + out.println("IRQ" + i + "\t" + irqMgr.getIrqCount(i) + "\t" + + irqMgr.getHandlerInfo(i)); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-05-06 14:00:03
|
Revision: 4066 http://jnode.svn.sourceforge.net/jnode/?rev=4066&view=rev Author: crawley Date: 2008-05-06 06:59:51 -0700 (Tue, 06 May 2008) Log Message: ----------- Converted TestCommand (aka utest) Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.test.xml trunk/shell/src/shell/org/jnode/shell/command/test/TestCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.test.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.test.xml 2008-05-06 11:33:20 UTC (rev 4065) +++ trunk/shell/descriptors/org.jnode.shell.command.test.xml 2008-05-06 13:59:51 UTC (rev 4066) @@ -23,6 +23,12 @@ <alias name="utest" class="org.jnode.shell.command.test.TestCommand"/> <alias name="suite" class="org.jnode.shell.command.test.SuiteCommand"/> </extension> + + <extension point="org.jnode.shell.syntaxes"> + <syntax alias="utest"> + <argument argLabel="className" description="run a JUnit testcase"/> + </syntax> + </extension> <extension point="org.jnode.security.permissions"> <permission class="java.util.PropertyPermission" name="user.home" actions="read"/> Modified: trunk/shell/src/shell/org/jnode/shell/command/test/TestCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/test/TestCommand.java 2008-05-06 11:33:20 UTC (rev 4065) +++ trunk/shell/src/shell/org/jnode/shell/command/test/TestCommand.java 2008-05-06 13:59:51 UTC (rev 4066) @@ -24,54 +24,49 @@ import java.io.InputStream; import java.io.PrintStream; +import junit.framework.TestResult; import junit.framework.TestSuite; import junit.textui.TestRunner; -import org.jnode.shell.help.Help; -import org.jnode.shell.help.Parameter; -import org.jnode.shell.help.ParsedArguments; -import org.jnode.shell.help.argument.ClassNameArgument; +import org.jnode.shell.AbstractCommand; +import org.jnode.shell.CommandLine; +import org.jnode.shell.syntax.Argument; +import org.jnode.shell.syntax.ClassNameArgument; /** * @author epr + * @author cr...@jn... */ -public class TestCommand { +public class TestCommand extends AbstractCommand { - static final ClassNameArgument ARG_CLASS = new ClassNameArgument( - "classname", "the class representing the testcase"); + private final ClassNameArgument ARG_CLASS = new ClassNameArgument( + "className", Argument.MANDATORY, "the class representing the testcase"); - // static final Argument ARG_ARGS = new Argument("arg", "the argument(s) to - // pass to the testcase", Argument.MULTI); + public TestCommand() { + super("Run a JUnit testcase"); + registerArguments(ARG_CLASS); + } - public static Help.Info HELP_INFO = new Help.Info("utest", - "Run a JUnit testcase", new Parameter[] { new Parameter(ARG_CLASS, - Parameter.MANDATORY) - // new Parameter(ARG_ARGS, Parameter.OPTIONAL) - }); - public static void main(String[] args) throws Exception { - new TestCommand().execute(HELP_INFO.parse(args), System.in, System.out, - System.err); + new TestCommand().execute(args); } /** * Execute this command + * + * @throws ClassNotFoundException */ - public void execute(ParsedArguments cmdLine, InputStream in, - PrintStream out, PrintStream err) throws Exception { - - Class<?> clazz = ARG_CLASS.getClass(cmdLine); - - JNodeTestRunner.run(clazz); - } - - private static class JNodeTestRunner extends TestRunner { - - public static void run(Class<?> testClass) { - JNodeTestRunner runner = new JNodeTestRunner(); - TestSuite suite = new TestSuite(testClass); - runner.doRun(suite); + public void execute(CommandLine cmdLine, InputStream in, + PrintStream out, PrintStream err) { + try { + Class<?> clazz = ARG_CLASS.getValueAsClass(); + TestResult res = new TestRunner().doRun(new TestSuite(clazz)); + if (!res.wasSuccessful()) { + exit(1); + } + } catch (ClassNotFoundException ex) { + err.println("Class not found: " + ex.getMessage()); + exit(2); } } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-05-08 13:21:12
|
Revision: 4071 http://jnode.svn.sourceforge.net/jnode/?rev=4071&view=rev Author: crawley Date: 2008-05-08 06:20:44 -0700 (Thu, 08 May 2008) Log Message: ----------- Converted SuiteCommand ... but see the bug I'm going to create. Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.test.xml trunk/shell/src/shell/org/jnode/shell/command/test/SuiteCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.test.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.test.xml 2008-05-08 13:19:10 UTC (rev 4070) +++ trunk/shell/descriptors/org.jnode.shell.command.test.xml 2008-05-08 13:20:44 UTC (rev 4071) @@ -7,7 +7,8 @@ license-name="lgpl" provider-name="JNode.org"> - <requires> + <requires> + <import plugin="org.jnode.runtime.core"/> <import plugin="org.junit" version="3.8"/> <import plugin="org.jnode.shell.help"/> <import plugin="org.jnode.testrunner"/> @@ -28,6 +29,16 @@ <syntax alias="utest"> <argument argLabel="className" description="run a JUnit testcase"/> </syntax> + <syntax alias="suite"> + <sequence description="run JUnit tests registered with the TestManager"> + <option argLabel="run" longName="run" shortName="r"/> + <repeat minCount="0"> + <argument argLabel="category"/> + </repeat> + </sequence> + <option argLabel="list" longName="list" shortName="l" + description="list JUnit tests registered with the TestManager"/> + </syntax> </extension> <extension point="org.jnode.security.permissions"> Modified: trunk/shell/src/shell/org/jnode/shell/command/test/SuiteCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/test/SuiteCommand.java 2008-05-08 13:19:10 UTC (rev 4070) +++ trunk/shell/src/shell/org/jnode/shell/command/test/SuiteCommand.java 2008-05-08 13:20:44 UTC (rev 4071) @@ -30,85 +30,76 @@ import junit.framework.TestSuite; import org.jnode.driver.console.CompletionInfo; -import org.jnode.shell.help.Argument; -import org.jnode.shell.help.Help; -import org.jnode.shell.help.Parameter; -import org.jnode.shell.help.ParsedArguments; -import org.jnode.shell.help.argument.OptionArgument; +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; +import org.jnode.shell.syntax.StringArgument; import org.jnode.test.framework.TestManager; /** + * This command runs JUnit tests registered with the JNode test framework. + * * @author Fabien DUMINY (fd...@jn...) + * @author cr...@jn... */ -public class SuiteCommand { - static private final OptionArgument.Option OPT_LIST = new OptionArgument.Option("list", "list the tests"); - static private final OptionArgument.Option OPT_RUN = new OptionArgument.Option("run", "run the tests for given categories"); - static final OptionArgument ARG_ACTION = new OptionArgument( - "action", "action to do", OPT_LIST, OPT_RUN); - - static final CategoryArgument ARG_CATEGORY = new CategoryArgument( - "category", "a category of test to run", CategoryArgument.MULTI); +public class SuiteCommand extends AbstractCommand { + private final FlagArgument FLAG_LIST = + new FlagArgument("list", Argument.OPTIONAL, "list the tests"); + + private final FlagArgument FLAG_RUN = + new FlagArgument("run", Argument.OPTIONAL, "run the tests"); + + private final CategoryArgument ARG_CATEGORY = + new CategoryArgument("category", Argument.OPTIONAL | Argument.MULTIPLE, + "test categories to run or list"); + + public SuiteCommand() { + super("Run one or more JUnit testcase(s)"); + registerArguments(FLAG_LIST, FLAG_RUN, ARG_CATEGORY); + } - static final Parameter PARAM_ACTION = new Parameter(ARG_ACTION); - - static final Parameter PARAM_CATEGORY = new Parameter(ARG_CATEGORY, Parameter.OPTIONAL); - - public static Help.Info HELP_INFO = new Help.Info("suite", - "Run one or more JUnit testcase(s)", - new Parameter[] - { PARAM_ACTION, PARAM_CATEGORY}); - public static void main(String[] args) throws Exception { - new SuiteCommand().execute(HELP_INFO.parse(args), System.in, System.out, - System.err); + new SuiteCommand().execute(args); } /** * Execute this command */ - public void execute(ParsedArguments cmdLine, InputStream in, - PrintStream out, PrintStream err) throws Exception { - - String action = ARG_ACTION.getValue(cmdLine); - if(OPT_LIST.getName().equals(action)) - { - TestManager mgr = TestManager.getInstance(); - for(Class<? extends Test> test : mgr.getTests()) - { - out.print(test.getName()+" :"); - for(String category : mgr.getCategories(test)) - { + public void execute(CommandLine cmdLine, InputStream in, + PrintStream out, PrintStream err) { + TestManager mgr = TestManager.getInstance(); + if (FLAG_LIST.isSet()) { + for (Class<? extends Test> test : mgr.getTests()) { + out.print(test.getName() + " :"); + for (String category : mgr.getCategories(test)) { out.print(" "); out.print(category); } out.println(); } } - else if(OPT_RUN.getName().equals(action)) - { - String[] categories = ARG_CATEGORY.getValues(cmdLine); + else if (FLAG_RUN.isSet()) { + String[] categories = ARG_CATEGORY.getValues(); if (categories == null) { categories = new String[0]; } - TestSuite suite = TestManager.getInstance().getTestSuite(Arrays.asList(categories)); + TestSuite suite = mgr.getTestSuite(Arrays.asList(categories)); junit.textui.TestRunner.run(suite); } - else - { - HELP_INFO.help(null, System.out); - } } - private static class CategoryArgument extends Argument { + /** + * Validate and complete test categories against the categories known to + * the TestManager. + */ + private static class CategoryArgument extends StringArgument { - public CategoryArgument(String name, String description, boolean multi) { - super(name, description, multi); + public CategoryArgument(String label, int flags, String description) { + super(label, flags, description); } - public CategoryArgument(String name, String description) { - super(name, description); - } - public void complete(CompletionInfo completion, String partial) { Set<String> availCategories = TestManager.getInstance().getCategories(); for (String availCategory : availCategories) { @@ -118,12 +109,14 @@ } } - protected boolean isValidValue(String category) { - if((category == null) || "".equals(category)) - return true; - + protected String doAccept(String category) throws CommandSyntaxException { Set<String> availCategories = TestManager.getInstance().getCategories(); - return availCategories.contains(category); + if (availCategories.contains(category)) { + return category; + } + else { + throw new CommandSyntaxException("not a recognized JUnit test category"); + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |