You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2006/05/31 07:33:27 UTC

svn commit: r410434 - in /geronimo/sandbox/gshell/trunk: gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/ gshell-commands/scripting-commands/src/main/java/org/apache/geronimo/gshell/commands/scripting/ gshell-commands/standard-commands/src/main...

Author: jdillon
Date: Tue May 30 22:33:26 2006
New Revision: 410434

URL: http://svn.apache.org/viewvc?rev=410434&view=rev
Log:
Making use of Java 1.5 awesomeness to simplify code
Added support to allow 'help' command to work again; still need to figure out how to use IoC with Command (that is really light)
Isolated interactive bits for GShell into InteractiveGShell (moved from Main)
Added some exceptions to provide better error handling for dealing with commands

Added:
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/InteractiveGShell.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandException.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandInstantiationException.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandNotFoundException.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/GShellTest.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/command/CommandManagerTest.java   (with props)
Modified:
    geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
    geronimo/sandbox/gshell/trunk/gshell-commands/scripting-commands/src/main/java/org/apache/geronimo/gshell/commands/scripting/ScriptCommand.java
    geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/EchoCommand.java
    geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/HelpCommand.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShell.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/Command.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandContext.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandExecutor.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandManager.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/CommandLineBuilder.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/ExecutingVisitor.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/LoggingVisitor.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/command/MockCommandExecutor.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/parser/CommandLineParserVisitorTest.java

Modified: geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java?rev=410434&r1=410433&r2=410434&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java Tue May 30 22:33:26 2006
@@ -29,9 +29,8 @@
 import org.apache.commons.logging.LogFactory;
 
 import org.apache.geronimo.gshell.GShell;
+import org.apache.geronimo.gshell.InteractiveGShell;
 import org.apache.geronimo.gshell.console.IO;
-import org.apache.geronimo.gshell.console.InteractiveConsole;
-import org.apache.geronimo.gshell.console.JLineConsole;
 
 import org.apache.geronimo.gshell.util.Version;
 import org.apache.geronimo.gshell.util.Banner;
@@ -230,40 +229,14 @@
         }
 
         if (interactive) {
-            //
-            // TODO: May want to create a simple class in core to hide these details
-            //
-
-            InteractiveConsole console = new InteractiveConsole(
-                new JLineConsole(io),
-                new InteractiveConsole.Executor() {
-                    public Result execute(final String line) throws Exception {
-                        assert line != null;
-
-                        // Execute unless the line is just blank
-                        if (!line.trim().equals("")) {
-                            gshell.execute(line);
-                        }
-
-                        return Result.CONTINUE;
-                    }
-                },
-                new InteractiveConsole.Prompter() {
-                    public String getPrompt() {
-                        //
-                        // TODO: Need to hook this up to allow it to change
-                        //
-
-                        return "> ";
-                    }
-                });
+            InteractiveGShell interp = new InteractiveGShell(io, gshell);
 
             // Check if there are args, and run them and then enter interactive
             if (args.length != 0) {
                 gshell.execute(args);
             }
 
-            console.run();
+            interp.run();
         }
         else {
             int status = gshell.execute(args);

Modified: geronimo/sandbox/gshell/trunk/gshell-commands/scripting-commands/src/main/java/org/apache/geronimo/gshell/commands/scripting/ScriptCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/scripting-commands/src/main/java/org/apache/geronimo/gshell/commands/scripting/ScriptCommand.java?rev=410434&r1=410433&r2=410434&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/scripting-commands/src/main/java/org/apache/geronimo/gshell/commands/scripting/ScriptCommand.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/scripting-commands/src/main/java/org/apache/geronimo/gshell/commands/scripting/ScriptCommand.java Tue May 30 22:33:26 2006
@@ -146,7 +146,8 @@
         }
 
         if (this.interactive) {
-            InteractiveInterpreter interp = new InteractiveInterpreter(new JLineConsole(getIO()), engine, language);
+            InteractiveInterpreter interp = new InteractiveInterpreter(
+                    new JLineConsole(getIO()), engine, language);
             interp.run();
         }
 

