geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r595921 - in /geronimo/gshell/trunk: gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/ gshell-core/src/main/java/org/apache/geronimo/gshell/ gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/ gshell-core/s...
Date Sat, 17 Nov 2007 08:30:18 GMT
Author: jdillon
Date: Sat Nov 17 00:30:08 2007
New Revision: 595921

URL: http://svn.apache.org/viewvc?rev=595921&view=rev
Log:
(GSHELL-71) Added command info
(GSHELL-59) Add getPath to node expose in command info

Added:
    geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandInfo.java
      - copied, changed from r595888, geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandContext.java
    geronimo/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/layout/model/NodeTest.java
      - copied, changed from r595888, geronimo/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/layout/model/GroupNodeTest.java
Modified:
    geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandContext.java
    geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
    geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultCommandExecutor.java
    geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/GroupNode.java
    geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/Node.java

Modified: geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandContext.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandContext.java?rev=595921&r1=595920&r2=595921&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandContext.java
(original)
+++ geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandContext.java
Sat Nov 17 00:30:08 2007
@@ -30,9 +30,5 @@
 
     Variables getVariables();
 
-    String getCommandId();
-
-    String getCommandName();
-
-    String getAliasName();
+    CommandInfo getInfo();
 }

Copied: geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandInfo.java
(from r595888, geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandContext.java)
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandInfo.java?p2=geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandInfo.java&p1=geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandContext.java&r1=595888&r2=595921&rev=595921&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandContext.java
(original)
+++ geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandInfo.java
Sat Nov 17 00:30:08 2007
@@ -20,19 +20,35 @@
 package org.apache.geronimo.gshell.command;
 
 /**
- * Provides commands with the context of its execution.
+ * Details about the command.
  *
  * @version $Rev$ $Date$
  */
-public interface CommandContext
+public interface CommandInfo
 {
-    IO getIO();
+    /**
+     * Returns the <em>identifier</em> for the command.
+     */
+    String getId();
 
-    Variables getVariables();
+    /**
+     * Returns the name of the command.
+     */
+    String getName();
 
-    String getCommandId();
+    /**
+     * Returns the alias used to invoke the command if any.
+     *
+     * @return  The alias used to invoke the command; null if not aliased.
+     */
+    String getAlias();
 
-    String getCommandName();
+    //
+    // TODO: Add alias path?  And/or expose layout node?
+    //
 
-    String getAliasName();
+    /**
+     * Returns the full path of the command.
+     */
+    String getPath();
 }

Modified: geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java?rev=595921&r1=595920&r2=595921&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
(original)
+++ geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
Sat Nov 17 00:30:08 2007
@@ -90,7 +90,7 @@
         // Handle --help/-h automatically for the command
         if (displayHelp) {
             //
-            // TODO: Make a special PrinterHandler to abstrat this muck from having to process
it by hand
+            // TODO: Make a special PrinterHandler to abstract this muck from having to process
it by hand
             //
             
             displayHelp(context, clp);
@@ -98,10 +98,6 @@
             return SUCCESS;
         }
 
-        assert context != null;
-        assert io != null;
-        assert variables != null;
-
         return doExecute();
     }
 
@@ -111,11 +107,16 @@
         assert context != null;
         assert clp != null;
 
-        String name = context.getAliasName();
+        // Use the alias if we have one, else use the command name
+        String name = context.getInfo().getAlias();
         if (name == null) {
-            name = context.getCommandName();
+            name = context.getInfo().getName();
         }
 
+        //
+        // FIXME: This is uuuuuggggllyyyy
+        //
+        
         io.out.println(name);
         io.out.println(" -- ");
         io.out.println();

Modified: geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultCommandExecutor.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultCommandExecutor.java?rev=595921&r1=595920&r2=595921&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultCommandExecutor.java
(original)
+++ geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultCommandExecutor.java
Sat Nov 17 00:30:08 2007
@@ -24,6 +24,7 @@
 import org.apache.geronimo.gshell.command.CommandExecutor;
 import org.apache.geronimo.gshell.command.IO;
 import org.apache.geronimo.gshell.command.Variables;
+import org.apache.geronimo.gshell.command.CommandInfo;
 import org.apache.geronimo.gshell.common.Arguments;
 import org.apache.geronimo.gshell.common.StopWatch;
 import org.apache.geronimo.gshell.layout.LayoutManager;
@@ -148,6 +149,8 @@
             // Command instances get their own namespace with defaults from the current
             final Variables vars = new DefaultVariables(env.getVariables());
 
+            CommandInfo info;
+
             public IO getIO() {
                 return env.getIO();
             }
@@ -156,24 +159,41 @@
                 return vars;
             }
 
-            public String getCommandId() {
-                return id;
-            }
-
-            public String getCommandName() {
-                if (node instanceof AliasNode) {
-                    return ((AliasNode)node).getCommand();
-                }
-
-                return node.getName();
-            }
-
-            public String getAliasName() {
-                if (node instanceof AliasNode) {
-                    return ((AliasNode)node).getName();
+            public CommandInfo getInfo() {
+                if (info == null) {
+                    info = new CommandInfo()
+                    {
+                        public String getId() {
+                            return id;
+                        }
+
+                        public String getName() {
+                            if (node instanceof AliasNode) {
+                                return ((AliasNode)node).getCommand();
+                            }
+
+                            return node.getName();
+                        }
+
+                        public String getAlias() {
+                            if (node instanceof AliasNode) {
+                                return node.getName();
+                            }
+
+                            return null;
+                        }
+
+                        public String getPath() {
+                            //
+                            // TODO:
+                            //
+
+                            return null;
+                        }
+                    };
                 }
 
-                return null;
+                return info;
             }
         };
 

Modified: geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/GroupNode.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/GroupNode.java?rev=595921&r1=595920&r2=595921&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/GroupNode.java
(original)
+++ geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/GroupNode.java
Sat Nov 17 00:30:08 2007
@@ -40,28 +40,7 @@
     public GroupNode(final String name) {
         super(name);
     }
-
-    public String getPath() {
-        StringBuffer buff = new StringBuffer();
-        Node node = this;
-
-        while (node != null) {
-            buff.insert(0, node.getName());
-
-            node = node.getParent();
-
-            if (node != null) {
-                buff.insert(0, LayoutManager.PATH_SEPARATOR);
-            }
-
-            if (node instanceof Layout) {
-                break;
-            }
-        }
-
-        return buff.toString();
-    }
-
+    
     public void add(final Node child) {
         assert child != null;
 

Modified: geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/Node.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/Node.java?rev=595921&r1=595920&r2=595921&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/Node.java
(original)
+++ geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/Node.java
Sat Nov 17 00:30:08 2007
@@ -30,6 +30,8 @@
  */
 public abstract class Node
 {
+    public static final String SEPARATOR = "/";
+
     public static final String ROOT = "/";
     
     protected String name;
@@ -53,6 +55,27 @@
 
     public void setParent(final Node parent) {
         this.parent = parent;
+    }
+
+    public String getPath() {
+        StringBuffer buff = new StringBuffer();
+        Node node = this;
+
+        while (node != null) {
+            buff.insert(0, node.getName());
+
+            node = node.getParent();
+
+            if (node != null) {
+                buff.insert(0, SEPARATOR);
+            }
+
+            if (node instanceof Layout) {
+                break;
+            }
+        }
+
+        return buff.toString();
     }
 
     public String toString() {

Copied: geronimo/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/layout/model/NodeTest.java
(from r595888, geronimo/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/layout/model/GroupNodeTest.java)
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/layout/model/NodeTest.java?p2=geronimo/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/layout/model/NodeTest.java&p1=geronimo/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/layout/model/GroupNodeTest.java&r1=595888&r2=595921&rev=595921&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/layout/model/GroupNodeTest.java
(original)
+++ geronimo/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/layout/model/NodeTest.java
Sat Nov 17 00:30:08 2007
@@ -19,47 +19,49 @@
 
 package org.apache.geronimo.gshell.layout.model;
 
-import com.thoughtworks.xstream.XStream;
-import com.thoughtworks.xstream.annotations.Annotations;
 import junit.framework.TestCase;
 
 /**
- * Test for the {@link GroupNode} class.
+ * Test for the {@link Node} class.
  *
  * @version $Rev$ $Date$
  */
-public class GroupNodeTest
+public class NodeTest
     extends TestCase
 {
-    public void testAddLinks() throws Exception {
-        GroupNode group = new GroupNode("test");
+    public void testGetPath1() throws Exception {
+        Layout layout = new Layout();
 
-        Node n1 = new CommandNode("a", "b");
+        CommandNode c = new CommandNode("foo", "bar");
+        layout.add(c);
 
-        group.add(n1);
-
-        assertEquals(group, n1.getParent());
+        assertEquals("/foo", c.getPath());
     }
 
-    public void testDeserializeLinks() throws Exception {
-        GroupNode g1 = new GroupNode("test");
+    public void testGetPath2() throws Exception {
+        Layout layout = new Layout();
+
+        GroupNode g = new GroupNode("test");
+        layout.add(g);
 
-        Node n1 = new CommandNode("a", "b");
+        CommandNode c = new CommandNode("foo", "bar");
+        g.add(c);
 
-        g1.add(n1);
+        assertEquals("/test/foo", c.getPath());
+    }
 
-        XStream xs = new XStream();
+    public void testGetPath3() throws Exception {
+        Layout layout = new Layout();
 
-        Annotations.configureAliases(xs, GroupNode.class);
-        
-        String xml = xs.toXML(g1);
+        GroupNode g1 = new GroupNode("a");
+        layout.add(g1);
 
-        System.err.println("XML: " + xml);
+        GroupNode g2 = new GroupNode("b");
+        g1.add(g2);
 
-        GroupNode g2 = (GroupNode) xs.fromXML(xml);
+        CommandNode c = new CommandNode("foo", "bar");
+        g2.add(c);
 
-        Node n2 = g2.nodes().iterator().next();
-        
-        assertEquals(g2, n2.getParent());
+        assertEquals("/a/b/foo", c.getPath());
     }
 }



Mime
View raw message