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 2007/09/07 21:56:38 UTC

svn commit: r573681 - in /geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell: ShellImpl.java layout/LayoutManager.java layout/LayoutManagerImpl.java

Author: jdillon
Date: Fri Sep  7 12:56:37 2007
New Revision: 573681

URL: http://svn.apache.org/viewvc?rev=573681&view=rev
Log:
Start to hookup the layout manager to resolve command descriptors from paths

Modified:
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellImpl.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/LayoutManager.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/LayoutManagerImpl.java

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellImpl.java?rev=573681&r1=573680&r2=573681&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellImpl.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellImpl.java Fri Sep  7 12:56:37 2007
@@ -21,6 +21,7 @@
 
 import org.apache.geronimo.gshell.command.Command;
 import org.apache.geronimo.gshell.command.CommandContext;
+import org.apache.geronimo.gshell.command.CommandNotFoundException;
 import org.apache.geronimo.gshell.command.IO;
 import org.apache.geronimo.gshell.command.Variables;
 import org.apache.geronimo.gshell.command.descriptor.CommandDescriptor;
@@ -91,24 +92,25 @@
 
         log.info("Executing ({}): [{}]", commandName, Arguments.asString(args));
 
-        //
-        // HACK: Probably need to pick a better way to name the command invocation container, or do we even really need this?
-        //
+        // Look up the command descriptor for the given commandName
+        final CommandDescriptor desc = layoutManager.find(commandName);
+        if (desc == null) {
+            throw new CommandNotFoundException(commandName);
+        }
 
+        // Create a new child container for the invocation and lookup the command instance
         String realmId = "command-invocation";
-
         final PlexusContainer childContainer = container.createChildContainer(realmId, container.getContainerRealm());
-        final CommandDescriptor commandDescriptor = (CommandDescriptor) childContainer.getComponentDescriptor(Command.class.getName(), commandName);
-        final Command command = (Command)childContainer.lookup(Command.class, commandName);
+        final Command command = (Command)childContainer.lookup(desc.getRole(), desc.getRoleHint());
 
         //
         // NOTE: For now, until we can figure out a better way to have the container deal with this stuff, pass in
         //       the execution context manually
         //
-        
-        CommandContext context = new CommandContext() {
-            final Variables vars = new VariablesImpl(ShellImpl.this.getVariables());
 
+        // Setup the command context and pass it to the command instance
+        final Variables vars = new VariablesImpl(getVariables());
+        CommandContext context = new CommandContext() {
             public IO getIO() {
                 return io;
             }
@@ -118,10 +120,9 @@
             }
 
             public CommandDescriptor getCommandDescriptor() {
-                return commandDescriptor;
+                return desc;
             }
         };
-
         command.init(context);
 
         // Setup command timings
@@ -140,10 +141,7 @@
             }
             catch (Exception ignore) {}
 
-            //
-            // HACK: Nuke the child container now
-            //
-
+            // Nuke the child container
             container.removeChildContainer(realmId);
         }
 
@@ -154,7 +152,7 @@
         assert args != null;
         assert args.length > 1;
 
-        log.info("Executing (Object...): {}", Arguments.asString(args));
+        log.info("Executing (Object...): [{}]", Arguments.asString(args));
 
         return execute(String.valueOf(args[0]), Arguments.shift(args));
     }

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/LayoutManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/LayoutManager.java?rev=573681&r1=573680&r2=573681&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/LayoutManager.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/LayoutManager.java Fri Sep  7 12:56:37 2007
@@ -20,6 +20,7 @@
 package org.apache.geronimo.gshell.layout;
 
 import org.apache.geronimo.gshell.layout.model.Layout;
+import org.apache.geronimo.gshell.command.descriptor.CommandDescriptor;
 
 /**
  * Provies the shell with a simple mechanism to organize commands.
@@ -30,9 +31,5 @@
 {
     Layout getLayout();
 
-    //
-    // TODO: Add lookup() command, to find a suitable command to execute from the layout.
-    //       Need to have the Command's context/env passed in to query the current location
-    //       as well as any additional search path muck
-    //
+    CommandDescriptor find(String path);
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/LayoutManagerImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/LayoutManagerImpl.java?rev=573681&r1=573680&r2=573681&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/LayoutManagerImpl.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/LayoutManagerImpl.java Fri Sep  7 12:56:37 2007
@@ -29,9 +29,11 @@
 import com.thoughtworks.xstream.annotations.Annotations;
 import com.thoughtworks.xstream.io.xml.DomDriver;
 import org.apache.geronimo.gshell.command.ShellInfo;
+import org.apache.geronimo.gshell.command.descriptor.CommandDescriptor;
 import org.apache.geronimo.gshell.layout.model.Alias;
 import org.apache.geronimo.gshell.layout.model.Command;
 import org.apache.geronimo.gshell.layout.model.Layout;
+import org.apache.geronimo.gshell.plugin.PluginCollector;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
@@ -53,6 +55,9 @@
     @Requirement
     private ShellInfo info;
 
+    @Requirement
+    private PluginCollector pluginCollector;
+
     private Layout layout;
     
     public void initialize() throws InitializationException {
@@ -112,5 +117,23 @@
         }
         
         return layout;
+    }
+
+    public CommandDescriptor find(final String path) {
+        assert path != null;
+
+        log.debug("Searching for command descriptor for path: {}", path);
+
+        //
+        // HACK: For now, assume the path is just the id... should eventually change this
+        //
+
+        for (CommandDescriptor desc : pluginCollector.getCommandDescriptors()) {
+            if (path.equals(desc.getId())) {
+                return desc;
+            }
+        }
+
+        return null;
     }
 }