Modified: geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/EchoCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/EchoCommand.java?rev=410434&r1=410433&r2=410434&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/EchoCommand.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/EchoCommand.java Tue May 30 22:33:26 2006
@@ -94,9 +94,9 @@
     
     private void echo(final String[] args) {
         IO io = getIO();
-        
-        for (int i=0; i<args.length; i++) {
-            io.out.print(args[i]);
+
+        for (String arg : args) {
+            io.out.print(arg);
             io.out.print(" ");
         }
         

Modified: geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/HelpCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/HelpCommand.java?rev=410434&r1=410433&r2=410434&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/HelpCommand.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/HelpCommand.java Tue May 30 22:33:26 2006
@@ -25,6 +25,7 @@
 
 import org.apache.geronimo.gshell.command.Command;
 import org.apache.geronimo.gshell.command.CommandSupport;
+import org.apache.geronimo.gshell.command.CommandManager;
 import org.apache.geronimo.gshell.console.IO;
 
 /**
@@ -79,23 +80,19 @@
         }
 
         //
-        // HACK: For now just list all know commands
+        // HACK: Need to DI this guy, but for now this will work
         //
+        
+        CommandManager manager = new CommandManager();
 
-        throw new Exception("Pending re-impl... sorry :-(");
-
-        /*
-        Map commands = ctx.getBeansOfType(Command.class);
-        Iterator iter = commands.keySet().iterator();
-
-        while (iter.hasNext()) {
-            String name = (String)iter.next();
-            Command cmd = (Command)commands.get(name);
+        //
+        // HACK: For now just list all know commands
+        //
 
+        for (String name : manager.commandNames()) {
             io.out.println(name);
         }
 
         return Command.SUCCESS;
-        */
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShell.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShell.java?rev=410434&r1=410433&r2=410434&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShell.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShell.java Tue May 30 22:33:26 2006
@@ -18,6 +18,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.commons.lang.time.StopWatch;
 import org.apache.geronimo.gshell.console.IO;
 import org.apache.geronimo.gshell.command.CommandExecutor;
 import org.apache.geronimo.gshell.command.Command;
@@ -78,6 +79,8 @@
         assert commandName != null;
         assert args != null;
 
+        boolean debug = log.isDebugEnabled();
+
         log.info("Executing (" + commandName + "): " + java.util.Arrays.asList(args));
 
         //
@@ -90,8 +93,6 @@
 
         Command cmd = new CommandManager().getCommand(commandName);
 
-        // Command cmd = (Command)ctx.getBean(commandName);
-
         cmd.init(new CommandContext() {
             Variables vars = new VariablesMap();
 
@@ -104,10 +105,21 @@
             }
         });
 
+        // Setup command timings
+        StopWatch watch = null;
+        if (debug) {
+            watch = new StopWatch();
+            watch.start();
+        }
+
         int status;
 
         try {
             status = cmd.execute(args);
+
+            if (debug) {
+                log.debug("Command completed in " + watch);
+            }
         }
         finally {
             cmd.destroy();
@@ -116,7 +128,7 @@
         return status;
     }
 
-    public int execute(final String[] args) throws Exception {
+    public int execute(final String... args) throws Exception {
         assert args != null;
         assert args.length > 1;
 

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/InteractiveGShell.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/InteractiveGShell.java?rev=410434&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/InteractiveGShell.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/InteractiveGShell.java Tue May 30 22:33:26 2006
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.gshell;
+
+import org.apache.geronimo.gshell.console.InteractiveConsole;
+import org.apache.geronimo.gshell.console.JLineConsole;
+import org.apache.geronimo.gshell.console.IO;
+
+import java.io.IOException;
+
+/**
+ * ???
+ *
+ * @version $Id$
+ */
+public class InteractiveGShell
+    extends InteractiveConsole
+{
+    public InteractiveGShell(final IO io, final GShell gshell) throws IOException {
+        super(new JLineConsole(io),
+
+            new InteractiveConsole.Executor() {
+                public Result execute(final String line) throws Exception {
+                    assert line != null;
+
+                    // Execute unless the line is just blank
+                    if (!line.trim().equals("")) {
+                        gshell.execute(line);
+                    }
+
+                    return Result.CONTINUE;
+                }
+            },
+                
+            new InteractiveConsole.Prompter() {
+                public String getPrompt() {
+                    //
+                    // TODO: Need to hook this up to allow it to change
+                    //
+
+                    return "> ";
+                }
+            });
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/InteractiveGShell.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/InteractiveGShell.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/InteractiveGShell.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/Command.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/Command.java?rev=410434&r1=410433&r2=410434&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/Command.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/Command.java Tue May 30 22:33:26 2006
@@ -37,7 +37,7 @@
     // TODO: Return an Object!  Take an Object[]!
     //
     
-    int execute(String[] args) throws Exception;
+    int execute(String... args) throws Exception;
     
     void abort(); // throws Exception ?
     

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandContext.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandContext.java?rev=410434&r1=410433&r2=410434&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandContext.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandContext.java Tue May 30 22:33:26 2006
@@ -19,7 +19,7 @@
 import org.apache.geronimo.gshell.console.IO;
 
 /**
- * ???
+ * Provides the running context (or environment) for a {@link Command}.
  *
  * @version $Id$
  */

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandException.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandException.java?rev=410434&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandException.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandException.java Tue May 30 22:33:26 2006
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.gshell.command;
+
+/**
+ * A command exception.
+ *
+ * @version $Revision$ $Date$
+ */
+public class CommandException
+    extends Exception
+{
+    public CommandException(String msg) {
+        super(msg);
+    }
+
+    public CommandException(String msg, Throwable cause) {
+        super(msg, cause);
+    }
+
+    public CommandException(Throwable cause) {
+        super(cause);
+    }
+
+    public CommandException() {
+        super();
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandException.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandExecutor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandExecutor.java?rev=410434&r1=410433&r2=410434&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandExecutor.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandExecutor.java Tue May 30 22:33:26 2006
@@ -23,9 +23,7 @@
  */
 public interface CommandExecutor
 {
-    int execute(String commandline) throws Exception;
-
-    int execute(String[] args) throws Exception;
+    int execute(String... args) throws Exception;
 
     int execute(String commandName, String[] args) throws Exception;
 }

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandInstantiationException.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandInstantiationException.java?rev=410434&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandInstantiationException.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandInstantiationException.java Tue May 30 22:33:26 2006
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.gshell.command;
+
+/**
+ * Thrown to indicate a problem instantiating a command instance.
+ *
+ * @version $Revision$ $Date$
+ */
+public class CommandInstantiationException
+    extends CommandException
+{
+    public CommandInstantiationException(final String msg) {
+        super(msg);
+    }
+
+    public CommandInstantiationException(final String msg, final Throwable cause) {
+        super(msg, cause);
+    }
+
+    public CommandInstantiationException(final Throwable cause) {
+        super(cause);
+    }
+
+    public CommandInstantiationException() {
+        super();
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandInstantiationException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandInstantiationException.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandInstantiationException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandManager.java?rev=410434&r1=410433&r2=410434&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandManager.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandManager.java Tue May 30 22:33:26 2006
@@ -18,11 +18,13 @@
 
 import org.apache.xbean.finder.ResourceFinder;
 
-import java.io.IOException;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Properties;
 import java.util.HashMap;
+import java.util.List;
+import java.util.Set;
+import java.util.Collections;
 
 /**
  * ???
@@ -33,15 +35,22 @@
 {
     private Map<String,Properties> commandDefMap = new HashMap<String,Properties>();
 
-    public CommandManager() throws IOException {
-        ResourceFinder resourceFinder = new ResourceFinder("META-INF/");
+    public CommandManager() throws CommandException {
+        try {
+            discoverCommands();
+        }
+        catch (Exception e) {
+            throw new CommandException(e);
+        }
+    }
 
-        Map<String, Properties> propertiesMap = resourceFinder.mapAllProperties("org.apache.geronimo.gshell.command");
-        Iterator<String> iter = propertiesMap.keySet().iterator();
+    private void discoverCommands() throws Exception {
+        ResourceFinder finder = new ResourceFinder("META-INF/");
+        Map<String, Properties> map = finder.mapAllProperties("org.apache.geronimo.gshell.command");
+        Iterator<String> iter = map.keySet().iterator();
 
-        while (iter.hasNext()) {
-            String filename = iter.next();
-            Properties props = propertiesMap.get(filename);
+        for (String filename : map.keySet()) {
+            Properties props = map.get(filename);
 
             String name = props.getProperty("name");
             if (name != null) {
@@ -50,14 +59,40 @@
         }
     }
 
-    public Command getCommand(final String name) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
-        assert name != null;
+    public Command getCommand(final String name) throws CommandNotFoundException, CommandInstantiationException {
+        if (name == null) {
+            throw new IllegalArgumentException("Name is null");
+        }
+        if (name.trim().length() == 0) {
+            throw new IllegalArgumentException("Name is empty");
+        }
 
         Properties props = commandDefMap.get(name);
-        ClassLoader cl = Thread.currentThread().getContextClassLoader();
-        Class type = cl.loadClass(props.getProperty("class"));
-        Command cmd = (Command)type.newInstance();
+
+        // No props means command was not discovered
+        if (props == null) {
+            throw new CommandNotFoundException(name);
+        }
+
+        String classname = props.getProperty("class");
+        if (classname == null) {
+            throw new CommandInstantiationException("Missing 'class' property for command: " + name);
+        }
+
+        Command cmd;
+        try {
+            ClassLoader cl = Thread.currentThread().getContextClassLoader();
+            Class type = cl.loadClass(classname);
+            cmd = (Command)type.newInstance();
+        }
+        catch (Exception e) {
+            throw new CommandInstantiationException(name, e);
+        }
 
         return cmd;
+    }
+    
+    public Set<String> commandNames() {
+        return Collections.unmodifiableSet(commandDefMap.keySet());
     }
 }

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandNotFoundException.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandNotFoundException.java?rev=410434&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandNotFoundException.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandNotFoundException.java Tue May 30 22:33:26 2006
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.gshell.command;
+
+/**
+ * Thrown to indicate that an operation which requires a named
+ * command has failed because the command was not found.
+ *
+ * @version $Revision$ $Date$
+ */
+public class CommandNotFoundException
+   extends CommandException
+{
+    public CommandNotFoundException(final String path) {
+        this(path, "Command or path was not found");
+    }
+
+    public CommandNotFoundException(final String path, final String msg) {
+        super(msg + ": " + path);
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandNotFoundException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandNotFoundException.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandNotFoundException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java?rev=410434&r1=410433&r2=410434&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java Tue May 30 22:33:26 2006
@@ -132,7 +132,7 @@
     // Execute Helpers
     //
     
-    public int execute(final String[] args) throws Exception {
+    public int execute(final String... args) throws Exception {
         assert args != null;
         
         // Make sure that we have been initialized before we go any further
@@ -146,6 +146,10 @@
             status = doExecute(args);
         }
         catch (Exception e) {
+            //
+            // TODO: Handle Errors here too
+            //
+            
             log.error(e.getMessage());
             if (log.isDebugEnabled()) {
                 log.debug("Failure details", e);

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/CommandLineBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/CommandLineBuilder.java?rev=410434&r1=410433&r2=410434&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/CommandLineBuilder.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/CommandLineBuilder.java Tue May 30 22:33:26 2006
@@ -35,9 +35,9 @@
 {
     private static final Log log = LogFactory.getLog(CommandLineBuilder.class);
 
-    private CommandExecutor executor;
+    private final CommandExecutor executor;
 
-    private CommandLineParser parser;
+    private final CommandLineParser parser;
 
     public CommandLineBuilder(final CommandExecutor executor) {
         if (executor == null) {

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/ExecutingVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/ExecutingVisitor.java?rev=410434&r1=410433&r2=410434&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/ExecutingVisitor.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/ExecutingVisitor.java Tue May 30 22:33:26 2006
@@ -43,7 +43,7 @@
 {
     private static final Log log = LogFactory.getLog(ExecutingVisitor.class);
 
-    private CommandExecutor executor;
+    private final CommandExecutor executor;
 
     public ExecutingVisitor(final CommandExecutor executor) {
         if (executor == null) {

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/LoggingVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/LoggingVisitor.java?rev=410434&r1=410433&r2=410434&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/LoggingVisitor.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commandline/LoggingVisitor.java Tue May 30 22:33:26 2006
@@ -26,6 +26,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.commons.lang.StringUtils;
 
 /**
  * Visitor whichs logs nodes in the tree.
@@ -35,8 +36,15 @@
 public class LoggingVisitor
     implements CommandLineParserVisitor
 {
+    public static enum Level {
+        INFO,
+        DEBUG
+    }
+
     private final Log log;
 
+    private final Level level;
+
     private int indent = 0;
 
     public LoggingVisitor() {
@@ -44,20 +52,39 @@
     }
 
     public LoggingVisitor(final Log log) {
+        this(log, Level.DEBUG);
+    }
+
+    public LoggingVisitor(final Log log, final Level level) {
         if (log == null) {
             throw new IllegalArgumentException("Log is null");
         }
+        if (level == null) {
+            throw new IllegalArgumentException("Level is null");
+        }
 
         this.log = log;
+        this.level = level;
     }
 
     private Object log(final Class type, final SimpleNode node, Object data) {
-        if (!log.isDebugEnabled()) {
-            return data;
+        // Short-circuit of logging level does not match
+        switch (level) {
+            case INFO:
+                if (!log.isInfoEnabled()) {
+                    return data;
+                }
+                break;
+
+            case DEBUG:
+                if (!log.isDebugEnabled()) {
+                    return data;
+                }
+                break;
         }
 
         StringBuffer buff = new StringBuffer();
-
+        
         for (int i=0; i<indent; i++) {
             buff.append(" ");
         }
@@ -67,11 +94,15 @@
             buff.append("; Data: ").append(data);
         }
 
-        //
-        // TODO: Expose DEBUG/INFO switch?
-        //
-
-        log.debug(buff);
+        switch (level) {
+            case INFO:
+                log.info(buff);
+                break;
+
+            case DEBUG:
+                log.debug(buff);
+                break;
+        }
 
         indent++;
         data = node.childrenAccept(this, data);

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/GShellTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/GShellTest.java?rev=410434&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/GShellTest.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/GShellTest.java Tue May 30 22:33:26 2006
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.gshell;
+
+import junit.framework.TestCase;
+import org.apache.geronimo.gshell.console.IO;
+import org.apache.geronimo.gshell.command.CommandNotFoundException;
+
+/**
+ * Unit tests for the {@link GShell} class.
+ *
+ * @version $Id$
+ */
+public class GShellTest
+    extends TestCase
+{
+    public void testConstructorArgs() throws Exception {
+        try {
+            new GShell(null);
+            fail("Accepted null value");
+        }
+        catch (IllegalArgumentException expected) {
+            // ignore
+        }
+
+        new GShell();
+
+        new GShell(new IO());
+    }
+
+    public void testExecuteVarargs() throws Exception {
+        GShell shell = new GShell();
+
+        try {
+            shell.execute("foo", "bar", "baz");
+        }
+        catch (CommandNotFoundException expected) {
+            // ignore
+        }
+    }
+
+    public void testExecuteArray() throws Exception {
+        GShell shell = new GShell();
+
+        try {
+            shell.execute(new String[]{ "foo", "bar", "baz" });
+        }
+        catch (CommandNotFoundException expected) {
+            // ignore
+        }
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/GShellTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/GShellTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/GShellTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/command/CommandManagerTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/command/CommandManagerTest.java?rev=410434&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/command/CommandManagerTest.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/command/CommandManagerTest.java Tue May 30 22:33:26 2006
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.gshell.command;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the {@link CommandManager} class.
+ *
+ * @version $Id$
+ */
+public class CommandManagerTest
+    extends TestCase
+{
+    public void testConstructor() throws Exception {
+        new CommandManager();
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/command/CommandManagerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/command/CommandManagerTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/command/CommandManagerTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/command/MockCommandExecutor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/command/MockCommandExecutor.java?rev=410434&r1=410433&r2=410434&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/command/MockCommandExecutor.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/command/MockCommandExecutor.java Tue May 30 22:33:26 2006
@@ -24,19 +24,11 @@
 public class MockCommandExecutor
     implements CommandExecutor
 {
-    public Object commandLine;
-
     public String[] args;
 
     public String commandName;
 
-    public int execute(String commandline) throws Exception {
-        this.commandLine = commandLine;
-
-        return 0;
-    }
-
-    public int execute(String[] args) throws Exception {
+    public int execute(String... args) throws Exception {
         this.args = args;
 
         return 0;

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/parser/CommandLineParserVisitorTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/parser/CommandLineParserVisitorTest.java?rev=410434&r1=410433&r2=410434&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/parser/CommandLineParserVisitorTest.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/commandline/parser/CommandLineParserVisitorTest.java Tue May 30 22:33:26 2006
@@ -49,57 +49,59 @@
         MockCommandLineVisitor v = new MockCommandLineVisitor();
 
         Object result = cl.jjtAccept(v, null);
+
+        assertNull(v.simpleNode);
+        assertNotNull(v.commandLine);
+        assertNotNull(v.expression);
+        assertNotNull(v.quotedString);
+        assertNotNull(v.opaqueString);
+        assertNotNull(v.plainString);
     }
 
     private static class MockCommandLineVisitor
         implements CommandLineParserVisitor
     {
-        public Object visit(SimpleNode node, Object data) {
-            System.out.println("SimpleNode: " + node + "; data: " + data);
+        private SimpleNode simpleNode;
+        private ASTCommandLine commandLine;
+        private ASTExpression expression;
+        private ASTQuotedString quotedString;
+        private ASTOpaqueString opaqueString;
+        private ASTPlainString plainString;
 
-            data = node.childrenAccept(this, data);
+        public Object visit(SimpleNode node, Object data) {
+            this.simpleNode = node;
 
-            return data;
+            return node.childrenAccept(this, data);
         }
 
         public Object visit(ASTCommandLine node, Object data) {
-            System.out.println("CommandLine: " + node + "; data: " + data);
-
-            data = node.childrenAccept(this, data);
+            this.commandLine = node;
 
-            return data;
+            return node.childrenAccept(this, data);
         }
 
         public Object visit(ASTExpression node, Object data) {
-            System.out.println("Expression: " + node + "; data: " + data);
+            this.expression = node;
 
-            data = node.childrenAccept(this, data);
-
-            return data;
+            return node.childrenAccept(this, data);
         }
 
         public Object visit(ASTQuotedString node, Object data) {
-            System.out.println("QuotedString: " + node + "; data: " + data);
-
-            data = node.childrenAccept(this, data);
+            this.quotedString = node;
 
-            return data;
+            return node.childrenAccept(this, data);
         }
 
         public Object visit(ASTOpaqueString node, Object data) {
-            System.out.println("OpaqueString: " + node + "; data: " + data);
+            this.opaqueString = node;
 
-            data = node.childrenAccept(this, data);
-
-            return data;
+            return node.childrenAccept(this, data);
         }
 
         public Object visit(ASTPlainString node, Object data) {
-            System.out.println("PlainString: " + node + "; data: " + data);
-
-            data = node.childrenAccept(this, data);
+            this.plainString = node;
 
-            return data;
+            return node.childrenAccept(this, data);
         }
     }
 }