From: <ls...@us...> - 2007-02-10 19:23:33
|
Revision: 3113 http://jnode.svn.sourceforge.net/jnode/?rev=3113&view=rev Author: lsantha Date: 2007-02-10 11:23:31 -0800 (Sat, 10 Feb 2007) Log Message: ----------- Fixed bsh command and updated beanshell to 2.0b4. Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.bsh.xml Added Paths: ----------- trunk/shell/lib/bsh-2.0b4.jar trunk/shell/src/shell/org/jnode/shell/command/bsh/BshCommand.java Removed Paths: ------------- trunk/shell/src/shell/org/jnode/shell/command/bsh/BeanshellCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.bsh.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.bsh.xml 2007-02-04 20:28:05 UTC (rev 3112) +++ trunk/shell/descriptors/org.jnode.shell.command.bsh.xml 2007-02-10 19:23:31 UTC (rev 3113) @@ -19,7 +19,7 @@ </runtime> <extension point="org.jnode.shell.aliases"> - <alias name="bsh" class="org.jnode.shell.command.bsh.BeanshellCommand"/> + <alias name="bsh" class="org.jnode.shell.command.bsh.BshCommand"/> </extension> <extension point="org.jnode.security.permissions"> Added: trunk/shell/lib/bsh-2.0b4.jar =================================================================== (Binary files differ) Property changes on: trunk/shell/lib/bsh-2.0b4.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Deleted: trunk/shell/src/shell/org/jnode/shell/command/bsh/BeanshellCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/bsh/BeanshellCommand.java 2007-02-04 20:28:05 UTC (rev 3112) +++ trunk/shell/src/shell/org/jnode/shell/command/bsh/BeanshellCommand.java 2007-02-10 19:23:31 UTC (rev 3113) @@ -1,235 +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.bsh; - -import gnu.java.io.NullOutputStream; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.PrintStream; -import java.io.Reader; -import java.io.StringReader; - -import bsh.ConsoleInterface; -import bsh.EvalError; -import bsh.Interpreter; - -/** - * User: Sam Reid Date: Jan 1, 2004 Time: 10:40:34 AM Copyright (c) Jan 1, 2004 - * by Sam Reid - */ -public class BeanshellCommand { - - private static Interpreter interpreter; - /*static { - //ConsoleInterface ci=new BshConsole(); - }*/ - - static class BshPrintStream extends PrintStream { - - public BshPrintStream() { - super(new NullOutputStream()); - } - - public void print(boolean b) { - // System.out.print - } - - public void print(char c) { - super.print(c); - } - - public void print(int i) { - super.print(i); - } - - public void print(long l) { - super.print(l); - } - - public void print(float f) { - super.print(f); - } - - public void print(double d) { - super.print(d); - } - - public void print(char[] s) { - super.print(s); - } - - public void print(String s) { - super.print(s); - } - - public void print(Object obj) { - super.print(obj); - } - - public void println() { - super.println(); - } - - public void println(boolean b) { - super.println(b); - } - - public void println(char c) { - super.println(c); - } - - public void println(int i) { - super.println(i); - } - - public void println(long l) { - super.println(l); - } - - public void println(float f) { - super.println(f); - } - - public void println(double d) { - super.println(d); - } - - public void println(char[] s) { - super.println(s); - } - - public void println(String s) { - super.println(s); - } - - public void println(Object obj) { - super.println(obj); - } - } - - static class BshConsole implements ConsoleInterface { - - StringReader in = new StringReader("234"); - - public Reader getIn() { - return in;//dummy - } - - public PrintStream getOut() { - return null; - } - - public PrintStream getErr() { - return null; - } - - public void println(Object o) { - } - - public void print(Object o) { - } - - public void error(Object o) { - } - - } - - /** - * Normal usage will be BeanshellCommand filename.bsh But you could also - * inline java code like this: BeanshellCommand -code "new - * JFrame().setVisible(true)"; <p/>BeanshellCommand should start an - * interactive session with beanshell. BeanshellCommand file.bsh should - * interpret and run the script. BeanshellCommand -code "code" should - * interpret and run the code. - */ - public static void showHelp() { - System.err - .println("Usage: \nbsh: interactive beanshell.\n" - + "bsh -help: this usage menu\n" - + "bsh -code CODE: evaluate the following shell code.\n" - + "bsh FILE: run the beanshell interpreter on the source FILE."); - } - - private static void evaluateFile(String arg) { - try { - System.err.println("Evaluating beanshell source=" + arg); - new Interpreter().source(arg); - } catch (IOException e) { - e.printStackTrace(); //To change body of catch statement use - // Options | File Templates. - } catch (EvalError evalError) { - evalError.printStackTrace(); //To change body of catch statement - // use Options | File Templates. - } - } - - public static void main(String[] args) { - // System.out.println("Started beanshell command."); - if (args.length == 0) { - //run interactive shell - // System.err.println("Interactive shell not yet written."); - runInteractiveShell(); - return; - } else if (args.length == 1 && args[ 0].toLowerCase().equals("-help")) { - System.err - .println("Usage: bsh: interactive beanshell. <not yet working>\n" - + "bsh FILE: run the beanshell interpreter on the source FILE. <not yet written>\n" - + "bsh -help: this usage menu\n" - + "bsh -code CODE: evaluate the following shell code."); - } else if (args.length == 1) { - evaluateFile(args[ 0]); - } else if (args.length == 2 && args[ 0].toLowerCase().equals("-code")) { - String sourcecode = args[ 1]; - evaluateSourceString(sourcecode); - } else if (args.length == 1 && args[ 0].toLowerCase().equals("-charva")) { - // runCharvaShell(); - } else { - showHelp(); - } - } - - private static void runInteractiveShell() { - System.err.println("Starting Interactive beanshell."); - Reader reader = new InputStreamReader(System.in); - Reader r2 = new BufferedReader(reader); - PrintStream out = new PrintStream(System.out); - PrintStream err = new PrintStream(System.err); - - Interpreter interpreter = new Interpreter(r2, out, err, true); - interpreter.run(); - System.err.println("Finished Interactive beanshell."); - } - - private static void evaluateSourceString(String sourcecode) { - System.out.println("Evaluating source string=" + sourcecode); - try { - Object out = interpreter.eval(sourcecode); - System.out.println(out); - } catch (EvalError evalError) { - evalError.printStackTrace(); //To change body of catch statement - // use Options | File Templates. - } - } - -} Copied: trunk/shell/src/shell/org/jnode/shell/command/bsh/BshCommand.java (from rev 3112, trunk/shell/src/shell/org/jnode/shell/command/bsh/BeanshellCommand.java) =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/bsh/BshCommand.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/command/bsh/BshCommand.java 2007-02-10 19:23:31 UTC (rev 3113) @@ -0,0 +1,116 @@ +/* + * $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.bsh; + +import java.io.*; + +import bsh.Interpreter; +import org.jnode.shell.help.*; +import org.jnode.shell.help.argument.StringArgument; +import org.jnode.shell.help.argument.FileArgument; +import org.jnode.shell.help.argument.OptionArgument; +import org.jnode.shell.CommandLine; + +/** + * @author Levente S\u00e1ntha + */ +public class BshCommand { + + 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) + ); + + public static void main(String[] args) throws Exception { + new BshCommand().execute(new CommandLine(args), System.in, System.out, System.err); + } + + public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception { + ParsedArguments parsedArguments = HELP_INFO.parse(commandLine.toStringArray()); + Interpreter bsh = null; + Object ret; + boolean interactive = false; + + if(PARAM_INTERACTIVE.isSet(parsedArguments)){ + bsh = createInterpreter(in, out, err, true); + interactive = true; + } + + + if (PARAM_C.isSet(parsedArguments)){ + if(bsh == null) + bsh = createInterpreter(in, out, err, false); + + String code = ARG_CODE.getValue(parsedArguments); + ret = bsh.eval(code); + + if(ret != null) + out.println(ret); + } + + + if(PARAM_F.isSet(parsedArguments)){ + if(bsh == null) + bsh = createInterpreter(in, out, err, false); + + String file = ARG_FILE.getValue(parsedArguments); + ret = bsh.source(file); + + if(ret != null) + out.println(ret); + } + + if(bsh == null){ + bsh = createInterpreter(in, out, err, true); + interactive = true; + } + + if(interactive) + bsh.run(); + } + + private static Interpreter createInterpreter(InputStream in, OutputStream out, OutputStream err, boolean interactive){ + return new Interpreter( + new BufferedReader(new InputStreamReader(in)), + new PrintStream(out), + new PrintStream(err), interactive); + } +} Property changes on: trunk/shell/src/shell/org/jnode/shell/command/bsh/BshCommand.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-03-24 07:52:41
|
Revision: 3868 http://jnode.svn.sourceforge.net/jnode/?rev=3868&view=rev Author: crawley Date: 2008-03-24 00:52:38 -0700 (Mon, 24 Mar 2008) Log Message: ----------- Converted cpuid command to new syntax Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.system.xml trunk/shell/src/shell/org/jnode/shell/command/system/CpuIDCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.system.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.system.xml 2008-03-24 07:51:28 UTC (rev 3867) +++ trunk/shell/descriptors/org.jnode.shell.command.system.xml 2008-03-24 07:52:38 UTC (rev 3868) @@ -23,5 +23,9 @@ <alias name="lsirq" class="org.jnode.shell.command.system.LsIRQ"/> <alias name="vminfo" class="org.jnode.vm.Vm"/> </extension> + + <extension point="org.jnode.shell.syntaxes"> + <syntax alias="cpuid"/> + </extension> </plugin> Modified: trunk/shell/src/shell/org/jnode/shell/command/system/CpuIDCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/system/CpuIDCommand.java 2008-03-24 07:51:28 UTC (rev 3867) +++ trunk/shell/src/shell/org/jnode/shell/command/system/CpuIDCommand.java 2008-03-24 07:52:38 UTC (rev 3868) @@ -26,7 +26,6 @@ import org.jnode.shell.AbstractCommand; import org.jnode.shell.CommandLine; -import org.jnode.shell.help.Help; import org.jnode.vm.scheduler.VmProcessor; /** @@ -34,17 +33,18 @@ */ public class CpuIDCommand extends AbstractCommand { - public static Help.Info HELP_INFO = new Help.Info("cpuid", "Show the identification of the current CPU"); + public CpuIDCommand() { + super("Show the identification of the current CPU"); + } public static void main(String[] args) throws Exception { - new CpuIDCommand().execute(args); + new CpuIDCommand().execute(args); } /** * Execute this command */ public void execute(CommandLine cmdLine, InputStream in, PrintStream out, PrintStream err) { - final VmProcessor cpu = VmProcessor.current(); out.println(cpu.getCPUID()); out.println(cpu.getPerformanceCounters()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-03-27 12:06:59
|
Revision: 3889 http://jnode.svn.sourceforge.net/jnode/?rev=3889&view=rev Author: crawley Date: 2008-03-27 05:06:55 -0700 (Thu, 27 Mar 2008) Log Message: ----------- Converted 'alias' command to use new syntax system Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/AliasCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-03-27 12:05:55 UTC (rev 3888) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-03-27 12:06:55 UTC (rev 3889) @@ -49,11 +49,20 @@ <extension point="org.jnode.shell.syntaxes"> <syntax alias="set"> - <sequence> + <sequence description="set a system property"> <argument argLabel="key"/> <argument argLabel="value"/> </sequence> + <argument description="remove a system property" argLabel="key"/> </syntax> + <syntax alias="alias"> + <empty description="list all aliases"/> + <option argLabel="remove" shortName="r" description="remove an alias"/> + <sequence description="create or update an alias"> + <argument argLabel="alias"/> + <argument argLabel="classname"/> + </sequence> + </syntax> </extension> <extension point="org.jnode.security.permissions"> Modified: trunk/shell/src/shell/org/jnode/shell/command/AliasCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/AliasCommand.java 2008-03-27 12:05:55 UTC (rev 3888) +++ trunk/shell/src/shell/org/jnode/shell/command/AliasCommand.java 2008-03-27 12:06:55 UTC (rev 3889) @@ -28,48 +28,34 @@ import org.jnode.shell.AbstractCommand; import org.jnode.shell.CommandLine; -import org.jnode.shell.Shell; import org.jnode.shell.ShellUtils; import org.jnode.shell.alias.AliasManager; import org.jnode.shell.alias.NoSuchAliasException; -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.AliasArgument; -import org.jnode.shell.help.argument.ClassNameArgument; +import org.jnode.shell.syntax.AliasArgument; +import org.jnode.shell.syntax.Argument; +import org.jnode.shell.syntax.ClassNameArgument; /** * @author epr * @author qades * @author Martin Husted Hartvig (ha...@jn...) + * @author cr...@jn... */ public class AliasCommand extends AbstractCommand { - static final AliasArgument ARG_ALIAS = new AliasArgument("alias", - "the alias"); - - static final ClassNameArgument ARG_CLASS = new ClassNameArgument( - "classname", "the classname"); - - static final Parameter PARAM_REMOVE = new Parameter("r", - "following alias will be removed", ARG_ALIAS, Parameter.MANDATORY); - private final static String slash_t = ":\t\t"; - public static Help.Info HELP_INFO = new Help.Info( - "alias", - new Syntax[] { - new Syntax( - "Print all available aliases and corresponding classnames"), - new Syntax("Set an aliases for given classnames", - new Parameter[] { - new Parameter(ARG_ALIAS, - Parameter.MANDATORY), - new Parameter(ARG_CLASS, - Parameter.MANDATORY) }), - new Syntax("Remove an alias", - new Parameter[] { PARAM_REMOVE }) }); + private final AliasArgument ARG_ALIAS; + private final ClassNameArgument ARG_CLASS; + private final AliasArgument ARG_REMOVE; + + public AliasCommand() { + super("list, add or remove JNode command aliases"); + ARG_ALIAS = new AliasArgument("alias", Argument.OPTIONAL, "the alias to be added"); + ARG_CLASS = new ClassNameArgument("classname", Argument.OPTIONAL, "the classname"); + ARG_REMOVE = new AliasArgument("remove", Argument.OPTIONAL, "the alias to be removed"); + registerArguments(ARG_ALIAS, ARG_CLASS, ARG_REMOVE); + } public static void main(String[] args) throws Exception { new AliasCommand().execute(args); @@ -90,20 +76,17 @@ public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception { - ParsedArguments parsedArguments = HELP_INFO.parse(commandLine); + final AliasManager aliasMgr = ShellUtils.getCurrentAliasManager(); - final Shell shell = ShellUtils.getShellManager().getCurrentShell(); - final AliasManager aliasMgr = shell.getAliasManager(); - - if (parsedArguments.size() == 0) { - showAliases(aliasMgr, out); - } else if (PARAM_REMOVE.isSet(parsedArguments)) { + if (ARG_REMOVE.isSet()) { // remove an alias - aliasMgr.remove(ARG_ALIAS.getValue(parsedArguments)); - } else { + aliasMgr.remove(ARG_REMOVE.getValue()); + } else if (ARG_ALIAS.isSet()) { // add an alias - aliasMgr.add(ARG_ALIAS.getValue(parsedArguments), ARG_CLASS - .getValue(parsedArguments)); - } + aliasMgr.add(ARG_ALIAS.getValue(), ARG_CLASS.getValue()); + } else { + // list the aliases + showAliases(aliasMgr, out); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-03-28 15:09:24
|
Revision: 3896 http://jnode.svn.sourceforge.net/jnode/?rev=3896&view=rev Author: crawley Date: 2008-03-28 08:09:17 -0700 (Fri, 28 Mar 2008) Log Message: ----------- Converted the 'class' command to new-style syntax and fixed permissions problems. Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/ClassCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-03-28 15:08:06 UTC (rev 3895) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-03-28 15:09:17 UTC (rev 3896) @@ -48,13 +48,6 @@ </extension> <extension point="org.jnode.shell.syntaxes"> - <syntax alias="set"> - <sequence description="set a system property"> - <argument argLabel="key"/> - <argument argLabel="value"/> - </sequence> - <argument description="remove a system property" argLabel="key"/> - </syntax> <syntax alias="alias"> <empty description="list all aliases"/> <option argLabel="remove" shortName="r" description="remove an alias"/> @@ -63,6 +56,16 @@ <argument argLabel="classname"/> </sequence> </syntax> + <syntax alias="class"> + <argument argLabel="classname" description="list details of a Java class"/> + </syntax> + <syntax alias="set"> + <sequence description="set a system property"> + <argument argLabel="key"/> + <argument argLabel="value"/> + </sequence> + <argument description="remove a system property" argLabel="key"/> + </syntax> </extension> <extension point="org.jnode.security.permissions"> Modified: trunk/shell/src/shell/org/jnode/shell/command/ClassCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/ClassCommand.java 2008-03-28 15:08:06 UTC (rev 3895) +++ trunk/shell/src/shell/org/jnode/shell/command/ClassCommand.java 2008-03-28 15:09:17 UTC (rev 3896) @@ -21,43 +21,66 @@ package org.jnode.shell.command; +import java.io.InputStream; import java.io.PrintStream; +import java.security.AccessController; +import java.security.PrivilegedAction; -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; import org.jnode.vm.classmgr.VmArrayClass; import org.jnode.vm.classmgr.VmClassType; import org.jnode.vm.classmgr.VmType; /** * @author Ewout Prangsma (ep...@us...) + * @author cr...@jn... */ -public class ClassCommand { +public class ClassCommand extends AbstractCommand { - static final ClassNameArgument ARG_CLASS = new ClassNameArgument("class", "the class file to view"); + private final ClassNameArgument ARG_CLASS = + new ClassNameArgument("classname", Argument.SINGLE | Argument.MANDATORY, + "the fully qualified Java name of the class to be viewed"); + + public ClassCommand() { + super("View a Java class"); + registerArguments(ARG_CLASS); + } + + public void execute(CommandLine commandLine, InputStream in, + PrintStream out, PrintStream err) throws Exception { + String className = ARG_CLASS.getValue(); + final ClassLoader cl = Thread.currentThread().getContextClassLoader(); + final Class<?> type = cl.loadClass(className); + showClass(type, out); + } - public static Help.Info HELP_INFO = new Help.Info("class", "View a Java class", new Parameter[] { new Parameter(ARG_CLASS, Parameter.MANDATORY)}); - - public static void main(String[] args) throws Exception { - ParsedArguments cmdLine = HELP_INFO.parse(args); - - String className = ARG_CLASS.getValue(cmdLine); - final ClassLoader cl = Thread.currentThread().getContextClassLoader(); - final Class type = cl.loadClass(className); - showClass(type, System.out); + public static void main(String[] args) throws Exception { + new ClassCommand().execute(args); } - private static void showClass(Class<?> type, PrintStream out) { - final VmType<?> vmType = type.getVmClass(); + private void showClass(final Class<?> type, final PrintStream out) { + final VmType<?> vmType = AccessController.doPrivileged( + new PrivilegedAction<VmType<?>>() { + public VmType<?> run() { + return type.getVmClass(); + } + }); out.println("Name : " + type.getName()); - //out.println("Is abstract : " + type.isAbstract()); + // out.println("Is abstract : " + type.isAbstract()); out.println("Is array : " + type.isArray()); out.println("Is primitive : " + type.isPrimitive()); out.println("Shared statics : " + vmType.isSharedStatics()); out.println("Is initialized : " + vmType.isInitialized()); - out.println("Protection domain: " + type.getProtectionDomain()); + AccessController.doPrivileged( + new PrivilegedAction<Void>() { + public Void run() { + out.println("Protection domain: " + type.getProtectionDomain()); + return null; + } + }); if (vmType instanceof VmClassType) { out.println("#Instances : " + ((VmClassType<?>)vmType).getInstanceCount()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-03-30 02:24:39
|
Revision: 3912 http://jnode.svn.sourceforge.net/jnode/?rev=3912&view=rev Author: crawley Date: 2008-03-29 19:24:36 -0700 (Sat, 29 Mar 2008) Log Message: ----------- Did an eclipse "organize imports" for the shell tree to get rid of unused import warnings. Modified Paths: -------------- trunk/shell/.settings/org.eclipse.jdt.core.prefs trunk/shell/src/shell/org/jnode/shell/CommandLine.java trunk/shell/src/shell/org/jnode/shell/CommandShell.java trunk/shell/src/shell/org/jnode/shell/RedirectingInterpreter.java trunk/shell/src/shell/org/jnode/shell/Shell.java trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneInterpreter.java trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneParser.java trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneTokenizer.java trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneTokenizerTests.java trunk/shell/src/shell/org/jnode/shell/command/DateCommand.java trunk/shell/src/shell/org/jnode/shell/command/DisassembleCommand.java trunk/shell/src/shell/org/jnode/shell/command/EchoCommand.java trunk/shell/src/shell/org/jnode/shell/command/ExecCommand.java trunk/shell/src/shell/org/jnode/shell/command/ExitCommand.java trunk/shell/src/shell/org/jnode/shell/command/GcCommand.java trunk/shell/src/shell/org/jnode/shell/command/HelpCommand.java trunk/shell/src/shell/org/jnode/shell/command/HistoryCommand.java trunk/shell/src/shell/org/jnode/shell/command/KillCommand.java trunk/shell/src/shell/org/jnode/shell/command/MemoryCommand.java trunk/shell/src/shell/org/jnode/shell/command/OnHeapCommand.java trunk/shell/src/shell/org/jnode/shell/command/RunCommand.java trunk/shell/src/shell/org/jnode/shell/command/SetCommand.java trunk/shell/src/shell/org/jnode/shell/command/bsh/BshCommand.java trunk/shell/src/shell/org/jnode/shell/command/debug/DebugCommand.java trunk/shell/src/shell/org/jnode/shell/command/debug/UDPOutputCommand.java trunk/shell/src/shell/org/jnode/shell/command/test/SuiteCommand.java trunk/shell/src/shell/org/jnode/shell/command/unix/UnixTestCommand.java trunk/shell/src/shell/org/jnode/shell/proclet/AbstractProxyPrintStream.java trunk/shell/src/shell/org/jnode/shell/proclet/ProcletContext.java trunk/shell/src/shell/org/jnode/shell/proclet/ProcletIOContext.java trunk/shell/src/shell/org/jnode/shell/proclet/ProcletProxyInputStream.java trunk/shell/src/shell/org/jnode/shell/proclet/ProcletProxyPrintStream.java trunk/shell/src/shell/org/jnode/shell/proclet/ProxyStream.java trunk/shell/src/test/org/jnode/test/shell/Cassowary.java trunk/shell/src/test/org/jnode/test/shell/CompletionInfoTest.java trunk/shell/src/test/org/jnode/test/shell/CompletionTest.java trunk/shell/src/test/org/jnode/test/shell/DeviceManager.java trunk/shell/src/test/org/jnode/test/shell/syntax/AlternativesSyntaxTest.java trunk/shell/src/test/org/jnode/test/shell/syntax/ArgumentMultiplicityTest.java trunk/shell/src/test/org/jnode/test/shell/syntax/ArgumentTypesTest.java trunk/shell/src/test/org/jnode/test/shell/syntax/CommandLineTest.java trunk/shell/src/test/org/jnode/test/shell/syntax/MuParserTest.java trunk/shell/src/test/org/jnode/test/shell/syntax/MuParserTest2.java trunk/shell/src/test/org/jnode/test/shell/syntax/OptionSetSyntaxTest.java trunk/shell/src/test/org/jnode/test/shell/syntax/OptionSyntaxTest.java trunk/shell/src/test/org/jnode/test/shell/syntax/PowersetSyntaxTest.java trunk/shell/src/test/org/jnode/test/shell/syntax/RepeatedSyntaxTest.java trunk/shell/src/test/org/jnode/test/shell/syntax/SequenceSyntaxTest.java Modified: trunk/shell/.settings/org.eclipse.jdt.core.prefs =================================================================== --- trunk/shell/.settings/org.eclipse.jdt.core.prefs 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/.settings/org.eclipse.jdt.core.prefs 2008-03-30 02:24:36 UTC (rev 3912) @@ -1,12 +1,56 @@ -#Tue Apr 12 20:13:19 CEST 2005 +#Sun Mar 30 11:39:36 EST 2008 eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 +org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning +org.eclipse.jdt.core.compiler.problem.autoboxing=ignore +org.eclipse.jdt.core.compiler.problem.deprecation=warning +org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled +org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled +org.eclipse.jdt.core.compiler.problem.discouragedReference=warning +org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore +org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore +org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled +org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore +org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning +org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning +org.eclipse.jdt.core.compiler.problem.forbiddenReference=error +org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning +org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning +org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore +org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore +org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore +org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning +org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning +org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning +org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning +org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore +org.eclipse.jdt.core.compiler.problem.nullReference=ignore +org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning +org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore +org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore +org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore +org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning +org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore +org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled +org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning +org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore +org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning +org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore +org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning +org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore +org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore +org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled +org.eclipse.jdt.core.compiler.problem.unusedImport=warning +org.eclipse.jdt.core.compiler.problem.unusedLabel=warning +org.eclipse.jdt.core.compiler.problem.unusedLocal=warning +org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled +org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning +org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning Modified: trunk/shell/src/shell/org/jnode/shell/CommandLine.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/CommandLine.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/CommandLine.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -29,11 +29,10 @@ import org.jnode.shell.help.Help; import org.jnode.shell.help.HelpException; import org.jnode.shell.help.Parameter; - -import org.jnode.shell.syntax.CommandSyntaxException; -import org.jnode.shell.syntax.FileArgument; import org.jnode.shell.syntax.ArgumentBundle; import org.jnode.shell.syntax.ArgumentSyntax; +import org.jnode.shell.syntax.CommandSyntaxException; +import org.jnode.shell.syntax.FileArgument; import org.jnode.shell.syntax.RepeatSyntax; import org.jnode.shell.syntax.Syntax; Modified: trunk/shell/src/shell/org/jnode/shell/CommandShell.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/CommandShell.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/CommandShell.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -21,18 +21,18 @@ package org.jnode.shell; +import java.io.BufferedReader; import java.io.Closeable; import java.io.File; +import java.io.FileReader; import java.io.FilterInputStream; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintStream; import java.io.Reader; import java.io.StringReader; -import java.io.IOException; -import java.io.BufferedReader; -import java.io.FileReader; import java.security.AccessController; import java.security.PrivilegedAction; import java.text.DateFormat; @@ -42,12 +42,12 @@ import javax.naming.NameNotFoundException; import org.apache.log4j.Logger; -import org.jnode.driver.console.InputHistory; import org.jnode.driver.console.CompletionInfo; +import org.jnode.driver.console.ConsoleEvent; +import org.jnode.driver.console.ConsoleListener; import org.jnode.driver.console.ConsoleManager; +import org.jnode.driver.console.InputHistory; import org.jnode.driver.console.TextConsole; -import org.jnode.driver.console.ConsoleListener; -import org.jnode.driver.console.ConsoleEvent; import org.jnode.driver.console.textscreen.KeyboardInputStream; import org.jnode.naming.InitialNaming; import org.jnode.shell.alias.AliasManager; Modified: trunk/shell/src/shell/org/jnode/shell/RedirectingInterpreter.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/RedirectingInterpreter.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/RedirectingInterpreter.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -33,12 +33,6 @@ import java.util.List; import org.apache.log4j.Logger; -import org.jnode.driver.console.CompletionInfo; -import org.jnode.shell.help.Argument; -import org.jnode.shell.help.CompletionException; -import org.jnode.shell.help.Help; -import org.jnode.shell.help.Parameter; -import org.jnode.shell.help.argument.AliasArgument; import org.jnode.shell.help.argument.FileArgument; import org.jnode.shell.syntax.CommandSyntaxException; Modified: trunk/shell/src/shell/org/jnode/shell/Shell.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/Shell.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/Shell.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -21,11 +21,11 @@ package org.jnode.shell; -import org.jnode.shell.alias.AliasManager; -import org.jnode.shell.syntax.SyntaxManager; import org.jnode.driver.console.Console; import org.jnode.driver.console.InputCompleter; import org.jnode.driver.console.InputHistory; +import org.jnode.shell.alias.AliasManager; +import org.jnode.shell.syntax.SyntaxManager; /** * @author epr Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneInterpreter.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneInterpreter.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneInterpreter.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -16,7 +16,6 @@ import java.io.PrintStream; import java.util.HashMap; -import org.jnode.shell.Command; import org.jnode.shell.CommandInfo; import org.jnode.shell.CommandInterpreter; import org.jnode.shell.CommandLine; Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneParser.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneParser.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneParser.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -1,7 +1,5 @@ package org.jnode.shell.bjorne; -import static org.jnode.shell.bjorne.BjorneToken.TOK_END_OF_LINE; -import static org.jnode.shell.bjorne.BjorneToken.TOK_END_OF_STREAM; import static org.jnode.shell.bjorne.BjorneInterpreter.CMD_BRACE_GROUP; import static org.jnode.shell.bjorne.BjorneInterpreter.CMD_COMMAND; import static org.jnode.shell.bjorne.BjorneInterpreter.CMD_ELIF; @@ -36,6 +34,8 @@ import static org.jnode.shell.bjorne.BjorneToken.TOK_DSEMI; import static org.jnode.shell.bjorne.BjorneToken.TOK_ELIF; import static org.jnode.shell.bjorne.BjorneToken.TOK_ELSE; +import static org.jnode.shell.bjorne.BjorneToken.TOK_END_OF_LINE; +import static org.jnode.shell.bjorne.BjorneToken.TOK_END_OF_STREAM; import static org.jnode.shell.bjorne.BjorneToken.TOK_ESAC; import static org.jnode.shell.bjorne.BjorneToken.TOK_FI; import static org.jnode.shell.bjorne.BjorneToken.TOK_FOR; Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneTokenizer.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneTokenizer.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneTokenizer.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -1,7 +1,5 @@ package org.jnode.shell.bjorne; -import static org.jnode.shell.bjorne.BjorneToken.TOK_END_OF_LINE; -import static org.jnode.shell.bjorne.BjorneToken.TOK_END_OF_STREAM; import static org.jnode.shell.bjorne.BjorneToken.RULE_1_CONTEXT; import static org.jnode.shell.bjorne.BjorneToken.RULE_5_CONTEXT; import static org.jnode.shell.bjorne.BjorneToken.RULE_6_CONTEXT; @@ -23,6 +21,8 @@ import static org.jnode.shell.bjorne.BjorneToken.TOK_DSEMI; import static org.jnode.shell.bjorne.BjorneToken.TOK_ELIF; import static org.jnode.shell.bjorne.BjorneToken.TOK_ELSE; +import static org.jnode.shell.bjorne.BjorneToken.TOK_END_OF_LINE; +import static org.jnode.shell.bjorne.BjorneToken.TOK_END_OF_STREAM; import static org.jnode.shell.bjorne.BjorneToken.TOK_ESAC; import static org.jnode.shell.bjorne.BjorneToken.TOK_FI; import static org.jnode.shell.bjorne.BjorneToken.TOK_FOR; Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneTokenizerTests.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneTokenizerTests.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneTokenizerTests.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -1,7 +1,5 @@ package org.jnode.shell.bjorne; -import static org.jnode.shell.bjorne.BjorneToken.TOK_END_OF_LINE; -import static org.jnode.shell.bjorne.BjorneToken.TOK_END_OF_STREAM; import static org.jnode.shell.bjorne.BjorneToken.RULE_1_CONTEXT; import static org.jnode.shell.bjorne.BjorneToken.RULE_5_CONTEXT; import static org.jnode.shell.bjorne.BjorneToken.RULE_6_CONTEXT; @@ -23,6 +21,8 @@ import static org.jnode.shell.bjorne.BjorneToken.TOK_DSEMI; import static org.jnode.shell.bjorne.BjorneToken.TOK_ELIF; import static org.jnode.shell.bjorne.BjorneToken.TOK_ELSE; +import static org.jnode.shell.bjorne.BjorneToken.TOK_END_OF_LINE; +import static org.jnode.shell.bjorne.BjorneToken.TOK_END_OF_STREAM; import static org.jnode.shell.bjorne.BjorneToken.TOK_ESAC; import static org.jnode.shell.bjorne.BjorneToken.TOK_FI; import static org.jnode.shell.bjorne.BjorneToken.TOK_FOR; Modified: trunk/shell/src/shell/org/jnode/shell/command/DateCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/DateCommand.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/command/DateCommand.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -25,7 +25,7 @@ import javax.naming.NameNotFoundException; -import org.jnode.shell.help.*; +import org.jnode.shell.help.Help; /** * A shell command to access the display the system date. Modified: trunk/shell/src/shell/org/jnode/shell/command/DisassembleCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/DisassembleCommand.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/command/DisassembleCommand.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -21,6 +21,8 @@ package org.jnode.shell.command; +import java.io.OutputStreamWriter; + import org.jnode.shell.help.Help; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; @@ -29,8 +31,6 @@ import org.jnode.shell.help.argument.StringArgument; import org.jnode.vm.classmgr.VmType; -import java.io.OutputStreamWriter; - /** * @author Levente S\u00e1ntha */ Modified: trunk/shell/src/shell/org/jnode/shell/command/EchoCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/EchoCommand.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/command/EchoCommand.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -27,8 +27,9 @@ import org.jnode.shell.AbstractCommand; import org.jnode.shell.CommandLine; -import org.jnode.shell.Command; -import org.jnode.shell.help.*; +import org.jnode.shell.help.Argument; +import org.jnode.shell.help.Help; +import org.jnode.shell.help.Parameter; import org.jnode.shell.help.argument.StringArgument; /** Modified: trunk/shell/src/shell/org/jnode/shell/command/ExecCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/ExecCommand.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/command/ExecCommand.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -26,7 +26,9 @@ import org.jnode.shell.AbstractCommand; import org.jnode.shell.CommandLine; -import org.jnode.shell.help.*; +import org.jnode.shell.help.Argument; +import org.jnode.shell.help.Help; +import org.jnode.shell.help.Parameter; import org.jnode.shell.help.argument.ClassNameArgument; /** Modified: trunk/shell/src/shell/org/jnode/shell/command/ExitCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/ExitCommand.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/command/ExitCommand.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -1,5 +1,8 @@ package org.jnode.shell.command; +import java.io.InputStream; +import java.io.PrintStream; + import org.jnode.naming.InitialNaming; import org.jnode.shell.AbstractCommand; import org.jnode.shell.CommandLine; @@ -7,9 +10,6 @@ import org.jnode.shell.ShellManager; import org.jnode.shell.help.Help; -import java.io.InputStream; -import java.io.PrintStream; - /** * @author Levente S\u00e1ntha */ Modified: trunk/shell/src/shell/org/jnode/shell/command/GcCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/GcCommand.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/command/GcCommand.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -26,10 +26,10 @@ import org.jnode.shell.AbstractCommand; import org.jnode.shell.CommandLine; -import org.jnode.shell.help.*; +import org.jnode.shell.help.Help; +import org.jnode.util.NumberUtils; import org.jnode.vm.Vm; import org.jnode.vm.memmgr.GCStatistics; -import org.jnode.util.NumberUtils; /** * @author epr Modified: trunk/shell/src/shell/org/jnode/shell/command/HelpCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/HelpCommand.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/command/HelpCommand.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -21,8 +21,6 @@ package org.jnode.shell.command; -import java.lang.reflect.Field; - import javax.naming.NameNotFoundException; import org.jnode.shell.AbstractCommand; @@ -34,9 +32,7 @@ import org.jnode.shell.help.HelpException; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; -import org.jnode.shell.help.Help.Info; import org.jnode.shell.help.argument.AliasArgument; -import org.jnode.shell.syntax.Argument; import org.jnode.shell.syntax.ArgumentBundle; import org.jnode.shell.syntax.Syntax; import org.jnode.shell.syntax.SyntaxManager; Modified: trunk/shell/src/shell/org/jnode/shell/command/HistoryCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/HistoryCommand.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/command/HistoryCommand.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -20,14 +20,17 @@ */ package org.jnode.shell.command; -import java.io.PrintStream; -import javax.naming.NameNotFoundException; +import java.io.PrintStream; +import javax.naming.NameNotFoundException; + import org.jnode.driver.console.InputHistory; -import org.jnode.shell.help.*; +import org.jnode.shell.Shell; +import org.jnode.shell.ShellUtils; +import org.jnode.shell.help.Help; +import org.jnode.shell.help.Parameter; +import org.jnode.shell.help.Syntax; import org.jnode.shell.help.argument.OptionArgument; -import org.jnode.shell.Shell; -import org.jnode.shell.ShellUtils; /** A shell command to access the data in the CommandHistory class. * @author Matt Paine Modified: trunk/shell/src/shell/org/jnode/shell/command/KillCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/KillCommand.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/command/KillCommand.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -27,9 +27,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.Syntax; -import org.jnode.shell.help.Parameter; import org.jnode.shell.help.argument.IntegerArgument; /** Modified: trunk/shell/src/shell/org/jnode/shell/command/MemoryCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/MemoryCommand.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/command/MemoryCommand.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -26,7 +26,6 @@ import org.jnode.shell.AbstractCommand; import org.jnode.shell.CommandLine; -import org.jnode.shell.Command; import org.jnode.shell.help.Help; import org.jnode.util.NumberUtils; Modified: trunk/shell/src/shell/org/jnode/shell/command/OnHeapCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/OnHeapCommand.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/command/OnHeapCommand.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -25,13 +25,11 @@ import java.io.PrintStream; import org.jnode.shell.AbstractCommand; -import org.jnode.shell.Command; 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.LongArgument; import org.jnode.shell.help.argument.SizeArgument; import org.jnode.vm.Vm; import org.jnode.vm.memmgr.HeapStatistics; Modified: trunk/shell/src/shell/org/jnode/shell/command/RunCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/RunCommand.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/command/RunCommand.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -1,20 +1,21 @@ package org.jnode.shell.command; +import java.io.File; +import java.io.InputStream; +import java.io.PrintStream; + +import javax.naming.NameNotFoundException; + import org.jnode.shell.AbstractCommand; import org.jnode.shell.CommandLine; +import org.jnode.shell.CommandShell; +import org.jnode.shell.Shell; import org.jnode.shell.ShellUtils; -import org.jnode.shell.Shell; -import org.jnode.shell.CommandShell; import org.jnode.shell.help.Help; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; import org.jnode.shell.help.argument.FileArgument; -import javax.naming.NameNotFoundException; -import java.io.InputStream; -import java.io.PrintStream; -import java.io.File; - /** * Load and execute a command file. * Modified: trunk/shell/src/shell/org/jnode/shell/command/SetCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/SetCommand.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/command/SetCommand.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -21,16 +21,16 @@ package org.jnode.shell.command; +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.PropertyNameArgument; -import org.jnode.shell.syntax.Argument; import org.jnode.shell.syntax.StringArgument; -import org.jnode.shell.AbstractCommand; -import org.jnode.shell.CommandLine; -import java.io.InputStream; -import java.io.PrintStream; - /** * Shell command to set property values. * Modified: trunk/shell/src/shell/org/jnode/shell/command/bsh/BshCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/bsh/BshCommand.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/command/bsh/BshCommand.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -21,16 +21,24 @@ package org.jnode.shell.command.bsh; -import java.io.*; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.PrintStream; -import bsh.Interpreter; -import org.jnode.shell.help.*; -import org.jnode.shell.help.argument.StringArgument; +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.AbstractCommand; -import org.jnode.shell.CommandLine; +import org.jnode.shell.help.argument.StringArgument; +import bsh.Interpreter; + /** * @author Levente S\u00e1ntha */ Modified: trunk/shell/src/shell/org/jnode/shell/command/debug/DebugCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/debug/DebugCommand.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/command/debug/DebugCommand.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -3,12 +3,13 @@ */ package org.jnode.shell.command.debug; +import gnu.classpath.jdwp.JNodeSocketTransport; import gnu.classpath.jdwp.Jdwp; -import gnu.classpath.jdwp.JNodeSocketTransport; -import org.jnode.shell.help.argument.IntegerArgument; + 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; /** * Starts up the remote debugger under JNode. Modified: trunk/shell/src/shell/org/jnode/shell/command/debug/UDPOutputCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/debug/UDPOutputCommand.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/command/debug/UDPOutputCommand.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -32,7 +32,6 @@ import org.jnode.debug.UDPAppender; import org.jnode.debug.UDPOutputStream; import org.jnode.shell.AbstractCommand; -import org.jnode.shell.Command; import org.jnode.shell.CommandLine; import org.jnode.shell.help.Help; import org.jnode.shell.help.Parameter; Modified: trunk/shell/src/shell/org/jnode/shell/command/test/SuiteCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/test/SuiteCommand.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/command/test/SuiteCommand.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -23,9 +23,7 @@ import java.io.InputStream; import java.io.PrintStream; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; import java.util.Set; import junit.framework.Test; Modified: trunk/shell/src/shell/org/jnode/shell/command/unix/UnixTestCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/unix/UnixTestCommand.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/command/unix/UnixTestCommand.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -21,17 +21,17 @@ package org.jnode.shell.command.unix; -import org.jnode.shell.AbstractCommand; -import org.jnode.shell.CommandLine; -import org.jnode.shell.help.SyntaxErrorException; - import java.io.File; import java.io.InputStream; import java.io.PrintStream; import java.util.HashMap; import java.util.Stack; +import org.jnode.shell.AbstractCommand; +import org.jnode.shell.CommandLine; +import org.jnode.shell.help.SyntaxErrorException; + /** * JNode implementation of the UNIX 'test' command * @author cr...@jn... Modified: trunk/shell/src/shell/org/jnode/shell/proclet/AbstractProxyPrintStream.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/proclet/AbstractProxyPrintStream.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/proclet/AbstractProxyPrintStream.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -45,14 +45,14 @@ package org.jnode.shell.proclet; +import gnu.classpath.SystemProperties; + import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; +import java.util.Formatter; import java.util.Locale; -import java.util.Formatter; -import gnu.classpath.SystemProperties; - /** * This class provides some infrastructure for PrintStream proxies. * Modified: trunk/shell/src/shell/org/jnode/shell/proclet/ProcletContext.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/proclet/ProcletContext.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/proclet/ProcletContext.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -29,8 +29,8 @@ import java.util.Properties; import org.jnode.shell.CommandThread; +import org.jnode.vm.VmExit; import org.jnode.vm.VmSystem; -import org.jnode.vm.VmExit; /** * This class implements the proclet-specific state used in the JNode proclet Modified: trunk/shell/src/shell/org/jnode/shell/proclet/ProcletIOContext.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/proclet/ProcletIOContext.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/proclet/ProcletIOContext.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -23,6 +23,7 @@ import java.io.InputStream; import java.io.PrintStream; + import org.jnode.vm.IOContext; import org.jnode.vm.VmSystem; Modified: trunk/shell/src/shell/org/jnode/shell/proclet/ProcletProxyInputStream.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/proclet/ProcletProxyInputStream.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/proclet/ProcletProxyInputStream.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.InputStream; + import org.jnode.vm.VmSystem; /** Modified: trunk/shell/src/shell/org/jnode/shell/proclet/ProcletProxyPrintStream.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/proclet/ProcletProxyPrintStream.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/proclet/ProcletProxyPrintStream.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -22,6 +22,7 @@ package org.jnode.shell.proclet; import java.io.PrintStream; + import org.jnode.vm.VmSystem; /** Modified: trunk/shell/src/shell/org/jnode/shell/proclet/ProxyStream.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/proclet/ProxyStream.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/shell/org/jnode/shell/proclet/ProxyStream.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -23,8 +23,6 @@ import java.io.Closeable; -import org.jnode.shell.proclet.ProxyStreamException; - /** * Proxy streams have an underlying stream and offer methods for getting that * stream. Modified: trunk/shell/src/test/org/jnode/test/shell/Cassowary.java =================================================================== --- trunk/shell/src/test/org/jnode/test/shell/Cassowary.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/test/org/jnode/test/shell/Cassowary.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -23,6 +23,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; + import javax.naming.NameAlreadyBoundException; import javax.naming.NameNotFoundException; import javax.naming.NamingException; Modified: trunk/shell/src/test/org/jnode/test/shell/CompletionInfoTest.java =================================================================== --- trunk/shell/src/test/org/jnode/test/shell/CompletionInfoTest.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/test/org/jnode/test/shell/CompletionInfoTest.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -23,10 +23,10 @@ import java.util.Iterator; import java.util.SortedSet; +import junit.framework.TestCase; + import org.jnode.driver.console.CompletionInfo; -import junit.framework.TestCase; - /** * Test key methods of the CompletionInfo class. * Modified: trunk/shell/src/test/org/jnode/test/shell/CompletionTest.java =================================================================== --- trunk/shell/src/test/org/jnode/test/shell/CompletionTest.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/test/org/jnode/test/shell/CompletionTest.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -20,6 +20,9 @@ */ package org.jnode.test.shell; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; import java.util.Arrays; import java.util.Collection; import java.util.SortedSet; @@ -28,6 +31,8 @@ import javax.naming.NameNotFoundException; import javax.naming.NamingException; +import junit.framework.TestCase; + import org.jnode.driver.console.CompletionInfo; import org.jnode.shell.CommandShell; import org.jnode.shell.DefaultCommandInvoker; @@ -46,12 +51,6 @@ import org.jnode.test.shell.syntax.TestAliasManager; import org.jnode.test.shell.syntax.TestSyntaxManager; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; - -import junit.framework.TestCase; - /** * Test command completion using various interpreters and commands. * Modified: trunk/shell/src/test/org/jnode/test/shell/DeviceManager.java =================================================================== --- trunk/shell/src/test/org/jnode/test/shell/DeviceManager.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/test/org/jnode/test/shell/DeviceManager.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -6,8 +6,13 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; + import org.apache.log4j.Logger; -import org.jnode.driver.*; +import org.jnode.driver.AbstractDeviceManager; +import org.jnode.driver.Device; +import org.jnode.driver.DeviceFinder; +import org.jnode.driver.DeviceToDriverMapper; +import org.jnode.driver.DriverException; /** * @author Levente S\u00e1ntha Modified: trunk/shell/src/test/org/jnode/test/shell/syntax/AlternativesSyntaxTest.java =================================================================== --- trunk/shell/src/test/org/jnode/test/shell/syntax/AlternativesSyntaxTest.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/test/org/jnode/test/shell/syntax/AlternativesSyntaxTest.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -33,12 +33,12 @@ import org.jnode.shell.CommandLine.Token; import org.jnode.shell.syntax.AlternativesSyntax; import org.jnode.shell.syntax.Argument; +import org.jnode.shell.syntax.CommandSyntaxException; import org.jnode.shell.syntax.FileArgument; import org.jnode.shell.syntax.FlagArgument; import org.jnode.shell.syntax.IntegerArgument; import org.jnode.shell.syntax.OptionSyntax; import org.jnode.shell.syntax.Syntax; -import org.jnode.shell.syntax.CommandSyntaxException; public class AlternativesSyntaxTest extends TestCase { Modified: trunk/shell/src/test/org/jnode/test/shell/syntax/ArgumentMultiplicityTest.java =================================================================== --- trunk/shell/src/test/org/jnode/test/shell/syntax/ArgumentMultiplicityTest.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/test/org/jnode/test/shell/syntax/ArgumentMultiplicityTest.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -30,13 +30,12 @@ import org.jnode.shell.Command; import org.jnode.shell.CommandInfo; import org.jnode.shell.CommandLine; -import org.jnode.shell.ShellException; import org.jnode.shell.CommandLine.Token; import org.jnode.shell.syntax.Argument; import org.jnode.shell.syntax.ArgumentSyntax; +import org.jnode.shell.syntax.CommandSyntaxException; import org.jnode.shell.syntax.FileArgument; import org.jnode.shell.syntax.RepeatSyntax; -import org.jnode.shell.syntax.CommandSyntaxException; public class ArgumentMultiplicityTest extends TestCase { Modified: trunk/shell/src/test/org/jnode/test/shell/syntax/ArgumentTypesTest.java =================================================================== --- trunk/shell/src/test/org/jnode/test/shell/syntax/ArgumentTypesTest.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/test/org/jnode/test/shell/syntax/ArgumentTypesTest.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -30,12 +30,11 @@ import org.jnode.shell.Command; import org.jnode.shell.CommandInfo; import org.jnode.shell.CommandLine; -import org.jnode.shell.ShellException; import org.jnode.shell.CommandLine.Token; import org.jnode.shell.syntax.ArgumentSyntax; +import org.jnode.shell.syntax.CommandSyntaxException; import org.jnode.shell.syntax.EnumArgument; import org.jnode.shell.syntax.FileArgument; -import org.jnode.shell.syntax.CommandSyntaxException; public class ArgumentTypesTest extends TestCase { Modified: trunk/shell/src/test/org/jnode/test/shell/syntax/CommandLineTest.java =================================================================== --- trunk/shell/src/test/org/jnode/test/shell/syntax/CommandLineTest.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/test/org/jnode/test/shell/syntax/CommandLineTest.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -30,7 +30,6 @@ import org.jnode.shell.Command; import org.jnode.shell.CommandInfo; import org.jnode.shell.CommandLine; -import org.jnode.shell.ShellException; import org.jnode.shell.SymbolSource; import org.jnode.shell.CommandLine.Token; import org.jnode.shell.syntax.ArgumentSyntax; Modified: trunk/shell/src/test/org/jnode/test/shell/syntax/MuParserTest.java =================================================================== --- trunk/shell/src/test/org/jnode/test/shell/syntax/MuParserTest.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/test/org/jnode/test/shell/syntax/MuParserTest.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -23,13 +23,13 @@ import org.jnode.shell.CommandLine; import org.jnode.shell.NoTokensAvailableException; +import org.jnode.shell.syntax.CommandSyntaxException; import org.jnode.shell.syntax.MuAlternation; import org.jnode.shell.syntax.MuBackReference; import org.jnode.shell.syntax.MuParser; import org.jnode.shell.syntax.MuSequence; import org.jnode.shell.syntax.MuSymbol; import org.jnode.shell.syntax.MuSyntax; -import org.jnode.shell.syntax.CommandSyntaxException; import org.jnode.shell.syntax.SyntaxFailureException; @SuppressWarnings("deprecation") Modified: trunk/shell/src/test/org/jnode/test/shell/syntax/MuParserTest2.java =================================================================== --- trunk/shell/src/test/org/jnode/test/shell/syntax/MuParserTest2.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/test/org/jnode/test/shell/syntax/MuParserTest2.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -29,6 +29,7 @@ import org.jnode.shell.NoTokensAvailableException; import org.jnode.shell.syntax.Argument; import org.jnode.shell.syntax.ArgumentBundle; +import org.jnode.shell.syntax.CommandSyntaxException; import org.jnode.shell.syntax.EnumArgument; import org.jnode.shell.syntax.FileArgument; import org.jnode.shell.syntax.IntegerArgument; @@ -38,7 +39,6 @@ import org.jnode.shell.syntax.MuParser; import org.jnode.shell.syntax.MuSequence; import org.jnode.shell.syntax.MuSyntax; -import org.jnode.shell.syntax.CommandSyntaxException; @SuppressWarnings("deprecation") public class MuParserTest2 extends TestCase { Modified: trunk/shell/src/test/org/jnode/test/shell/syntax/OptionSetSyntaxTest.java =================================================================== --- trunk/shell/src/test/org/jnode/test/shell/syntax/OptionSetSyntaxTest.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/test/org/jnode/test/shell/syntax/OptionSetSyntaxTest.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -30,15 +30,14 @@ import org.jnode.shell.Command; import org.jnode.shell.CommandInfo; import org.jnode.shell.CommandLine; -import org.jnode.shell.ShellException; import org.jnode.shell.CommandLine.Token; import org.jnode.shell.syntax.Argument; +import org.jnode.shell.syntax.CommandSyntaxException; import org.jnode.shell.syntax.FileArgument; import org.jnode.shell.syntax.FlagArgument; import org.jnode.shell.syntax.IntegerArgument; import org.jnode.shell.syntax.OptionSetSyntax; import org.jnode.shell.syntax.OptionSyntax; -import org.jnode.shell.syntax.CommandSyntaxException; public class OptionSetSyntaxTest extends TestCase { Modified: trunk/shell/src/test/org/jnode/test/shell/syntax/OptionSyntaxTest.java =================================================================== --- trunk/shell/src/test/org/jnode/test/shell/syntax/OptionSyntaxTest.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/test/org/jnode/test/shell/syntax/OptionSyntaxTest.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -30,16 +30,15 @@ import org.jnode.shell.Command; import org.jnode.shell.CommandInfo; import org.jnode.shell.CommandLine; -import org.jnode.shell.ShellException; import org.jnode.shell.CommandLine.Token; import org.jnode.shell.syntax.Argument; +import org.jnode.shell.syntax.CommandSyntaxException; import org.jnode.shell.syntax.FileArgument; import org.jnode.shell.syntax.FlagArgument; import org.jnode.shell.syntax.IntegerArgument; import org.jnode.shell.syntax.OptionSyntax; import org.jnode.shell.syntax.RepeatSyntax; import org.jnode.shell.syntax.Syntax; -import org.jnode.shell.syntax.CommandSyntaxException; public class OptionSyntaxTest extends TestCase { Modified: trunk/shell/src/test/org/jnode/test/shell/syntax/PowersetSyntaxTest.java =================================================================== --- trunk/shell/src/test/org/jnode/test/shell/syntax/PowersetSyntaxTest.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/test/org/jnode/test/shell/syntax/PowersetSyntaxTest.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -30,16 +30,15 @@ import org.jnode.shell.Command; import org.jnode.shell.CommandInfo; import org.jnode.shell.CommandLine; -import org.jnode.shell.ShellException; import org.jnode.shell.CommandLine.Token; import org.jnode.shell.syntax.Argument; import org.jnode.shell.syntax.ArgumentBundle; +import org.jnode.shell.syntax.CommandSyntaxException; import org.jnode.shell.syntax.FileArgument; import org.jnode.shell.syntax.IntegerArgument; import org.jnode.shell.syntax.OptionSyntax; import org.jnode.shell.syntax.PowersetSyntax; import org.jnode.shell.syntax.Syntax; -import org.jnode.shell.syntax.CommandSyntaxException; public class PowersetSyntaxTest extends TestCase { Modified: trunk/shell/src/test/org/jnode/test/shell/syntax/RepeatedSyntaxTest.java =================================================================== --- trunk/shell/src/test/org/jnode/test/shell/syntax/RepeatedSyntaxTest.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/test/org/jnode/test/shell/syntax/RepeatedSyntaxTest.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -30,14 +30,13 @@ import org.jnode.shell.Command; import org.jnode.shell.CommandInfo; import org.jnode.shell.CommandLine; -import org.jnode.shell.ShellException; import org.jnode.shell.CommandLine.Token; import org.jnode.shell.syntax.Argument; import org.jnode.shell.syntax.ArgumentSyntax; +import org.jnode.shell.syntax.CommandSyntaxException; import org.jnode.shell.syntax.FileArgument; import org.jnode.shell.syntax.RepeatSyntax; import org.jnode.shell.syntax.Syntax; -import org.jnode.shell.syntax.CommandSyntaxException; public class RepeatedSyntaxTest extends TestCase { Modified: trunk/shell/src/test/org/jnode/test/shell/syntax/SequenceSyntaxTest.java =================================================================== --- trunk/shell/src/test/org/jnode/test/shell/syntax/SequenceSyntaxTest.java 2008-03-30 02:20:56 UTC (rev 3911) +++ trunk/shell/src/test/org/jnode/test/shell/syntax/SequenceSyntaxTest.java 2008-03-30 02:24:36 UTC (rev 3912) @@ -30,16 +30,15 @@ import org.jnode.shell.Command; import org.jnode.shell.CommandInfo; import org.jnode.shell.CommandLine; -import org.jnode.shell.ShellException; import org.jnode.shell.CommandLine.Token; import org.jnode.shell.syntax.Argument; import org.jnode.shell.syntax.ArgumentSyntax; +import org.jnode.shell.syntax.CommandSyntaxException; import org.jnode.shell.syntax.FileArgument; import org.jnode.shell.syntax.IntegerArgument; import org.jnode.shell.syntax.RepeatSyntax; import org.jnode.shell.syntax.SequenceSyntax; import org.jnode.shell.syntax.Syntax; -import org.jnode.shell.syntax.CommandSyntaxException; public class SequenceSyntaxTest extends TestCase { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-04-03 13:16:42
|
Revision: 3923 http://jnode.svn.sourceforge.net/jnode/?rev=3923&view=rev Author: crawley Date: 2008-04-03 06:16:36 -0700 (Thu, 03 Apr 2008) Log Message: ----------- Convert ClasspathCommand to new syntax mechanism. Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/ClasspathCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-03 13:15:29 UTC (rev 3922) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-03 13:16:36 UTC (rev 3923) @@ -59,6 +59,12 @@ <syntax alias="class"> <argument argLabel="classname" description="list details of a Java class"/> </syntax> + <syntax alias="classpath"> + <empty description="print the current classpath"/> + <option argLabel="addurl" longName="add" description="add a URL to the classpath"/> + <option argLabel="clear" longName="clear" description="remove all URLs from the classpath"/> + <option argLabel="refresh" longName="refresh" description="refresh the loaded classes on next use"/> + </syntax> <syntax alias="set"> <sequence description="set a system property"> <argument argLabel="key"/> Modified: trunk/shell/src/shell/org/jnode/shell/command/ClasspathCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/ClasspathCommand.java 2008-04-03 13:15:29 UTC (rev 3922) +++ trunk/shell/src/shell/org/jnode/shell/command/ClasspathCommand.java 2008-04-03 13:16:36 UTC (rev 3923) @@ -21,83 +21,82 @@ package org.jnode.shell.command; +import java.io.InputStream; import java.io.PrintStream; -import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; -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.OptionArgument; -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.URLArgument; /** * @author Ewout Prangsma (ep...@us...) * @author Levente S\u00e1ntha + * @author cr...@jn... */ -public class ClasspathCommand { +public class ClasspathCommand extends AbstractCommand { + + private final URLArgument ARG_ADD = + new URLArgument("addurl", Argument.OPTIONAL, "the URL to be added to the classpath"); + + private final FlagArgument ARG_CLEAR = + new FlagArgument("clear", Argument.OPTIONAL); + + private final FlagArgument ARG_REFRESH = + new FlagArgument("refresh", Argument.OPTIONAL); + + public ClasspathCommand() { + super("Print, modify or refresh the classpath"); + registerArguments(ARG_ADD, ARG_CLEAR, ARG_REFRESH); + } - static final OptionArgument ARG_ACTION = new OptionArgument("action", - "action to do on the classpath", new OptionArgument.Option("add", - "Add an URL to the classpath"), new OptionArgument.Option( - "clear", "Remove all URL's from the classpath"), new OptionArgument.Option( - "refresh", "Refresh the loaded classes on next use")); - - static final URLArgument ARG_URL = new URLArgument("url", "the url"); - - static final Parameter PARAM_ACTION = new Parameter(ARG_ACTION); - - static final Parameter PARAM_URL = new Parameter(ARG_URL, true); - - public static Help.Info HELP_INFO = new Help.Info( - "classpath", - new Syntax[] { new Syntax("Print the current classpath"), - new Syntax("Modify the classpath", PARAM_ACTION, PARAM_URL) }); - - public static void main(String[] args) throws SyntaxErrorException, - MalformedURLException { - final ParsedArguments cmdLine = HELP_INFO.parse(args); - - if (PARAM_ACTION.isSet(cmdLine)) { - final String action = ARG_ACTION.getValue(cmdLine); - if (action.equals("add")) { - if (PARAM_URL.isSet(cmdLine)) { - addClassPath(ARG_URL.getURL(cmdLine)); - } else { - throw new SyntaxErrorException("URL expected"); - } - } else if (action.equals("clear")) { - clearClassPath(); - } else if (action.equals("refresh")) { - refreshClassPath(); - } - } else { - printClassPath(); - } + public static void main(String[] args) throws Exception { + new ClasspathCommand().execute(args); } + + @Override + public void execute(CommandLine commandLine, InputStream in, + PrintStream out, PrintStream err) throws Exception { + if (ARG_ADD.isSet()) { + addToClassPath(ARG_ADD.getValueAsURL()); + } + else if (ARG_CLEAR.isSet()) { + clearClassPath(); + } + else if (ARG_REFRESH.isSet()) { + refreshClassPath(); + } + else { + printClassPath(out); + } + } - private static void refreshClassPath() { + private void refreshClassPath() { URL[] urls = getClassLoader().getURLs(); clearClassPath(); - if(urls != null) - for(URL url : urls) - addClassPath(url); + if (urls != null) { + for (URL url : urls) { + addToClassPath(url); + } + } } - private static void addClassPath(URL url) { + private void addToClassPath(URL url) { URL[] urls = getClassLoader().getURLs(); - if(urls != null) - for(URL u : urls) - if(u.equals(url)) + if (urls != null) { + for (URL u : urls) { + if (u.equals(url)) { return; - + } + } + } getClassLoader().add(url); } - private static void clearClassPath() { + private void clearClassPath() { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl instanceof CPClassLoader) { cl = new CPClassLoader(cl.getParent()); @@ -105,11 +104,11 @@ } } - private static void printClassPath() { - getClassLoader().print(System.out); + private void printClassPath(PrintStream out) { + getClassLoader().print(out); } - private static CPClassLoader getClassLoader() { + private CPClassLoader getClassLoader() { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (!(cl instanceof CPClassLoader)) { cl = new CPClassLoader(cl); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-04-06 05:06:45
|
Revision: 3936 http://jnode.svn.sourceforge.net/jnode/?rev=3936&view=rev Author: crawley Date: 2008-04-05 22:06:43 -0700 (Sat, 05 Apr 2008) Log Message: ----------- Recoded 'compile' command to use new syntax mechanism. (It also does completion in the 'level' argument, though more work is needed ...) Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/CompileCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-06 05:04:33 UTC (rev 3935) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-06 05:06:43 UTC (rev 3936) @@ -65,6 +65,15 @@ <option argLabel="clear" longName="clear" description="remove all URLs from the classpath"/> <option argLabel="refresh" longName="refresh" description="refresh the loaded classes on next use"/> </syntax> + <syntax alias="classpath"> + <sequence description="print the current classpath"/> + <optionSet> + <option argLabel="test" longName="test"/> + <option argLabel="level" longName="level"/> + </optionSet> + <argument argLabel="classname"/> + </sequence> + </syntax> <syntax alias="set"> <sequence description="set a system property"> <argument argLabel="key"/> Modified: trunk/shell/src/shell/org/jnode/shell/command/CompileCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/CompileCommand.java 2008-04-06 05:04:33 UTC (rev 3935) +++ trunk/shell/src/shell/org/jnode/shell/command/CompileCommand.java 2008-04-06 05:06:43 UTC (rev 3936) @@ -21,40 +21,79 @@ package org.jnode.shell.command; -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.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.ClassNameArgument; +import org.jnode.shell.syntax.FlagArgument; +import org.jnode.shell.syntax.IntegerArgument; +import org.jnode.vm.VmArchitecture; +import org.jnode.vm.VmMagic; import org.jnode.vm.classmgr.VmType; /** * @author epr + * @author cr...@jn... */ -public class CompileCommand { - - static final ClassNameArgument ARG_CLASS = new ClassNameArgument("className", "the class file to compile"); - static final IntegerArgument ARG_LEVEL = new IntegerArgument("level", "the optimization level"); - static final IntegerArgument ARG_TEST = new IntegerArgument("test", "If 1, the test compilers are used"); - static final Parameter PARAM_LEVEL = new Parameter(ARG_LEVEL, Parameter.OPTIONAL); - static final Parameter PARAM_TEST = new Parameter(ARG_TEST, Parameter.OPTIONAL); +public class CompileCommand extends AbstractCommand { + // FIXME ... it would be good if something exposed the current maximum + // compiler optimization level via(s) a getter method. +// private final VmArchitecture arch = VmMagic.currentProcessor().getArchitecture(); +// private final Object[] compilers = arch.getCompilers(); +// private final Object[] testCompilers = arch.getTestCompilers(); +// private final int maxLevel = Math.max( +// compilers.length, (testCompilers == null) ? 0 : testCompilers.length) - 1; + + // FIXME ... temporary hack until I work out what is causing the System.out stream + // to be toasted in the compiler thread. (The commented out code causes the compiler + // to try to print "MagicPermission is not granted ..." to System.out, and a NPE is + // being thrown because (I think) the proclet context thinks that the global output + // stream is null.) + private final int maxLevel = 3; + + private final ClassNameArgument ARG_CLASS = + new ClassNameArgument("className", Argument.MANDATORY, "the class file to compile"); + private final IntegerArgument ARG_LEVEL = + new IntegerArgument("level", Argument.OPTIONAL, 0, maxLevel, "the optimization level"); + private final FlagArgument ARG_TEST = + new FlagArgument("test", Argument.OPTIONAL, "use the test version of the compiler"); - public static Help.Info HELP_INFO = new Help.Info("compile", "Compile a Java class", new Parameter[] { new Parameter(ARG_CLASS, Parameter.MANDATORY), PARAM_LEVEL, PARAM_TEST}); - + public CompileCommand() { + super("compile a Java class (bytecodes) to native code"); + registerArguments(ARG_CLASS, ARG_LEVEL, ARG_TEST); + } + public static void main(String[] args) throws Exception { - final ParsedArguments cmdLine = HELP_INFO.parse(args); - - final String className = ARG_CLASS.getValue(cmdLine); - final int level = PARAM_LEVEL.isSet(cmdLine) ? ARG_LEVEL.getInteger(cmdLine) : 0; - final boolean test = PARAM_TEST.isSet(cmdLine) ? (ARG_TEST.getInteger(cmdLine) != 0) : false; + new CompileCommand().execute(args); + } + + @Override + public void execute(CommandLine commandLine, InputStream in, + PrintStream out, PrintStream err) + throws Exception { + final String className = ARG_CLASS.getValue(); + final int level = ARG_LEVEL.isSet() ? ARG_LEVEL.getValue() : 0; + final boolean test = ARG_TEST.isSet(); final ClassLoader cl = Thread.currentThread().getContextClassLoader(); - final Class<?> cls = cl.loadClass(className); + final Class<?> cls; + try { + cls = cl.loadClass(className); + } + catch (ClassNotFoundException ex) { + err.println("Class '" + className + "' not found"); + exit(1); + // not reached + return; + } final VmType<?> type = cls.getVmClass(); final long start = System.currentTimeMillis(); final int count = type.compileRuntime(level, test); final long end = System.currentTimeMillis(); - System.out.println("Compiling " + count + " methods took " + (end - start) + "ms"); + out.println("Compiling " + count + " methods took " + (end - start) + "ms"); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-04-06 06:26:56
|
Revision: 3940 http://jnode.svn.sourceforge.net/jnode/?rev=3940&view=rev Author: crawley Date: 2008-04-05 23:26:51 -0700 (Sat, 05 Apr 2008) Log Message: ----------- Enabled code to find out what the max --level should be (hacky). Fixed a couple of syntax issues. Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/CompileCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-06 06:25:22 UTC (rev 3939) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-06 06:26:51 UTC (rev 3940) @@ -65,7 +65,7 @@ <option argLabel="clear" longName="clear" description="remove all URLs from the classpath"/> <option argLabel="refresh" longName="refresh" description="refresh the loaded classes on next use"/> </syntax> - <syntax alias="classpath"> + <syntax alias="compile"> <sequence description="print the current classpath"> <optionSet> <option argLabel="test" longName="test"/> Modified: trunk/shell/src/shell/org/jnode/shell/command/CompileCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/CompileCommand.java 2008-04-06 06:25:22 UTC (rev 3939) +++ trunk/shell/src/shell/org/jnode/shell/command/CompileCommand.java 2008-04-06 06:26:51 UTC (rev 3940) @@ -39,23 +39,16 @@ * @author cr...@jn... */ public class CompileCommand extends AbstractCommand { - // FIXME ... it would be good if something exposed the current maximum - // compiler optimization level via(s) a getter method. -// private final VmArchitecture arch = VmMagic.currentProcessor().getArchitecture(); -// private final Object[] compilers = arch.getCompilers(); -// private final Object[] testCompilers = arch.getTestCompilers(); -// private final int maxLevel = Math.max( -// compilers.length, (testCompilers == null) ? 0 : testCompilers.length) - 1; + // FIXME ... something should exposed the maximum compiler optimization levels + // via getter methods. The code below gives "MagicPermission is not granted ..." + private final VmArchitecture arch = VmMagic.currentProcessor().getArchitecture(); + private final Object[] compilers = arch.getCompilers(); + private final Object[] testCompilers = arch.getTestCompilers(); + private final int maxLevel = Math.max( + compilers.length, (testCompilers == null) ? 0 : testCompilers.length) - 1; - // FIXME ... temporary hack until I work out what is causing the System.out stream - // to be toasted in the compiler thread. (The commented out code causes the compiler - // to try to print "MagicPermission is not granted ..." to System.out, and a NPE is - // being thrown because (I think) the proclet context thinks that the global output - // stream is null.) - private final int maxLevel = 3; - private final ClassNameArgument ARG_CLASS = - new ClassNameArgument("className", Argument.MANDATORY, "the class file to compile"); + new ClassNameArgument("classname", Argument.MANDATORY, "the class file to compile"); private final IntegerArgument ARG_LEVEL = new IntegerArgument("level", Argument.OPTIONAL, 0, maxLevel, "the optimization level"); private final FlagArgument ARG_TEST = This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-04-06 15:07:38
|
Revision: 3941 http://jnode.svn.sourceforge.net/jnode/?rev=3941&view=rev Author: crawley Date: 2008-04-06 08:07:36 -0700 (Sun, 06 Apr 2008) Log Message: ----------- Converted DateCommand to use new syntax mechanism, etc Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/DateCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-06 06:26:51 UTC (rev 3940) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-06 15:07:36 UTC (rev 3941) @@ -74,6 +74,7 @@ <argument argLabel="classname"/> </sequence> </syntax> + <syntax alias="date" description="print the current date"/> <syntax alias="set"> <sequence description="set a system property"> <argument argLabel="key"/> Modified: trunk/shell/src/shell/org/jnode/shell/command/DateCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/DateCommand.java 2008-04-06 06:26:51 UTC (rev 3940) +++ trunk/shell/src/shell/org/jnode/shell/command/DateCommand.java 2008-04-06 15:07:36 UTC (rev 3941) @@ -21,37 +21,36 @@ package org.jnode.shell.command; +import java.io.InputStream; +import java.io.PrintStream; import java.util.Date; -import javax.naming.NameNotFoundException; +import org.jnode.shell.AbstractCommand; +import org.jnode.shell.CommandLine; -import org.jnode.shell.help.Help; - /** * A shell command to access the display the system date. * @author Matt Paine + * @author cr...@jn... */ -public class DateCommand { +public class DateCommand extends AbstractCommand { - public static Help.Info HELP_INFO = new Help.Info( - "date", - "prints the current date" - ); + public DateCommand() { + super("prints the current date"); + } - /** - * Sets up any instance variables and processes the command arguments. - * @param args The arguments to work with. - **/ - public DateCommand(String[] args) throws NameNotFoundException { - System.out.println(new Date()); - } + @Override + public void execute(CommandLine commandLine, InputStream in, + PrintStream out, PrintStream err) throws Exception { + out.println(new Date()); + } - /** - * Displays the system date - * @param args No arguments. - **/ - public static void main(String[] args) throws NameNotFoundException { - new DateCommand(args); - } + /** + * Displays the system date + * @param args No arguments. + **/ + public static void main(String[] args) throws Exception { + new DateCommand().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-08 13:49:44
|
Revision: 3944 http://jnode.svn.sourceforge.net/jnode/?rev=3944&view=rev Author: crawley Date: 2008-04-08 06:49:41 -0700 (Tue, 08 Apr 2008) Log Message: ----------- Converted 'disasm' command to use new syntax mechanism Use camel-case for argument labels in syntaxes, etc Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/AliasCommand.java trunk/shell/src/shell/org/jnode/shell/command/ClassCommand.java trunk/shell/src/shell/org/jnode/shell/command/ClasspathCommand.java trunk/shell/src/shell/org/jnode/shell/command/CompileCommand.java trunk/shell/src/shell/org/jnode/shell/command/DisassembleCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-08 13:47:57 UTC (rev 3943) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-08 13:49:41 UTC (rev 3944) @@ -53,28 +53,40 @@ <option argLabel="remove" shortName="r" description="remove an alias"/> <sequence description="create or update an alias"> <argument argLabel="alias"/> - <argument argLabel="classname"/> + <argument argLabel="className"/> </sequence> </syntax> <syntax alias="class"> - <argument argLabel="classname" description="list details of a Java class"/> + <argument argLabel="className" description="list details of a Java class"/> </syntax> <syntax alias="classpath"> <empty description="print the current classpath"/> - <option argLabel="addurl" longName="add" description="add a URL to the classpath"/> + <option argLabel="addUrl" longName="add" description="add a URL to the classpath"/> <option argLabel="clear" longName="clear" description="remove all URLs from the classpath"/> <option argLabel="refresh" longName="refresh" description="refresh the loaded classes on next use"/> </syntax> <syntax alias="compile"> - <sequence description="print the current classpath"> + <sequence description="compile a class to native code"> <optionSet> <option argLabel="test" longName="test"/> <option argLabel="level" longName="level"/> </optionSet> - <argument argLabel="classname"/> + <argument argLabel="className"/> </sequence> </syntax> <syntax alias="date" description="print the current date"/> + <syntax alias="disasm"> + <sequence description="disassemble a native code class"> + <optionSet> + <option argLabel="test" longName="test"/> + <option argLabel="level" longName="level"/> + </optionSet> + <argument argLabel="className"/> + <repeat minCount="0" maxCount="1"> + <argument argLabel="methodName"/> + </repeat> + </sequence> + </syntax> <syntax alias="set"> <sequence description="set a system property"> <argument argLabel="key"/> Modified: trunk/shell/src/shell/org/jnode/shell/command/AliasCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/AliasCommand.java 2008-04-08 13:47:57 UTC (rev 3943) +++ trunk/shell/src/shell/org/jnode/shell/command/AliasCommand.java 2008-04-08 13:49:41 UTC (rev 3944) @@ -52,7 +52,7 @@ public AliasCommand() { super("list, add or remove JNode command aliases"); ARG_ALIAS = new AliasArgument("alias", Argument.OPTIONAL, "the alias to be added"); - ARG_CLASS = new ClassNameArgument("classname", Argument.OPTIONAL, "the classname"); + ARG_CLASS = new ClassNameArgument("className", Argument.OPTIONAL, "the classname"); ARG_REMOVE = new AliasArgument("remove", Argument.OPTIONAL, "the alias to be removed"); registerArguments(ARG_ALIAS, ARG_CLASS, ARG_REMOVE); } Modified: trunk/shell/src/shell/org/jnode/shell/command/ClassCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/ClassCommand.java 2008-04-08 13:47:57 UTC (rev 3943) +++ trunk/shell/src/shell/org/jnode/shell/command/ClassCommand.java 2008-04-08 13:49:41 UTC (rev 3944) @@ -41,7 +41,7 @@ public class ClassCommand extends AbstractCommand { private final ClassNameArgument ARG_CLASS = - new ClassNameArgument("classname", Argument.SINGLE | Argument.MANDATORY, + new ClassNameArgument("className", Argument.SINGLE | Argument.MANDATORY, "the fully qualified Java name of the class to be viewed"); public ClassCommand() { Modified: trunk/shell/src/shell/org/jnode/shell/command/ClasspathCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/ClasspathCommand.java 2008-04-08 13:47:57 UTC (rev 3943) +++ trunk/shell/src/shell/org/jnode/shell/command/ClasspathCommand.java 2008-04-08 13:49:41 UTC (rev 3944) @@ -40,7 +40,7 @@ public class ClasspathCommand extends AbstractCommand { private final URLArgument ARG_ADD = - new URLArgument("addurl", Argument.OPTIONAL, "the URL to be added to the classpath"); + new URLArgument("addUrl", Argument.OPTIONAL, "the URL to be added to the classpath"); private final FlagArgument ARG_CLEAR = new FlagArgument("clear", Argument.OPTIONAL, "when set, clear the classpath"); Modified: trunk/shell/src/shell/org/jnode/shell/command/CompileCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/CompileCommand.java 2008-04-08 13:47:57 UTC (rev 3943) +++ trunk/shell/src/shell/org/jnode/shell/command/CompileCommand.java 2008-04-08 13:49:41 UTC (rev 3944) @@ -45,7 +45,7 @@ private final int maxLevel = Math.max(maxTestLevel, maxNontestLevel); private final ClassNameArgument ARG_CLASS = - new ClassNameArgument("classname", Argument.MANDATORY, "the class file to compile"); + new ClassNameArgument("className", Argument.MANDATORY, "the class file to compile"); private final IntegerArgument ARG_LEVEL = new IntegerArgument("level", Argument.OPTIONAL, 0, maxLevel, "the optimization level"); private final FlagArgument ARG_TEST = Modified: trunk/shell/src/shell/org/jnode/shell/command/DisassembleCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/DisassembleCommand.java 2008-04-08 13:47:57 UTC (rev 3943) +++ trunk/shell/src/shell/org/jnode/shell/command/DisassembleCommand.java 2008-04-08 13:49:41 UTC (rev 3944) @@ -21,48 +21,86 @@ package org.jnode.shell.command; +import java.io.InputStream; import java.io.OutputStreamWriter; +import java.io.PrintStream; -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.help.argument.IntegerArgument; -import org.jnode.shell.help.argument.StringArgument; +import org.jnode.shell.AbstractCommand; +import org.jnode.shell.CommandLine; +import org.jnode.shell.syntax.Argument; +import org.jnode.shell.syntax.ClassNameArgument; +import org.jnode.shell.syntax.FlagArgument; +import org.jnode.shell.syntax.IntegerArgument; +import org.jnode.shell.syntax.StringArgument; +import org.jnode.vm.LoadCompileService; import org.jnode.vm.classmgr.VmType; /** * @author Levente S\u00e1ntha + * @author cl...@jn... */ -public class DisassembleCommand { +public class DisassembleCommand extends AbstractCommand { + private final int maxTestLevel = + LoadCompileService.getHighestOptimizationLevel(true); + private final int maxNontestLevel = + LoadCompileService.getHighestOptimizationLevel(false); + private final int maxLevel = Math.max(maxTestLevel, maxNontestLevel); + + private final ClassNameArgument ARG_CLASS = + new ClassNameArgument("className", Argument.MANDATORY, "the class to disassemble"); + private final StringArgument ARG_METHOD = + new StringArgument("methodName", Argument.OPTIONAL, "the method to disassemble"); + private final IntegerArgument ARG_LEVEL = + new IntegerArgument("level", Argument.OPTIONAL, 0, maxLevel, "the optimization level"); + private final FlagArgument ARG_TEST = + new FlagArgument("test", Argument.OPTIONAL, "If set, the test compilers are used"); + + public DisassembleCommand() { + super("disassemble a Java class or method"); + registerArguments(ARG_CLASS, ARG_METHOD, ARG_LEVEL, ARG_TEST); + } - static final ClassNameArgument ARG_CLASS = new ClassNameArgument("className", "the class to disassemble"); - static final StringArgument ARG_METHOD = new StringArgument("methodName", "the method to disassemble"); - static final IntegerArgument ARG_LEVEL = new IntegerArgument("level", "the optimization level"); - static final IntegerArgument ARG_TEST = new IntegerArgument("test", "If 1, the test compilers are used"); - static final Parameter PARAM_LEVEL = new Parameter(ARG_LEVEL, Parameter.OPTIONAL); - static final Parameter PARAM_TEST = new Parameter(ARG_TEST, Parameter.OPTIONAL); - - public static Help.Info HELP_INFO = new Help.Info("disasm", "Disassemble a Java class or method", - new Parameter[] { - new Parameter(ARG_CLASS, Parameter.MANDATORY), - new Parameter(ARG_METHOD, Parameter.OPTIONAL), - PARAM_LEVEL, PARAM_TEST}); + public static void main(String[] args) throws Exception { + new DisassembleCommand().execute(args); + } - public static void main(String[] args) throws Exception { - final ParsedArguments cmdLine = HELP_INFO.parse(args); - - final String className = ARG_CLASS.getValue(cmdLine); - final String methodName = ARG_METHOD.getValue(cmdLine); - final int level = PARAM_LEVEL.isSet(cmdLine) ? ARG_LEVEL.getInteger(cmdLine) : 0; - final boolean test = PARAM_TEST.isSet(cmdLine) ? (ARG_TEST.getInteger(cmdLine) != 0) : false; - - final ClassLoader cl = Thread.currentThread().getContextClassLoader(); - final Class<?> cls = cl.loadClass(className); - final VmType<?> type = cls.getVmClass(); - final long start = System.currentTimeMillis(); - final int count = type.disassemble(methodName, level, test, new OutputStreamWriter(System.out)); - final long end = System.currentTimeMillis(); - System.out.println("Disassembling " + count + " methods took " + (end - start) + "ms"); - } + @Override + public void execute(CommandLine commandLine, InputStream in, + PrintStream out, PrintStream err) throws Exception { + final String className = ARG_CLASS.getValue(); + final String methodName = ARG_METHOD.isSet() ? ARG_METHOD.getValue() : null; + final int level = ARG_LEVEL.isSet() ? ARG_LEVEL.getValue() : 0; + final boolean test = ARG_TEST.isSet(); + + final ClassLoader cl = Thread.currentThread().getContextClassLoader(); + Class<?> cls; + try { + cls = cl.loadClass(className); + } + catch (ClassNotFoundException ex) { + err.println("Class '" + className + "' not found"); + exit(1); + // not reached + return; + } + final VmType<?> type = cls.getVmClass(); + if (test) { + if (maxTestLevel == -1) { + err.println("No test compilers are currently registered"); + exit(1); + } + else if (maxTestLevel < level) { + err.println("The highest (test) optimization level is " + maxTestLevel); + exit(1); + } + } + else if (maxNontestLevel < level) { + err.println("The highest optimization level is " + maxNontestLevel); + exit(1); + } + final long start = System.currentTimeMillis(); + final int count = type.disassemble(methodName, level, test, new OutputStreamWriter(out)); + final long end = System.currentTimeMillis(); + out.println("Disassembling " + count + " methods took " + (end - start) + "ms"); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-04-10 14:37:30
|
Revision: 3948 http://jnode.svn.sourceforge.net/jnode/?rev=3948&view=rev Author: crawley Date: 2008-04-10 07:37:15 -0700 (Thu, 10 Apr 2008) Log Message: ----------- Implemented a new command for dumping and loading Syntax specs as XML Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml Added Paths: ----------- trunk/shell/src/shell/org/jnode/shell/command/SyntaxCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-10 14:35:49 UTC (rev 3947) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-10 14:37:15 UTC (rev 3948) @@ -45,6 +45,7 @@ <alias name="locale" class="org.jnode.shell.command.LocaleCommand"/> <alias name="onheap" class="org.jnode.shell.command.OnHeapCommand"/> <alias name="grep" class="org.jnode.shell.command.GrepCommand"/> + <alias name="syntax" class="org.jnode.shell.command.SyntaxCommand"/> </extension> <extension point="org.jnode.shell.syntaxes"> @@ -94,6 +95,22 @@ </sequence> <argument description="remove a system property" argLabel="key"/> </syntax> + <syntax alias="syntax"> + <option argLabel="list" longName="list" shortName="l" description="list aliases with syntaxes"/> + <option argLabel="dumpAll" longName="dump" shortName="d" description="dump all syntaxes"/> + <sequence description="dump the syntax for a given alias"> + <option argLabel="dump" longName="dump" shortName="d"/> + <argument argLabel="alias"/> + </sequence> + <sequence description="load a new syntax for a given alias"> + <option argLabel="file" longName="load" shortName="l"/> + <argument argLabel="alias"/> + </sequence> + <sequence description="set a system property"> + <option argLabel="remove" longName="remove" shortName="r"/> + <argument argLabel="alias"/> + </sequence> + </syntax> </extension> <extension point="org.jnode.security.permissions"> Added: trunk/shell/src/shell/org/jnode/shell/command/SyntaxCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/SyntaxCommand.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/command/SyntaxCommand.java 2008-04-10 14:37:15 UTC (rev 3948) @@ -0,0 +1,144 @@ +/* + * $Id: SetCommand.java 3912 2008-03-30 02:24:36Z 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; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStreamWriter; +import java.io.PrintStream; +import java.io.Writer; + +import nanoxml.XMLElement; + +import org.jnode.shell.AbstractCommand; +import org.jnode.shell.CommandLine; +import org.jnode.shell.ShellUtils; +import org.jnode.shell.syntax.Syntax; +import org.jnode.shell.syntax.AliasArgument; +import org.jnode.shell.syntax.Argument; +import org.jnode.shell.syntax.FileArgument; +import org.jnode.shell.syntax.FlagArgument; +import org.jnode.shell.syntax.SyntaxArgumentMissingException; +import org.jnode.shell.syntax.SyntaxManager; +import org.jnode.shell.syntax.SyntaxSpecLoader; +import org.jnode.shell.syntax.XMLSyntaxSpecAdapter; + + +/** + * Shell command to manage command syntaxes + * + * @author cr...@jn... + */ +public class SyntaxCommand extends AbstractCommand { + + private final AliasArgument ARG_ALIAS = + new AliasArgument("alias", Argument.OPTIONAL, "the target alias"); + private FileArgument ARG_FILE = + new FileArgument("file", Argument.OPTIONAL, "if set, load the syntax from this file"); + private FlagArgument ARG_LIST = + new FlagArgument("list", Argument.OPTIONAL, "if set, list the syntaxes"); + private FlagArgument ARG_REMOVE = + new FlagArgument("remove", Argument.OPTIONAL, "if set, remove the syntaxes for the target alias"); + private FlagArgument ARG_DUMP = + new FlagArgument("dump", Argument.OPTIONAL, "if set, show the syntaxes for the target alias"); + private FlagArgument ARG_DUMP_ALL = + new FlagArgument("dumpAll", Argument.OPTIONAL, "if set, show the syntaxes for all aliases"); + + public SyntaxCommand() { + super("load or clear a syntax for an alias"); + registerArguments(ARG_ALIAS, ARG_FILE, ARG_LIST, ARG_REMOVE, ARG_DUMP, ARG_DUMP_ALL); + } + + public static void main(String[] args) throws Exception { + new SyntaxCommand().execute(args); + } + + public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) + throws Exception { + SyntaxManager synMgr = ShellUtils.getCurrentSyntaxManager(); + + if (ARG_LIST.isSet()) { + for (String key : synMgr.getKeys()) { + out.println(key); + } + } + else if (ARG_DUMP_ALL.isSet()) { + for (String alias : synMgr.getKeys()) { + Syntax syntax = synMgr.getSyntax(alias); + dumpSyntax(alias, syntax, out); + } + } + else { + if (!ARG_ALIAS.isSet()) { + throw new SyntaxArgumentMissingException( + "alias argument required for these flags", ARG_ALIAS); + } + String alias = ARG_ALIAS.getValue(); + if (ARG_DUMP.isSet()) { + Syntax syntax = synMgr.getSyntax(alias); + if (syntax == null) { + err.println("No syntax for alias '" + alias + "'"); + } + else { + dumpSyntax(alias, syntax, out); + } + } + else if (ARG_FILE.isSet()) { + File file = ARG_FILE.getValue(); + XMLElement xml = new XMLElement(); + FileReader reader = null; + try { + reader = new FileReader(file); + xml.parseFromReader(new BufferedReader(reader)); + Syntax syntax = new SyntaxSpecLoader().loadSyntax(new XMLSyntaxSpecAdapter(xml)); + synMgr.add(alias, syntax); + } + catch (IOException ex) { + err.println("Cannot read file '" + file + "': " + ex.getMessage()); + } + finally { + if (reader != null) { + reader.close(); + } + } + } + else if (ARG_REMOVE.isSet()) { + synMgr.remove(alias); + } + } + } + + private void dumpSyntax(String alias, Syntax syntax, PrintStream out) + throws IOException { + XMLElement element = syntax.toXML(); + element.setName("syntax"); + element.setAttribute("alias", alias); + Writer writer = new OutputStreamWriter(out); + element.write(writer); + writer.flush(); + out.println(); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-04-11 11:38:24
|
Revision: 3949 http://jnode.svn.sourceforge.net/jnode/?rev=3949&view=rev Author: crawley Date: 2008-04-11 04:38:22 -0700 (Fri, 11 Apr 2008) Log Message: ----------- Fixed inconsistencies in the syntax of the syntax command. Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/SyntaxCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-10 14:37:15 UTC (rev 3948) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-11 11:38:22 UTC (rev 3949) @@ -96,8 +96,8 @@ <argument description="remove a system property" argLabel="key"/> </syntax> <syntax alias="syntax"> - <option argLabel="list" longName="list" shortName="l" description="list aliases with syntaxes"/> - <option argLabel="dumpAll" longName="dump" shortName="d" description="dump all syntaxes"/> + <empty description="list aliases with syntaxes"/> + <option argLabel="dumpAll" longName="dump-all" description="dump all syntaxes"/> <sequence description="dump the syntax for a given alias"> <option argLabel="dump" longName="dump" shortName="d"/> <argument argLabel="alias"/> Modified: trunk/shell/src/shell/org/jnode/shell/command/SyntaxCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/SyntaxCommand.java 2008-04-10 14:37:15 UTC (rev 3948) +++ trunk/shell/src/shell/org/jnode/shell/command/SyntaxCommand.java 2008-04-11 11:38:22 UTC (rev 3949) @@ -57,8 +57,6 @@ new AliasArgument("alias", Argument.OPTIONAL, "the target alias"); private FileArgument ARG_FILE = new FileArgument("file", Argument.OPTIONAL, "if set, load the syntax from this file"); - private FlagArgument ARG_LIST = - new FlagArgument("list", Argument.OPTIONAL, "if set, list the syntaxes"); private FlagArgument ARG_REMOVE = new FlagArgument("remove", Argument.OPTIONAL, "if set, remove the syntaxes for the target alias"); private FlagArgument ARG_DUMP = @@ -67,8 +65,8 @@ new FlagArgument("dumpAll", Argument.OPTIONAL, "if set, show the syntaxes for all aliases"); public SyntaxCommand() { - super("load or clear a syntax for an alias"); - registerArguments(ARG_ALIAS, ARG_FILE, ARG_LIST, ARG_REMOVE, ARG_DUMP, ARG_DUMP_ALL); + super("manages syntaxes for commands using the 'new' syntax mechanisms"); + registerArguments(ARG_ALIAS, ARG_FILE, ARG_REMOVE, ARG_DUMP, ARG_DUMP_ALL); } public static void main(String[] args) throws Exception { @@ -79,12 +77,7 @@ throws Exception { SyntaxManager synMgr = ShellUtils.getCurrentSyntaxManager(); - if (ARG_LIST.isSet()) { - for (String key : synMgr.getKeys()) { - out.println(key); - } - } - else if (ARG_DUMP_ALL.isSet()) { + if (ARG_DUMP_ALL.isSet()) { for (String alias : synMgr.getKeys()) { Syntax syntax = synMgr.getSyntax(alias); dumpSyntax(alias, syntax, out); @@ -127,6 +120,11 @@ else if (ARG_REMOVE.isSet()) { synMgr.remove(alias); } + else { + for (String key : synMgr.getKeys()) { + out.println(key); + } + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-04-13 04:58:34
|
Revision: 3952 http://jnode.svn.sourceforge.net/jnode/?rev=3952&view=rev Author: crawley Date: 2008-04-12 21:58:31 -0700 (Sat, 12 Apr 2008) Log Message: ----------- Added "clear" command by Jacob Kosod. Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.driver.console.xml Added Paths: ----------- 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-04-13 03:27:40 UTC (rev 3951) +++ trunk/shell/descriptors/org.jnode.shell.command.driver.console.xml 2008-04-13 04:58:31 UTC (rev 3952) @@ -20,6 +20,7 @@ <extension point="org.jnode.shell.aliases"> <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.security.permissions"> Added: trunk/shell/src/shell/org/jnode/shell/command/driver/console/ClearConsoleCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/driver/console/ClearConsoleCommand.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/command/driver/console/ClearConsoleCommand.java 2008-04-13 04:58:31 UTC (rev 3952) @@ -0,0 +1,54 @@ +/* + * $Id: ConsoleCommand.java 3580 2007-11-03 20:31:24Z lsantha $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.shell.command.driver.console; + +import javax.naming.NameNotFoundException; +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; + +/** + * @author Jacob Kofod + */ +public class ClearConsoleCommand { + + public static Help.Info HELP_INFO = + new Help.Info("clear", new Syntax[] { new Syntax("Clear console screen", new Parameter[] {}), } + ); + + /** + * 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(); + 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-04-14 13:47:56
|
Revision: 3955 http://jnode.svn.sourceforge.net/jnode/?rev=3955&view=rev Author: crawley Date: 2008-04-14 06:47:55 -0700 (Mon, 14 Apr 2008) Log Message: ----------- Converted 'echo' command to new syntax Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/EchoCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-14 13:47:05 UTC (rev 3954) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-14 13:47:55 UTC (rev 3955) @@ -88,6 +88,11 @@ </repeat> </sequence> </syntax> + <syntax alias="echo"> + <repeat> + <argument argLabel="text"/> + </repeat> + </syntax> <syntax alias="set"> <sequence description="set a system property"> <argument argLabel="key"/> Modified: trunk/shell/src/shell/org/jnode/shell/command/EchoCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/EchoCommand.java 2008-04-14 13:47:05 UTC (rev 3954) +++ trunk/shell/src/shell/org/jnode/shell/command/EchoCommand.java 2008-04-14 13:47:55 UTC (rev 3955) @@ -23,47 +23,45 @@ import java.io.InputStream; import java.io.PrintStream; -import java.util.Iterator; import org.jnode.shell.AbstractCommand; import org.jnode.shell.CommandLine; -import org.jnode.shell.help.Argument; -import org.jnode.shell.help.Help; -import org.jnode.shell.help.Parameter; -import org.jnode.shell.help.argument.StringArgument; +import org.jnode.shell.syntax.Argument; +import org.jnode.shell.syntax.StringArgument; /** + * Echo the command's arguments to its output. + * * @author epr + * @author cr...@jn... */ - public class EchoCommand extends AbstractCommand { - - public static Help.Info HELP_INFO = new Help.Info( - "echo", "Print the given text", - new Parameter[]{ - new Parameter(new StringArgument("arg", "the text to print", Argument.MULTI), Parameter.OPTIONAL) - } - ); - + + private final StringArgument ARG_WORDS = + new StringArgument("text", Argument.MULTIPLE, "the text to be printed"); + + public EchoCommand() { + super("Print the argument text to standard output"); + registerArguments(ARG_WORDS); + } + public static void main(String[] args) throws Exception { new EchoCommand().execute(args); } /** - * Execute this command + * Execute the command */ @SuppressWarnings("deprecation") - public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) + public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception { - Iterator<String> it = commandLine.iterator(); - int i = 0; - while (it.hasNext()) { - if (i > 0) { - out.print(' '); - } - out.print(it.next()); - i++; - } - out.println(); + String[] words = ARG_WORDS.getValues(); + for (int i = 0; i < words.length; i++) { + if (i > 0) { + out.print(' '); + } + out.print(words[i]); + } + out.println(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-04-18 14:22:51
|
Revision: 3973 http://jnode.svn.sourceforge.net/jnode/?rev=3973&view=rev Author: crawley Date: 2008-04-18 07:22:46 -0700 (Fri, 18 Apr 2008) Log Message: ----------- Converted ExecCommand to new syntax Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/ExecCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-18 14:22:03 UTC (rev 3972) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-18 14:22:46 UTC (rev 3973) @@ -94,6 +94,14 @@ </repeat> </syntax> <syntax alias="env" description="Print the system properties"/> + <syntax alias="exec" description="Execute a class in a new Process"> + <sequence> + <argument argLabel="className"/> + <repeat> + <argument argLabel="arg"/> + </repeat> + </sequence> + </syntax> <syntax alias="set"> <sequence description="Set a system property"> <argument argLabel="key"/> Modified: trunk/shell/src/shell/org/jnode/shell/command/ExecCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/ExecCommand.java 2008-04-18 14:22:03 UTC (rev 3972) +++ trunk/shell/src/shell/org/jnode/shell/command/ExecCommand.java 2008-04-18 14:22:46 UTC (rev 3973) @@ -26,41 +26,43 @@ import org.jnode.shell.AbstractCommand; import org.jnode.shell.CommandLine; -import org.jnode.shell.help.Argument; -import org.jnode.shell.help.Help; -import org.jnode.shell.help.Parameter; -import org.jnode.shell.help.argument.ClassNameArgument; +import org.jnode.shell.syntax.Argument; +import org.jnode.shell.syntax.ClassNameArgument; +import org.jnode.shell.syntax.StringArgument; /** * @author epr + * @author cr...@jn... */ public class ExecCommand extends AbstractCommand { + + private final ClassNameArgument ARG_CLASSNAME = + new ClassNameArgument("className", Argument.MANDATORY, + "The fully qualified name of the class to be 'exec'd"); + private final StringArgument ARG_ARG = + new StringArgument("arg", Argument.OPTIONAL | Argument.MULTIPLE, + "Arguments to be passed to the class"); - public static Help.Info HELP_INFO = new Help.Info( - "exec", - "Execute the given class in a new process", - new Parameter[]{ - new Parameter(new ClassNameArgument("classname", "the class to execute"), Parameter.MANDATORY), - new Parameter(new Argument("arg", "the argument(s) to pass to the class", Argument.MULTI), Parameter.OPTIONAL) - } - ); + public ExecCommand() { + super("Execute the given class in a new process"); + registerArguments(ARG_CLASSNAME, ARG_ARG); + } - public static void main(String[] args) - throws Exception { + public static void main(String[] args) throws Exception { new ExecCommand().execute(args); } /** * Execute this command */ - public void execute( - CommandLine cmdLine, - InputStream in, - PrintStream out, - PrintStream err) + public void execute(CommandLine cmdLine, InputStream in, PrintStream out, PrintStream err) throws Exception { - - Runtime.getRuntime().exec(cmdLine.getArguments()); + String className = ARG_CLASSNAME.getValue(); + String[] args = ARG_ARG.getValues(); + String[] execArgs = new String[args.length + 1]; + execArgs[0] = className; + System.arraycopy(args, 0, execArgs, 1, args.length); + Runtime.getRuntime().exec(execArgs); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-04-19 02:42:52
|
Revision: 3974 http://jnode.svn.sourceforge.net/jnode/?rev=3974&view=rev Author: crawley Date: 2008-04-18 19:42:49 -0700 (Fri, 18 Apr 2008) Log Message: ----------- Converted ExitCommand Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/ExitCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-18 14:22:46 UTC (rev 3973) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-19 02:42:49 UTC (rev 3974) @@ -102,6 +102,7 @@ </repeat> </sequence> </syntax> + <syntax alias="exit" description="Exit the current shell"/> <syntax alias="set"> <sequence description="Set a system property"> <argument argLabel="key"/> Modified: trunk/shell/src/shell/org/jnode/shell/command/ExitCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/ExitCommand.java 2008-04-18 14:22:46 UTC (rev 3973) +++ trunk/shell/src/shell/org/jnode/shell/command/ExitCommand.java 2008-04-19 02:42:49 UTC (rev 3974) @@ -8,20 +8,17 @@ import org.jnode.shell.CommandLine; import org.jnode.shell.CommandShell; import org.jnode.shell.ShellManager; -import org.jnode.shell.help.Help; /** * @author Levente S\u00e1ntha */ public class ExitCommand extends AbstractCommand { - public static Help.Info HELP_INFO = new Help.Info( - "exit", - "Exit the shell" - ); + public ExitCommand() { + super("Exit the current shell"); + } - public static void main(String[] args) - throws Exception { + public static void main(String[] args) throws Exception { new ExitCommand().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-19 02:54:32
|
Revision: 3975 http://jnode.svn.sourceforge.net/jnode/?rev=3975&view=rev Author: crawley Date: 2008-04-18 19:54:26 -0700 (Fri, 18 Apr 2008) Log Message: ----------- Converted 'GcCommand' Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/GcCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-19 02:42:49 UTC (rev 3974) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-19 02:54:26 UTC (rev 3975) @@ -103,6 +103,7 @@ </sequence> </syntax> <syntax alias="exit" description="Exit the current shell"/> + <syntax alias="gc" description="Run the garbage collector"/> <syntax alias="set"> <sequence description="Set a system property"> <argument argLabel="key"/> Modified: trunk/shell/src/shell/org/jnode/shell/command/GcCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/GcCommand.java 2008-04-19 02:42:49 UTC (rev 3974) +++ trunk/shell/src/shell/org/jnode/shell/command/GcCommand.java 2008-04-19 02:54:26 UTC (rev 3975) @@ -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; import org.jnode.vm.Vm; import org.jnode.vm.memmgr.GCStatistics; @@ -36,32 +35,25 @@ */ public class GcCommand extends AbstractCommand { - public static Help.Info HELP_INFO = new Help.Info( - "gc", - "Start the garbage collector" - ); + public GcCommand() { + super("Run the garbage collector"); + } - public static void main(String[] args) - throws Exception { + public static void main(String[] args) throws Exception { new GcCommand().execute(args); } /** * Execute this command */ - public void execute( - CommandLine cmdLine, - InputStream in, - PrintStream out, - PrintStream err) + public void execute(CommandLine cmdLine, InputStream in, PrintStream out, PrintStream err) throws Exception { final Runtime rt = Runtime.getRuntime(); out.println("Memory size: " + NumberUtils.toBinaryByte(rt.totalMemory())); out.println("Free memory: " + NumberUtils.toBinaryByte(rt.freeMemory())); - - out.println("Starting gc..."); + out.println("Starting gc..."); long start = System.currentTimeMillis(); rt.gc(); GCStatistics stats = Vm.getHeapManager().getStatistics(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-04-21 11:02:03
|
Revision: 3991 http://jnode.svn.sourceforge.net/jnode/?rev=3991&view=rev Author: crawley Date: 2008-04-21 04:01:59 -0700 (Mon, 21 Apr 2008) Log Message: ----------- Converted GrepCommand Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/GrepCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-20 22:25:15 UTC (rev 3990) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-21 11:01:59 UTC (rev 3991) @@ -115,6 +115,15 @@ </sequence> <option argLabel="show" longName="show" description="Show heap debug flags"/> </syntax> + <syntax alias="grep"> + <sequence description="Search for lines that match a string or regex"> + <optionSet> + <option argLabel="inverse" shortName="i"/> + <option argLabel="isRegex" shortName="r"/> + </optionSet> + <argument argLabel="expression"/> + </sequence> + </syntax> <syntax alias="set"> <sequence description="Set a system property"> <argument argLabel="key"/> Modified: trunk/shell/src/shell/org/jnode/shell/command/GrepCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/GrepCommand.java 2008-04-20 22:25:15 UTC (rev 3990) +++ trunk/shell/src/shell/org/jnode/shell/command/GrepCommand.java 2008-04-21 11:01:59 UTC (rev 3991) @@ -1,3 +1,23 @@ +/* + * $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.command; import java.io.BufferedReader; @@ -4,156 +24,87 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; 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.Syntax; -import org.jnode.shell.help.argument.OptionArgument; +import org.jnode.shell.syntax.*; /** - * * @author peda + * @author cr...@jn... */ public class GrepCommand extends AbstractCommand { - public static final int MODE_CONTAINS = 0; - public static final int MODE_REGEXP = 1; + private final FlagArgument FLAG_INVERSE = + new FlagArgument("inverse", Argument.OPTIONAL, "Output non-matching lines"); + private final FlagArgument FLAG_REGEX = + new FlagArgument("isRegex", Argument.OPTIONAL, "Do regex search rather than simple string search"); + private final StringArgument ARG_EXPR = + new StringArgument("expression", Argument.MANDATORY, "The expression to be searched for"); - - static final OptionArgument ARG_ACTION = - new OptionArgument("options", "options that can be passed to grep", - new OptionArgument.Option("-v", "Only output non matching lines"), - new OptionArgument.Option("-r", "Use java regexp syntax instead of include syntax")); - - static final Parameter PARAM_ACTION = new Parameter(ARG_ACTION); - static final Parameter PARAM_EXPRESSION = new Parameter("expression", "the expression that should be greped for", false); - - public static Help.Info HELP_INFO = new Help.Info("grep", - new Syntax[] { new Syntax("grep for regular expressions", PARAM_ACTION, PARAM_EXPRESSION) }); + public GrepCommand() { + super("Search for lines that match a string or regex"); + registerArguments(ARG_EXPR, FLAG_INVERSE, FLAG_REGEX); + } /** - * main method, normaly not used, use execute instead!! + * main method, normally not used, use execute instead!! * @param args * @throws Exception */ - public static void main(String[] args) - throws Exception { - new GrepCommand().execute(args); - } + public static void main(String[] args) throws Exception { + new GrepCommand().execute(args); + } /** - * main entry point - * called from Shell + * Primary entry point */ public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception { - Options options = new Options(); - options.err = err; - options.args = commandLine.getArguments(); - - out.println("Start grep..."); - // parse commandline arguments... - final boolean parseOK = parseCommandLine(options); - if (!parseOK) { - displayHelp(out); - exit(2); - } + boolean inverse = FLAG_INVERSE.isSet(); + boolean useRegex = FLAG_REGEX.isSet(); + String expr = ARG_EXPR.getValue(); + + Pattern pattern = null; + try { + if (useRegex) { + pattern = Pattern.compile(expr); + } + else { + // By using Pattern to search for regular strings, we should + // get the benefit of Pattern's ability to do fast string + // searching; e.g. using the Boyer-Moore algorithm. + pattern = Pattern.compile(Pattern.quote(expr)); + } + } + catch (PatternSyntaxException ex) { + err.println("Invalid regex: " + ex.getMessage()); + exit(2); + } final BufferedReader r = new BufferedReader(new InputStreamReader(in)); - String line; - - // loop over inputstream and grep for expression... - boolean found = false; - while ((line = r.readLine()) != null) { - if (options.mode == MODE_CONTAINS) { - if (line.contains(options.expression)) { - if (!options.inverse) { - out.println(line); - found = true; - } - } else if (options.inverse) { - out.println(line); - found = true; - } - - } else { - if (line.matches(options.expression)) { - if (!options.inverse) { - out.println(line); - found = true; - } - } else if (options.inverse) { - out.println(line); - found = true; - } - } - } - if (!found) { - exit(1); - } - } - - private boolean parseCommandLine(Options options) { - for (int i = 0; i < options.args.length; i++) { - if (options.args[i].startsWith("-")) { - setOptions(options.args[i], options); - options.args[i] = null; - } + // Read the input a line at a time, searching each line for the expression. + boolean found = false; + String line; + while ((line = r.readLine()) != null) { + if (pattern.matcher(line).find()) { + if (!inverse) { + out.println(line); + found = true; + } + } + else if (inverse) { + out.println(line); + found = true; + } } - - for (int i = 0; i < options.args.length; i++) { - if (options.args[i] != null) { - options.expression = options.args[i]; - return true; - } + if (!found) { + exit(1); } - - return false; } - - private void setOptions(String opts, Options options) { - if (opts.startsWith("--")) { - // none yet - options.err.println("unknown longopt '" + opts + "'"); - } else { - for (int i = 1; i < opts.length(); i++) { - switch (opts.charAt(i)) { - case 'r': - options.mode = MODE_REGEXP; - break; - case 'v': - options.inverse = true; - break; - default: - options.err.println("unknown opt '" + opts.charAt(i) + "'"); - break; - } - } - } - } - - private void displayHelp(PrintStream out) { - out.println("JNode grep <options> expression"); - out.println("options:"); - out.println(" -v inverse search, only print non matching lines"); - out.println(" -r java regexp mode instead of contains mode"); - out.println(); - } - - private class Options { - - private int mode = 0; - - private boolean inverse = false; - - private String expression; - - private PrintStream err; - - private String[] args; - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-04-21 11:59:04
|
Revision: 3993 http://jnode.svn.sourceforge.net/jnode/?rev=3993&view=rev Author: crawley Date: 2008-04-21 04:58:54 -0700 (Mon, 21 Apr 2008) Log Message: ----------- Converted HelpCommand Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/HelpCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-21 11:57:47 UTC (rev 3992) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-21 11:58:54 UTC (rev 3993) @@ -124,6 +124,10 @@ <argument argLabel="expression"/> </sequence> </syntax> + <syntax alias="help"> + <empty description="Print help about 'help'"/> + <argument argLabel="alias" description="Print help about a command alias or class"/> + </syntax> <syntax alias="set"> <sequence description="Set a system property"> <argument argLabel="key"/> Modified: trunk/shell/src/shell/org/jnode/shell/command/HelpCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/HelpCommand.java 2008-04-21 11:57:47 UTC (rev 3992) +++ trunk/shell/src/shell/org/jnode/shell/command/HelpCommand.java 2008-04-21 11:58:54 UTC (rev 3993) @@ -21,18 +21,20 @@ package org.jnode.shell.command; +import java.io.InputStream; +import java.io.PrintStream; + import javax.naming.NameNotFoundException; import org.jnode.shell.AbstractCommand; +import org.jnode.shell.CommandLine; import org.jnode.shell.Shell; import org.jnode.shell.ShellUtils; import org.jnode.shell.alias.AliasManager; import org.jnode.shell.alias.NoSuchAliasException; import org.jnode.shell.help.Help; -import org.jnode.shell.help.HelpException; -import org.jnode.shell.help.Parameter; -import org.jnode.shell.help.ParsedArguments; -import org.jnode.shell.help.argument.AliasArgument; +import org.jnode.shell.syntax.AliasArgument; +import org.jnode.shell.syntax.Argument; import org.jnode.shell.syntax.ArgumentBundle; import org.jnode.shell.syntax.SyntaxBundle; import org.jnode.shell.syntax.SyntaxManager; @@ -42,88 +44,100 @@ * @author Fabien DUMINY (fd...@jn...) * @author cr...@jn... */ -public class HelpCommand { +public class HelpCommand extends AbstractCommand { - static final AliasArgument ARG_COMMAND = new AliasArgument("command", Help.getLocalizedHelp("help.arg.command")); - static final Parameter PARAM_COMMAND = new Parameter(ARG_COMMAND, Parameter.OPTIONAL); + private final AliasArgument ARG_ALIAS = + new AliasArgument("alias", Argument.OPTIONAL, "The command alias name"); - public static Help.Info HELP_INFO = - new Help.Info( - "help", - Help.getLocalizedHelp("help.desc"), - new Parameter[] { PARAM_COMMAND }); + public HelpCommand() { + super("Print online help for a command alias"); + registerArguments(ARG_ALIAS); + } - public static void main(String[] args) - throws HelpException { - Help.Info info = null; - SyntaxBundle syntaxes = null; + public static void main(String[] args) throws Exception { + new HelpCommand().execute(args); + } + + @Override + public void execute(CommandLine commandLine, InputStream in, + PrintStream out, PrintStream err) throws Exception { + + String alias; + if (ARG_ALIAS.isSet()) { + alias = ARG_ALIAS.getValue(); + } + else if (commandLine.getCommandName() != null) { + alias = commandLine.getCommandName(); + } + else { + alias = "help"; + } + + Help.Info info = null; + SyntaxBundle syntaxes = null; ArgumentBundle bundle = null; - String otherAliases = null; - - ParsedArguments cmdLine = HELP_INFO.parse(args); - String cmd = null; - String arg = null; - if (PARAM_COMMAND.isSet(cmdLine)){ - try { - final Shell shell = ShellUtils.getShellManager().getCurrentShell(); - final AliasManager aliasManager = shell.getAliasManager(); - final SyntaxManager syntaxManager = shell.getSyntaxManager(); + String otherAliases = null; + try { + final Shell shell = ShellUtils.getShellManager().getCurrentShell(); + final AliasManager aliasManager = shell.getAliasManager(); + final SyntaxManager syntaxManager = shell.getSyntaxManager(); + Class<?> clazz = getCommandClass(aliasManager, alias); - arg = ARG_COMMAND.getValue(cmdLine); - Class<?> clazz = getCommandClass(aliasManager, arg); - - bundle = getBundle(clazz); - if (bundle != null) { - syntaxes = syntaxManager.getSyntaxBundle(arg); - if (syntaxes == null) { - syntaxes = new SyntaxBundle(arg, bundle.createDefaultSyntax()); - } + bundle = getBundle(clazz, err); + if (bundle != null) { + syntaxes = syntaxManager.getSyntaxBundle(alias); + if (syntaxes == null) { + syntaxes = new SyntaxBundle(alias, bundle.createDefaultSyntax()); } - else { - info = Help.getInfo(clazz); - } - if (info != null || syntaxes != null) { - cmd = arg; - otherAliases = getOtherAliases(aliasManager, cmd, clazz); - } - } catch (ClassNotFoundException ex) { - System.err.println("Command not found: " + arg); - } catch (SecurityException ex) { - System.err.println("Access to class prevented by security manager"); - } catch (NameNotFoundException e) { - System.err.println("Can't find the shell manager"); - } + } + else { + info = Help.getInfo(clazz); + } + if (info != null || syntaxes != null) { + otherAliases = getOtherAliases(aliasManager, alias, clazz); + } + } catch (ClassNotFoundException ex) { + err.println("Alias not found: " + alias); + exit(1); + } catch (SecurityException ex) { + err.println("Access to class prevented by security manager"); + exit(2); + } catch (NameNotFoundException e) { + err.println("Can't find the shell manager"); + exit(2); } - else { - info = HELP_INFO; // defaults to print own help - } if (syntaxes != null) { - Help.getHelp().help(syntaxes, bundle, System.out); + Help.getHelp().help(syntaxes, bundle, out); } else if (info != null) { - Help.getHelp().help(info, cmd, System.out); + Help.getHelp().help(info, alias, out); } + else { + out.println("No help information available: " + alias); + } if (otherAliases != null) { - System.out.println(otherAliases); + out.println(otherAliases); } } - private static ArgumentBundle getBundle(Class<?> clazz) { + private ArgumentBundle getBundle(Class<?> clazz, PrintStream err) { try { AbstractCommand command = (AbstractCommand) clazz.newInstance(); return command.getArgumentBundle(); } catch (ClassCastException e) { - return null; + // The target class cannot } catch (InstantiationException e) { - System.err.println("Problem during instantiation of " + clazz.getName()); + err.println("Problem during instantiation of " + clazz.getName()); + exit(2); } catch (IllegalAccessException e) { - System.err.println("Constructor for " + clazz.getName() + " is not accessible"); + err.println("Constructor for " + clazz.getName() + " is not accessible"); + exit(2); } return null; } - private static Class<?> getCommandClass(AliasManager aliasManager, String commandName) + private Class<?> getCommandClass(AliasManager aliasManager, String commandName) throws ClassNotFoundException { try { @@ -135,7 +149,7 @@ } } - private static String getOtherAliases(AliasManager aliasManager, String alias, Class<?> aliasClass) + private String getOtherAliases(AliasManager aliasManager, String alias, Class<?> aliasClass) { boolean hasOtherAlias = false; StringBuilder sb = new StringBuilder("Other aliases: "); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-04-22 10:59:33
|
Revision: 3998 http://jnode.svn.sourceforge.net/jnode/?rev=3998&view=rev Author: crawley Date: 2008-04-22 03:59:29 -0700 (Tue, 22 Apr 2008) Log Message: ----------- Converted HistoryCommand Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/HistoryCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-22 10:43:56 UTC (rev 3997) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-22 10:59:29 UTC (rev 3998) @@ -128,6 +128,16 @@ <empty description="Print help about 'help'"/> <argument argLabel="alias" description="Print help about a command alias or class"/> </syntax> + <syntax alias="history"> + <empty description="List history entries"/> + <sequence description="Run a history command"> + <alternatives><empty/><option argLabel="test" shortName="t" longName="test"/></alternatives> + <alternatives> + <argument argLabel="index"/> + <argument argLabel="prefix"/> + </alternatives> + </sequence> + </syntax> <syntax alias="set"> <sequence description="Set a system property"> <argument argLabel="key"/> Modified: trunk/shell/src/shell/org/jnode/shell/command/HistoryCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/HistoryCommand.java 2008-04-22 10:43:56 UTC (rev 3997) +++ trunk/shell/src/shell/org/jnode/shell/command/HistoryCommand.java 2008-04-22 10:59:29 UTC (rev 3998) @@ -20,198 +20,101 @@ */ package org.jnode.shell.command; +import java.io.InputStream; import java.io.PrintStream; -import javax.naming.NameNotFoundException; - import org.jnode.driver.console.InputHistory; +import org.jnode.shell.AbstractCommand; +import org.jnode.shell.CommandLine; import org.jnode.shell.Shell; import org.jnode.shell.ShellUtils; -import org.jnode.shell.help.Help; -import org.jnode.shell.help.Parameter; -import org.jnode.shell.help.Syntax; -import org.jnode.shell.help.argument.OptionArgument; +import org.jnode.shell.syntax.*; -/** A shell command to access the data in the CommandHistory class. - * @author Matt Paine +/** + * List or execute a command from the shell's command history. + * + * @author Matt Paine + * @author cr...@jn... */ -public class HistoryCommand { +public class HistoryCommand extends AbstractCommand { -//********** HELP_INFO **********// + private final IntegerArgument ARG_INDEX = + new IntegerArgument("index", Argument.OPTIONAL, 0, Integer.MAX_VALUE, "A history list index"); + private final StringArgument ARG_PREFIX = + new StringArgument("prefix", Argument.OPTIONAL, "A history list prefix (>= 0)"); + private final FlagArgument FLAG_TEST = + new FlagArgument("test", Argument.OPTIONAL, "If set, don't try to execute the history command"); - - public static final OptionArgument ARG_HISTORYARG = new OptionArgument("history arg", "The argument for the history", - new OptionArgument.Option[] - { - new OptionArgument.Option("string", "The command to search for"), - new OptionArgument.Option("int", "The index of the command to execute") - }); - - - public static final Help.Info HELP_INFO = new Help.Info("history", - new Syntax[] - { - // history - new Syntax("List the current archive of commands", new Parameter[] - { - new Parameter("h", "Displays the usage message", Parameter.OPTIONAL) - }), - new Syntax("Executes a historical command", new Parameter[] - { - new Parameter("t", "Test the history argument (does not execute)", Parameter.OPTIONAL), - new Parameter(ARG_HISTORYARG, Parameter.MANDATORY) - }) - }); - - -//********** Private Variables **********// - - /** Reference to the current shell. **/ private Shell shell; - - /** Sends all output to this PrintStream. **/ - private PrintStream out; - - /** Reference to the CommandHistory to work with. **/ + private PrintStream out; + private PrintStream err; private InputHistory history; -//********** Constructor **********// - - /** Sets up any instance variables and processes the command arguments. - * @param args The arguments to work with. - **/ - public HistoryCommand (String[] args) - throws NameNotFoundException { - shell = ShellUtils.getShellManager().getCurrentShell(); + public HistoryCommand() { + super("Command history list or execute"); + registerArguments(ARG_INDEX, ARG_PREFIX, FLAG_TEST); + } + + @Override + public void execute(CommandLine commandLine, InputStream in, + PrintStream out, PrintStream err) throws Exception + { + shell = ShellUtils.getShellManager().getCurrentShell(); history = shell.getCommandHistory(); - out = System.out; + this.out = out; + this.err = err; + + int index = ARG_INDEX.isSet() ? ARG_INDEX.getValue() : -1; + String prefix = ARG_PREFIX.isSet() ? ARG_PREFIX.getValue() : null; + boolean test = FLAG_TEST.isSet(); - // no arguments prints all history - if (args.length == 0) + if (index == -1 && prefix == null && !test) { listCommands(); - - // -h displays usage - else if ("-h".equals(args[0])) - printUsage(); - - // -t tests the next argument for a match - else if ("-t".equals(args[0])) { - if (args.length != 2) - printUsage(); - else - printTest(args[1]); } - - // If there are more than 1 argument then display the useage - else if (args.length != 1) - printUsage(); - - // Try executing the historical command based on the argument - else - executeHistoryCommand(args[0]); + else { + runCommand(index, prefix, test); + } } - -//********** Public Methods **********// - - /** List out every command from the history, with each commands index. **/ + /** + * List every command in the history with its history index. + */ public void listCommands() { - for (int x = 0; x < history.size(); x++) - out.println("" + x + ": " + history.getLineAt(x)); - out.println(); + for (int i = 0; i < history.size(); i++) { + out.println("" + i + ": " + history.getLineAt(i)); + } } - /** Tests the given argument to see if it is found in the history. - * The found command is displayed. - * @param arg The argument to test for. - **/ - public void printTest(String arg) { - String line = parseCommandArg(arg); - if (line == null) - out.println("No command found!"); - else + /** + * Select and run (or print) a command from the history. + * + * @param index a history index or <code>-1</code> + * @param prefix a command prefix or <code>null</code> + * @param test if <code>true</code> this is just a test ... don't execute the command. + */ + public void runCommand(int index, String prefix, boolean test) { + String line = (index >= 0) ? history.getLineAt(index) : history.getLineWithPrefix(prefix); + + if (line == null) { + if (index >= 0) { + err.println("History command #" + index + " not found"); + } + else { + err.println("History command starting with '" + prefix + "' not found"); + } + exit(1); + } + else if (test) { out.println(line); - out.println(); - } - - /** Executes the command based on the given argument. - * TODO: This method needs implementing. - * @param arg The argument to parse and execute. - **/ - public void executeHistoryCommand (String arg) { - //TODO - out.println("Not Implemented Yet (try -t switch to test the command)"); - } - - - /** Write the usage information of this command into the given stream. **/ - public void printUsage() { - out.println("Usage:"); - out.println("\thistory : List all the current archived commands, showing the index"); - out.println("\t number of each command."); - out.println(); - out.println("\thistory -h : Displays this usage message."); - out.println(); - out.println("\thistory 4 : If an index number is used, that number is used to execute the"); - out.println("\t historical command with that index."); - out.println(); - out.println("\thistory di : If a string is used, the last command used that starts with"); - out.println("\t that string is executed.E.g. This command may execute the last"); - out.println("\t \"dir\" command if no other command starting with \"di\" has been"); - out.println("\t executed since the last dir."); - out.println(); - out.println("\thistory -t [index | string]</b> "); - out.println("\t : Instead of executing the archived command"); - out.println("\t (at the given index, or starting with the search string), test"); - out.println("\t the command by printing the command line to the output."); - out.println(); - } - - -//********** Private Methods **********// - - /** Parses the argument to get the historical command. - * This method works out if the argument is an index number or a search - * string and returns the command based on that deduction. - * @param arg The argument to parse. - * @return The CommandLine object returned from the CommandHistory based - * on the parsed argument. - **/ - private String parseCommandArg(String arg) { - try { - int i = Integer.parseInt(arg); - return history.getLineAt(i); } - catch (NumberFormatException nfex) { - return history.getLineWithPrefix(arg); + else { + err.println("History command running is not implemented yet: try '-t' to test"); + exit(2); } } - -//********** Main **********// - - /** Main method. This method creates the HistoryCommand based on the arguments. - * <p>Usage:</p> - * <ul><li><b>history</b> : List all the current archived commands, - * showing the index number of each command.</li> - * <li><b>history -h</b> : Displays a short help message.</li> - * <li><b>history 4</b> : If an index number is used, that number is - * used to execute the historical command with that index.</li> - * <li><b>history di</b> : If a string is used, the last command used - * that starts with that string is executed. E.g. This command - * may execute the last "dir" command if no other command - * starting with "di" has been executed since the last dir.</li> - * <li><b>history -t [index | string]</b> : Instead of executing the - * archived command (at the given index, or starting with the - * search string), test the command by printing the command line - * to the output. - * </ul> - * @param args The arguments for this command as outlined in the description. - **/ - public static void main(String[] args) - throws NameNotFoundException { - new HistoryCommand(args); + public static void main(String[] args) throws Exception { + new HistoryCommand().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-22 13:51:02
|
Revision: 4002 http://jnode.svn.sourceforge.net/jnode/?rev=4002&view=rev Author: crawley Date: 2008-04-22 06:50:36 -0700 (Tue, 22 Apr 2008) Log Message: ----------- Convert RunCommand Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/RunCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-22 13:50:00 UTC (rev 4001) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-22 13:50:36 UTC (rev 4002) @@ -138,6 +138,9 @@ </alternatives> </sequence> </syntax> + <syntax alias="run" description="Run a command file"> + <argument argLabel="file"/> + </syntax> <syntax alias="set"> <sequence description="Set a system property"> <argument argLabel="key"/> Modified: trunk/shell/src/shell/org/jnode/shell/command/RunCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/RunCommand.java 2008-04-22 13:50:00 UTC (rev 4001) +++ trunk/shell/src/shell/org/jnode/shell/command/RunCommand.java 2008-04-22 13:50:36 UTC (rev 4002) @@ -1,3 +1,23 @@ +/* + * $Id: JavaCommand.java 3913 2008-03-30 02:36:44Z 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; import java.io.File; @@ -8,55 +28,50 @@ import org.jnode.shell.AbstractCommand; import org.jnode.shell.CommandLine; -import org.jnode.shell.CommandShell; import org.jnode.shell.Shell; import org.jnode.shell.ShellUtils; -import org.jnode.shell.help.Help; -import org.jnode.shell.help.Parameter; -import org.jnode.shell.help.ParsedArguments; -import org.jnode.shell.help.argument.FileArgument; +import org.jnode.shell.syntax.Argument; +import org.jnode.shell.syntax.FileArgument; /** * Load and execute a command file. * * @author Levente S\u00e1ntha + * @author cr...@jn... */ public class RunCommand extends AbstractCommand { + + private final FileArgument ARG_FILE = new FileArgument("file", Argument.MANDATORY, "The command file name"); + + public RunCommand() { + super("Run a command file"); + registerArguments(ARG_FILE); + } - static final FileArgument ARG_FILE = new FileArgument("file", - "a command file", false); - - public static Help.Info HELP_INFO = new Help.Info("run", - "execute a command file", new Parameter[] { new Parameter( - RunCommand.ARG_FILE, Parameter.MANDATORY) }); - public static void main(String[] args) throws Exception { new RunCommand().execute(args); } public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception { - ParsedArguments cmdLine = RunCommand.HELP_INFO.parse(commandLine); - final File file = RunCommand.ARG_FILE.getFile(cmdLine); + final File file = ARG_FILE.getValue(); Shell shell = null; try { shell = ShellUtils.getShellManager().getCurrentShell(); - } catch( NameNotFoundException e ) { + } catch (NameNotFoundException e) { e.printStackTrace(); exit(2); } - if( shell == null ) { - System.err.println( "Shell is null." ); + if (shell == null) { + System.err.println("Shell is null."); exit(2); } - if(!(shell instanceof CommandShell)) { - System.err.println("Shell wasn't a CommandShell: " + shell.getClass()); - exit(2); + int rc = shell.runCommandFile(file); + if (rc != 0) { + exit(rc); } - - ((CommandShell)shell).executeFile(file); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-04-23 13:37:22
|
Revision: 4005 http://jnode.svn.sourceforge.net/jnode/?rev=4005&view=rev Author: crawley Date: 2008-04-23 06:37:21 -0700 (Wed, 23 Apr 2008) Log Message: ----------- Converted JavaCommand and tidied up the error detection and reporting. Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/JavaCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-23 11:42:09 UTC (rev 4004) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-23 13:37:21 UTC (rev 4005) @@ -138,6 +138,12 @@ </alternatives> </sequence> </syntax> + <syntax alias="java" description="Run a Java class via its 'main' method"> + <sequence> + <argument argLabel="className"/> + <repeat><argument argLabel="arg"/></repeat> + </sequence> + </syntax> <syntax alias="run" description="Run a command file"> <argument argLabel="file"/> </syntax> Modified: trunk/shell/src/shell/org/jnode/shell/command/JavaCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/JavaCommand.java 2008-04-23 11:42:09 UTC (rev 4004) +++ trunk/shell/src/shell/org/jnode/shell/command/JavaCommand.java 2008-04-23 13:37:21 UTC (rev 4005) @@ -23,72 +23,102 @@ import java.io.File; import java.io.FileInputStream; +import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.net.MalformedURLException; import java.net.URL; import org.jnode.shell.AbstractCommand; import org.jnode.shell.CommandLine; -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.ClassNameArgument; +import org.jnode.shell.syntax.Argument; +import org.jnode.shell.syntax.ClassNameArgument; +import org.jnode.shell.syntax.StringArgument; +import java.lang.reflect.Modifier; + /** + * This command runs a Java class by calling its 'public static void + * main(String[])' method. The class is located by searching the the shell + * classpath, searching the plugins, and finally looking in the current + * directory. + * * @author epr + * @author cr...@jn... */ public class JavaCommand extends AbstractCommand { - static final ClassNameArgument ARG_CLASS = new ClassNameArgument("classname", "the class to excute"); - static final Argument ARG_ARGS = new Argument("arg", "the argument(s) to pass to the class", Argument.MULTI); - - public static Help.Info HELP_INFO = new Help.Info( - "java", - "Execute the main method of the given java class", - new Parameter[]{ - new Parameter(ARG_CLASS, Parameter.MANDATORY), - new Parameter(ARG_ARGS, Parameter.OPTIONAL) - } - ); - - public static void main(String[] args) - throws Exception { + private final ClassNameArgument ARG_CLASS = + new ClassNameArgument("className", Argument.MANDATORY, "the class to execute"); + private final StringArgument ARG_ARGS = + new StringArgument("arg", Argument.OPTIONAL | Argument.MULTIPLE, + "the argument(s) to pass to the class"); + + public JavaCommand() { + super("Run a Java class via its 'main' method"); + registerArguments(ARG_ARGS, ARG_CLASS); + } + + public static void main(String[] args) throws Exception { new JavaCommand().execute(args); } /** - * Execute this command + * Execute the command */ public void execute(CommandLine cmdLine, InputStream in, PrintStream out, PrintStream err) throws Exception { - ParsedArguments args = HELP_INFO.parse(cmdLine); - + // Build our classloader final ClassLoader parent_cl = Thread.currentThread().getContextClassLoader(); JCClassLoader cl = new JCClassLoader(parent_cl, new String[]{"./"}); - - Class<?> cls = cl.loadClass(ARG_CLASS.getValue(args)); - - Method mainMethod = cls.getMethod("main", new Class[] { String[].class }); - - String[] clsArgs = ARG_ARGS.getValues(args); - if (clsArgs == null) { - clsArgs = new String[0]; + + Method mainMethod = null; + try { + // Find (if necessary load) the class to be executed. + Class<?> cls = cl.loadClass(ARG_CLASS.getValue()); + // Lookup and check the 'main' method. + mainMethod = cls.getMethod("main", new Class[]{String[].class}); + if ((mainMethod.getModifiers() & Modifier.STATIC) == 0) { + err.println("The 'main' method for this class is not static"); + exit(1); + } + if ((mainMethod.getModifiers() & Modifier.PUBLIC) == 0) { + err.println("The 'main' method for this class is not public"); + exit(1); + } + String[] mainArgs = ARG_ARGS.isSet() ? ARG_ARGS.getValues() : new String[0]; + mainMethod.invoke(null, new Object[]{mainArgs}); + } + catch (ClassNotFoundException ex) { + err.println("Cannot find the supplied class: " + ARG_CLASS.getValue()); + exit(1); + } + catch (NoSuchMethodException ex) { + err.println("Cannot the 'void main(String[])' method for class " + ARG_CLASS.getValue()); + exit(1); + } + catch (InvocationTargetException ex) { + // We unwrap and rethrow any exceptions that were thrown by 'invoke'. It is + // up to the shell to print a stacktrace ... or not. + Throwable t = ex.getTargetException(); + if (t instanceof Exception) { + throw (Exception) t; + } + else { + throw (Error) t; + } } - - try { - mainMethod.invoke(null, new Object[] { clsArgs }); - } catch (InvocationTargetException ex) { - ex.getTargetException().printStackTrace(err); - exit(1); - } } + /** + * This class loader looks in the supplied list of directories after + * checking the parent class loader. + */ private static class JCClassLoader extends ClassLoader { - private String dirs[]; + private String dirs[]; public JCClassLoader(ClassLoader parent, String[] dir) { super(parent); @@ -101,54 +131,49 @@ } protected URL findResource(String name) { - try{ - System.out.println("Find res: " + name); + try { return findResource(name, dirs); - }catch(Exception e){ - + } catch (MalformedURLException e) { + return null; } - return null; } - private URL findResource(String name, String[] dirs) throws Exception{ - - for(int i = 0; i < dirs.length; i++){ + private URL findResource(String name, String[] dirs) + throws MalformedURLException { + for (int i = 0; i < dirs.length; i++) { File d = new File(dirs[i]); - if(d.isDirectory()){ - System.out.println("Find res: " + name + " in " + d); + if (d.isDirectory()) { return findResource(name, d.list()); - }else{ - System.out.println("Find res: " + name + " as " + d); - if(d.getName().equals(name)){ - return d.toURL(); - } + } + else if (d.getName().equals(name)) { + return d.toURI().toURL(); } } - return null; } - private byte[] loadClassData(String name) throws ClassNotFoundException{ - String fn = name.replace('.','/'); - File f = null; - for(int i = 0; i < dirs.length; i++){ - f = new File(dirs[i] + fn + ".class"); - if(f.exists()) break; - f = null; - } - if(f == null){ - throw new ClassNotFoundException(name); - }else{ - byte[] data = new byte[(int) f.length()]; - try{ - FileInputStream fis = new FileInputStream(f); - fis.read(data); - return data; - }catch(Exception fnfe){ - throw new ClassNotFoundException(name); - } - } - } - } + private byte[] loadClassData(String name) throws ClassNotFoundException{ + String fn = name.replace('.','/'); + File f = null; + for (int i = 0; i < dirs.length; i++) { + f = new File(dirs[i] + fn + ".class"); + if (f.exists()) { + break; + } + f = null; + } + if (f == null) { + throw new ClassNotFoundException(name); + } + byte[] data = new byte[(int) f.length()]; + try { + FileInputStream fis = new FileInputStream(f); + fis.read(data); + return data; + } catch (IOException ex) { + throw new ClassNotFoundException(name, ex); + } + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-04-24 11:36:44
|
Revision: 4009 http://jnode.svn.sourceforge.net/jnode/?rev=4009&view=rev Author: crawley Date: 2008-04-24 04:36:41 -0700 (Thu, 24 Apr 2008) Log Message: ----------- Converted KillCommand. Note that 'kill' is currently failing due to a SecurityException. This is probably a good thing ... Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/KillCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-23 18:50:23 UTC (rev 4008) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-24 11:36:41 UTC (rev 4009) @@ -144,6 +144,12 @@ <repeat><argument argLabel="arg"/></repeat> </sequence> </syntax> + <syntax alias="kill" description="Kill a thread"> + <sequence> + <repeat maxCount="1"><option argLabel="debug" longName="debug"/></repeat> + <argument argLabel="threadId"/> + </sequence> + </syntax> <syntax alias="run" description="Run a command file"> <argument argLabel="file"/> </syntax> Modified: trunk/shell/src/shell/org/jnode/shell/command/KillCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/KillCommand.java 2008-04-23 18:50:23 UTC (rev 4008) +++ trunk/shell/src/shell/org/jnode/shell/command/KillCommand.java 2008-04-24 11:36:41 UTC (rev 4009) @@ -26,73 +26,95 @@ 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.IntegerArgument; +import org.jnode.shell.syntax.*; /** * @author Andreas H\u00e4nel + * @author cr...@jn... */ public class KillCommand extends AbstractCommand { - - static IntegerArgument ARG_THREADID = new IntegerArgument("id", "the id of the thread to kill"); - - public static Help.Info HELP_INFO = new Help.Info( - "kill", new Syntax[] { - new Syntax("kill the Thread with given id", - new Parameter[] { - new Parameter(ARG_THREADID, Parameter.MANDATORY) - } - ) - }); - + + private final IntegerArgument ARG_THREADID = + new IntegerArgument("threadId", Argument.MANDATORY, "the id of the thread to be kill"); + private final FlagArgument FLAG_DEBUG = + new FlagArgument("debug", Argument.OPTIONAL, "if set, print debug information"); + + public KillCommand() { + super("kill the thread with the id supplied"); + registerArguments(ARG_THREADID, FLAG_DEBUG); + } + public static void main(String[] args) throws Exception { new KillCommand().execute(args); } - public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception { - ParsedArguments parsedArguments = HELP_INFO.parse(commandLine); - out.print("going to kill Thread with id : "); - out.println(ARG_THREADID.getInteger(parsedArguments)); - // kill Thread - ThreadGroup grp = Thread.currentThread().getThreadGroup(); - while (grp.getParent() != null) { - grp = grp.getParent(); - } - kill(grp,ARG_THREADID.getInteger(parsedArguments),out); - + @SuppressWarnings("deprecation") + public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) + throws Exception { + boolean debug = FLAG_DEBUG.isSet(); + int threadId = ARG_THREADID.getValue(); + if (debug) { + out.print("preparing to kill thread with id " + threadId); + } + // In order to kill the thread, we need to traverse the thread group tree, looking + // for the thread whose 'id' matches the supplied one. First, find the tree root. + ThreadGroup grp = Thread.currentThread().getThreadGroup(); + while (grp.getParent() != null) { + grp = grp.getParent(); + } + // Next search the tree + Thread t = findThread(grp, threadId); + // Finally, kill the thread if we found one. + if (t != null) { + if (debug) { + out.print("found the thread: "); + } + out.println(threadId); + // FIXME ... this is bad. Killing a thread this way could in theory bring down the + // entire system if we do it at a point where the application thread is executing + // a method that is updating OS data structures. + t.stop(new ThreadDeath()); + out.println("Killed thread " + threadId); + } + else { + out.println("Thread " + threadId + " not found"); + exit(1); + } } - - @SuppressWarnings("deprecation") - private void kill(ThreadGroup grp,int id,PrintStream out){ - 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 (t.getId()==id){ - out.print("found the thread : "); - out.println(id); - t.stop(new ThreadDeath()); - out.println("killed it..."); - } - } - } - final int gmax = grp.activeGroupCount() * 2; - final ThreadGroup[] tgs = new ThreadGroup[gmax]; - grp.enumerate(tgs); - for (int i = 0; i < gmax; i++) { - final ThreadGroup tg = tgs[i]; - if (tg != null) { - kill(tg, id, out); - } - } - + /** + * Search thread group 'grp' and its dependents groups for a given thread. + * @param grp the thread group to search + * @param id the id of the thread we are looking for + * @return the Thread found or <code>null</code> + */ + private Thread findThread(ThreadGroup grp, int id) { + // Search the current thread group + 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 (t.getId() == id) { + return t; + } + } + } + // Recursively search the child thread groups + final int gmax = grp.activeGroupCount() * 2; + final ThreadGroup[] tgs = new ThreadGroup[gmax]; + grp.enumerate(tgs); + for (int i = 0; i < gmax; i++) { + final ThreadGroup tg = tgs[i]; + if (tg != null) { + Thread t = findThread(tg, id); + if (t != null) { + return t; + } + } + } + // Didn't find it here + return null; } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-04-24 14:27:51
|
Revision: 4012 http://jnode.svn.sourceforge.net/jnode/?rev=4012&view=rev Author: crawley Date: 2008-04-24 07:27:45 -0700 (Thu, 24 Apr 2008) Log Message: ----------- Converted LoadkeysCommand Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/LoadkeysCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-24 14:26:48 UTC (rev 4011) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-24 14:27:45 UTC (rev 4012) @@ -150,6 +150,18 @@ <argument argLabel="threadId"/> </sequence> </syntax> + <syntax alias="loadkeys"> + <empty description="print the current keyboard layout"/> + <sequence description="change the keyboard layout"> + <argument argLabel="country"/> + <repeat maxCount="1"> + <sequence> + <argument argLabel="language"/> + <repeat maxCount="1"><argument argLabel="variant"/></repeat> + </sequence> + </repeat> + </sequence> + </syntax> <syntax alias="run" description="Run a command file"> <argument argLabel="file"/> </syntax> Modified: trunk/shell/src/shell/org/jnode/shell/command/LoadkeysCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/LoadkeysCommand.java 2008-04-24 14:26:48 UTC (rev 4011) +++ trunk/shell/src/shell/org/jnode/shell/command/LoadkeysCommand.java 2008-04-24 14:27:45 UTC (rev 4012) @@ -32,41 +32,31 @@ import org.jnode.driver.input.KeyboardInterpreterFactory; import org.jnode.shell.AbstractCommand; import org.jnode.shell.CommandLine; -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.CountryArgument; -import org.jnode.shell.help.argument.LanguageArgument; +import org.jnode.shell.syntax.Argument; +import org.jnode.shell.syntax.CountryArgument; +import org.jnode.shell.syntax.LanguageArgument; +import org.jnode.shell.syntax.StringArgument; /** * @author Marc DENTY - * @version Feb 2004 - * @since 0.15 + * @author cr...@jn... */ public class LoadkeysCommand extends AbstractCommand { - static final Argument COUNTRY = new CountryArgument("country", "country parameter"); + private final CountryArgument ARG_COUNTRY = + new CountryArgument("country", Argument.OPTIONAL, "country code"); - static final Argument LANGUAGE = new LanguageArgument("language", "language parameter"); + private final LanguageArgument ARG_LANGUAGE = + new LanguageArgument("language", Argument.OPTIONAL, "language parameter"); - static final Argument VARIANT = new Argument("variant", "variant parameter"); + private final StringArgument ARG_VARIANT = + new StringArgument("variant", Argument.OPTIONAL, "variant parameter"); + + public LoadkeysCommand() { + super("display or change the current keyboard layout"); + registerArguments(ARG_COUNTRY, ARG_LANGUAGE, ARG_VARIANT); + } - static final Parameter PARAM_COUNTRY = new Parameter(COUNTRY); - - static final Parameter PARAM_LANGUAGE = new Parameter(LANGUAGE, Parameter.OPTIONAL); - - static final Parameter PARAM_VARIANT = new Parameter(VARIANT, Parameter.OPTIONAL); - - public static Help.Info HELP_INFO = new Help.Info( - "loadkeys", - new Syntax[] { - new Syntax("Display the current keyboard layout"), - new Syntax("change the current keyboard layout\n\tExample : loadkeys fr", - PARAM_COUNTRY, PARAM_LANGUAGE, PARAM_VARIANT) - }); - public static void main(String[] args) throws Exception { new LoadkeysCommand().execute(args); } @@ -76,40 +66,43 @@ */ public void execute(CommandLine cmdLine, InputStream in, PrintStream out, PrintStream err) throws Exception { - final Collection<Device> kbDevs = DeviceUtils - .getDevicesByAPI(KeyboardAPI.class); + final Collection<Device> kbDevs = + DeviceUtils.getDevicesByAPI(KeyboardAPI.class); - ParsedArguments args = HELP_INFO.parse(cmdLine); + final String country = ARG_COUNTRY.isSet() ? ARG_COUNTRY.getValue() : null; + + if (country == null) { + for (Device kb : kbDevs) { + final KeyboardAPI api = kb.getAPI(KeyboardAPI.class); + out.println("Current layout for keyboard " + kb.getId() + ": " + + api.getKbInterpreter().getClass().getName()); + } + } + else { + String language = ARG_LANGUAGE.isSet() ? ARG_LANGUAGE.getValue() : ""; + String variant = ARG_VARIANT.isSet() ? ARG_VARIANT.getValue() : ""; + if (language.trim().length() == 0) { + language = null; + } + if (variant.trim().length() == 0) { + variant = null; + } - for (Device kb : kbDevs) { - final KeyboardAPI api = kb.getAPI(KeyboardAPI.class); - - if (!PARAM_COUNTRY.isSet(args)) { - out.println("layout currently loaded : " - + api.getKbInterpreter().getClass().getName()); - } else { - final String country = COUNTRY.getValue(args); - String language = LANGUAGE.getValue(args); - String variant = VARIANT.getValue(args); - - //TODO add more validation for country and language - if(language != null && - !language.equals(language.toLowerCase()) && - variant == null){ - - variant = language; - language = null; - } - - final KeyboardInterpreter kbInt = KeyboardInterpreterFactory - .getKeyboardInterpreter(country, language, variant); + for (Device kb : kbDevs) { + final KeyboardAPI api = kb.getAPI(KeyboardAPI.class); + final KeyboardInterpreter kbInt = + KeyboardInterpreterFactory.getKeyboardInterpreter( + country, language, variant); if (kbInt != null) { - api.setKbInterpreter(kbInt); - } else { - out.println("Not found"); + out.println("Setting layout for keyboard " + kb.getId() + " to " + + kbInt.getClass().getName()); + api.setKbInterpreter(kbInt); + } + else { + out.println("No suitable keyboard layout found"); + break; } } } - out.println(" Done."); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cr...@us...> - 2008-04-25 05:56:05
|
Revision: 4017 http://jnode.svn.sourceforge.net/jnode/?rev=4017&view=rev Author: crawley Date: 2008-04-24 22:56:03 -0700 (Thu, 24 Apr 2008) Log Message: ----------- Converted LocaleCommand, and added the "--list" option to list all available Locales. Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/LocaleCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-25 03:37:47 UTC (rev 4016) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-25 05:56:03 UTC (rev 4017) @@ -160,6 +160,19 @@ </optional> </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"> + <argument argLabel="language"/> + <optional> + <argument argLabel="country"/> + <optional> + <argument argLabel="variant"/> + </optional> + </optional> + </sequence> + </syntax> <syntax alias="run" description="Run a command file"> <argument argLabel="file"/> </syntax> Modified: trunk/shell/src/shell/org/jnode/shell/command/LocaleCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/LocaleCommand.java 2008-04-25 03:37:47 UTC (rev 4016) +++ trunk/shell/src/shell/org/jnode/shell/command/LocaleCommand.java 2008-04-25 05:56:03 UTC (rev 4017) @@ -23,104 +23,111 @@ import java.io.InputStream; import java.io.PrintStream; +import java.util.Arrays; +import java.util.Comparator; import java.util.Locale; +import java.util.TreeSet; -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.CountryArgument; -import org.jnode.shell.help.argument.LanguageArgument; +import org.jnode.shell.AbstractCommand; +import org.jnode.shell.CommandLine; +import org.jnode.shell.syntax.Argument; +import org.jnode.shell.syntax.CountryArgument; +import org.jnode.shell.syntax.FlagArgument; +import org.jnode.shell.syntax.LanguageArgument; +import org.jnode.shell.syntax.StringArgument; /** - * Change the default locale of JNode + * Manage JNode's default locale. * * @author Fabien DUMINY (fd...@jn...) + * @author cr...@jn... */ -public class LocaleCommand { +public class LocaleCommand extends AbstractCommand { - static final Argument LANGUAGE = new LanguageArgument("language", "language parameter"); - static final Argument COUNTRY = new CountryArgument("country", "country parameter"); - static final Argument VARIANT = new Argument("variant", "variant parameter"); + private final LanguageArgument ARG_LANGUAGE = + new LanguageArgument("language", Argument.OPTIONAL, "the locale's language"); + private final CountryArgument ARG_COUNTRY = + new CountryArgument("country", Argument.OPTIONAL, "the locale's country"); + private final StringArgument ARG_VARIANT = + new StringArgument("variant", Argument.OPTIONAL, "the locale's variant"); + private final FlagArgument FLAG_LIST = + new FlagArgument("list", Argument.OPTIONAL, "if set, list the available Locales"); - static final Parameter PARAM_LANGUAGE = new Parameter(LANGUAGE, Parameter.MANDATORY); - static final Parameter PARAM_COUNTRY = new Parameter(COUNTRY, Parameter.OPTIONAL); - static final Parameter PARAM_VARIANT = new Parameter(VARIANT, Parameter.OPTIONAL); - - public static Help.Info HELP_INFO = new Help.Info( - "locale", - new Syntax[] { - new Syntax("Display the current locale"), - new Syntax("Change the current locale\n\tExample : locale fr FR", - PARAM_LANGUAGE, PARAM_COUNTRY, PARAM_VARIANT) - }); - + public LocaleCommand() { + super("print or change JNode's default Locale"); + registerArguments(ARG_LANGUAGE, ARG_COUNTRY, ARG_VARIANT, FLAG_LIST); + } + public static void main(String[] args) throws Exception { - new LocaleCommand().execute(args, System.in, System.out, System.err); + new LocaleCommand().execute(args); } - /** - * Execute this command - */ - protected void execute(String[] args, InputStream in, PrintStream out, - PrintStream err) throws Exception { + @Override + public void execute(CommandLine commandLine, InputStream in, + PrintStream out, PrintStream err) throws Exception { + if (ARG_LANGUAGE.isSet()) { + final String language = ARG_LANGUAGE.getValue(); - ParsedArguments cmdLine = HELP_INFO.parse(args); - - if (PARAM_LANGUAGE.isSatisfied()) { - final String language = LANGUAGE.getValue(cmdLine); + String country = (ARG_COUNTRY.isSet()) ? ARG_COUNTRY.getValue() : ""; + String variant = (ARG_VARIANT.isSet()) ? ARG_VARIANT.getValue() : ""; - String country = ""; - if(PARAM_COUNTRY.isSatisfied()) - { - country = COUNTRY.getValue(cmdLine); - } - - String variant = ""; - if(PARAM_VARIANT.isSatisfied()) - { - variant = VARIANT.getValue(cmdLine); - } - Locale locale = findLocale(language, country, variant); - if(locale == null) - { - err.println("locale not available "+language+" "+country+" "+variant); - return; + if (locale == null) { + err.println("No Locale is available for " + language + " " + country + " " + variant); + exit(1); } - + out.println("Setting default Locale to " + formatLocale(locale)); Locale.setDefault(locale); - } - - out.println("current locale : " + Locale.getDefault().getDisplayName()); + } + else if (FLAG_LIST.isSet()) { + listLocales(out); + } + else { + out.println("Current default Locale is " + formatLocale(Locale.getDefault())); + } } /** - * Find the locale among the available locales + * List the available Locales in alphabetical order + * + * @param out destination for the listing + */ + private void listLocales(PrintStream out) { + // (The getAvailableLocales() method returns a cloned array ...) + Locale[] locales = Locale.getAvailableLocales(); + TreeSet<Locale> treeSet = new TreeSet<Locale>(new Comparator<Locale>() { + public int compare(Locale o1, Locale o2) { + return o1.getDisplayName().compareTo(o2.getDisplayName()); + } + }); + treeSet.addAll(Arrays.asList(locales)); + for (Locale l : treeSet) { + out.println(formatLocale(l)); + } + } + + private String formatLocale(Locale l) { + return (l.getDisplayName() + " : " + l.getLanguage() + + " " + l.getCountry() + " " + l.getVariant()); + } + + /** + * Find a Locale that matches the supplied language / country / variant triple. * - * @param language - * @param country - * @param variant - * @return + * @param language the language for the required Locale + * @param country the country code for the required Locale + * @param variant the variant for the required Locale + * @return the requested Locale, or <code>null</code> */ protected Locale findLocale(String language, String country, String variant) { - Locale[] locales = Locale.getAvailableLocales(); - Locale locale = null; - - for(int i = 0 ; i < locales.length ; i++) - { - Locale l = locales[i]; - if(l.getCountry().equals(country) && - l.getLanguage().equals(language) && - l.getVariant().equals(variant)) - { - locale = l; - break; - } + for (Locale l : Locale.getAvailableLocales()) { + if (l.getCountry().equals(country) && + l.getLanguage().equals(language) && + l.getVariant().equals(variant)) { + return l; + } } - - return locale; + return null; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |