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 2008/06/05 14:27:48 UTC

svn commit: r663583 - in /geronimo/gshell/trunk: gshell-api/src/main/java/org/apache/geronimo/gshell/command/ gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/ gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/

Author: jdillon
Date: Thu Jun  5 05:27:48 2008
New Revision: 663583

URL: http://svn.apache.org/viewvc?rev=663583&view=rev
Log:
Starting to refactor out Command and replace with Executable and let CommandContainer be used for non-execution bits

Added:
    geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Executable.java
      - copied, changed from r662817, geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Command.java
Modified:
    geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Command.java
    geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandContainer.java
    geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/DefaultCommandContainer.java
    geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/ComponentDescriptorSupport.java

Modified: geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Command.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Command.java?rev=663583&r1=663582&r2=663583&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Command.java (original)
+++ geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Command.java Thu Jun  5 05:27:48 2008
@@ -24,32 +24,13 @@
  *
  * @version $Rev$ $Date$
  */
+@Deprecated
 public interface Command
+    extends Executable
 {
-    /** Standard command success status code. */
-    Result SUCCESS = Result.SUCCESS;
-
-    /** Standard command failure status code. */
-    Result FAILURE = Result.FAILURE;
-
     @Deprecated
     String getId();
 
     @Deprecated
     String getDescription();
-
-    /**
-     * Execute the commands behavior.
-     */
-    Object execute(CommandContext context, Object... args) throws Exception;
-
-    //
-    // Result
-    //
-
-    enum Result
-    {
-        SUCCESS,
-        FAILURE
-    }
 }

Modified: geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandContainer.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandContainer.java?rev=663583&r1=663582&r2=663583&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandContainer.java (original)
+++ geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandContainer.java Thu Jun  5 05:27:48 2008
@@ -19,6 +19,8 @@
 
 package org.apache.geronimo.gshell.command;
 
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+
 /**
  * ???
  * 
@@ -26,7 +28,13 @@
  */
 public interface CommandContainer
 {
-    // TODO: Change to ShellContext, let the container build its own CommandContext
+    String getId();
+
+    String getDescription();
+
+    Executable getExecutable();
     
+    // TODO: Change to ShellContext, let the container build its own CommandContext
+
     Object execute(CommandContext context, Object... args) throws Exception;
 }
\ No newline at end of file

Copied: geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Executable.java (from r662817, geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Command.java)
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Executable.java?p2=geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Executable.java&p1=geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Command.java&r1=662817&r2=663583&rev=663583&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Command.java (original)
+++ geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Executable.java Thu Jun  5 05:27:48 2008
@@ -20,27 +20,16 @@
 package org.apache.geronimo.gshell.command;
 
 /**
- * Provides the basic interface for commands.
+ * ???
  *
  * @version $Rev$ $Date$
  */
-public interface Command
+public interface Executable
 {
-    /** Standard command success status code. */
     Result SUCCESS = Result.SUCCESS;
 
-    /** Standard command failure status code. */
     Result FAILURE = Result.FAILURE;
 
-    @Deprecated
-    String getId();
-
-    @Deprecated
-    String getDescription();
-
-    /**
-     * Execute the commands behavior.
-     */
     Object execute(CommandContext context, Object... args) throws Exception;
 
     //
@@ -52,4 +41,4 @@
         SUCCESS,
         FAILURE
     }
-}
+}
\ No newline at end of file

Modified: geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/DefaultCommandContainer.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/DefaultCommandContainer.java?rev=663583&r1=663582&r2=663583&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/DefaultCommandContainer.java (original)
+++ geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/DefaultCommandContainer.java Thu Jun  5 05:27:48 2008
@@ -22,11 +22,14 @@
 import org.apache.geronimo.gshell.command.CommandContainer;
 import org.apache.geronimo.gshell.command.Command;
 import org.apache.geronimo.gshell.command.CommandContext;
+import org.apache.geronimo.gshell.command.Executable;
+import org.apache.geronimo.gshell.command.annotation.CommandComponent;
 import org.apache.geronimo.gshell.plexus.GShellPlexusContainer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.codehaus.plexus.component.annotations.Configuration;
 import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
 import org.codehaus.plexus.context.Context;
 import org.codehaus.plexus.context.ContextException;
@@ -45,7 +48,7 @@
 
     private GShellPlexusContainer container;
 
-    @Configuration("")
+    @Configuration("invalid")
     private String commandId;
 
     // Contextualizable
@@ -55,22 +58,54 @@
 
         container = (GShellPlexusContainer) context.get(PlexusConstants.PLEXUS_KEY);
         assert container != null;
+        
         log.debug("Container: {}", container);
     }
 
     // CommandContainer
 
+    public String getId() {
+        return commandId;
+    }
+
+    public String getDescription() {
+        //
+        // FIXME:
+        //
+
+        CommandComponent cmd = getExecutable().getClass().getAnnotation(CommandComponent.class);
+        if (cmd == null) {
+            throw new IllegalStateException("Command description not found");
+        }
+        return cmd.description();
+    }
+
+    public Executable getExecutable() {
+        assert container != null;
+
+        try {
+            return container.lookupComponent(Command.class, commandId);
+        }
+        catch (ComponentLookupException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
     public Object execute(final CommandContext context, final Object... args) throws Exception {
         assert context != null;
         assert args != null;
 
         log.trace("Executing; context={}, args={}", context, args);
 
-        assert container != null;
+        Executable executable = getExecutable();
+
+        // TODO: Handle logging muck
         
-        Command command = container.lookupComponent(Command.class, commandId);
+        // TODO: Bind context, io and variables
+
+        // TODO: Process CLP
 
-        Object result = command.execute(context, args);
+        Object result = executable.execute(context, args);
 
         log.trace("Result: {}", result);
 

Modified: geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/ComponentDescriptorSupport.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/ComponentDescriptorSupport.java?rev=663583&r1=663582&r2=663583&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/ComponentDescriptorSupport.java (original)
+++ geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/ComponentDescriptorSupport.java Thu Jun  5 05:27:48 2008
@@ -24,8 +24,8 @@
 import org.codehaus.plexus.component.repository.ComponentDescriptor;
 
 /**
- * ???
- *
+ * Support for {@link ComponentDescriptor} implementations.
+ * 
  * @version $Rev$ $Date$
  */
 public class ComponentDescriptorSupport