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/10/05 12:08:22 UTC

svn commit: r582191 - in /geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin: CommandDiscoverer.java CommandDiscoveryListener.java PlexusCommandWrapper.java

Author: jdillon
Date: Fri Oct  5 03:08:21 2007
New Revision: 582191

URL: http://svn.apache.org/viewvc?rev=582191&view=rev
Log:
Update plexus plugin integration for all the latest changes

Modified:
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandDiscoverer.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandDiscoveryListener.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/PlexusCommandWrapper.java

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandDiscoverer.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandDiscoverer.java?rev=582191&r1=582190&r2=582191&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandDiscoverer.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandDiscoverer.java Fri Oct  5 03:08:21 2007
@@ -21,6 +21,9 @@
 
 import java.io.Reader;
 
+import com.thoughtworks.xstream.core.BaseException;
+import org.apache.geronimo.gshell.descriptor.CommandSetDescriptor;
+import org.apache.geronimo.gshell.plugin.adapter.ComponentSetDescriptorAdapter;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.discovery.AbstractComponentDiscoverer;
 import org.codehaus.plexus.component.discovery.ComponentDiscoverer;
@@ -39,18 +42,26 @@
     extends AbstractComponentDiscoverer
 {
     private final Logger log = LoggerFactory.getLogger(getClass());
-    
-    private final CommandSetDescriptorBuilder builder = new CommandSetDescriptorBuilder();
 
-    public String getComponentDescriptorLocation() {
+    protected String getComponentDescriptorLocation() {
         return "META-INF/gshell/commands.xml";
     }
 
-    public ComponentSetDescriptor createComponentDescriptors(final Reader reader, final String source)
-        throws PlexusConfigurationException
-    {
-        log.debug("Creating components from: {}", source);
-        
-        return builder.build(reader, source);
+    protected ComponentSetDescriptor createComponentDescriptors(final Reader reader, final String source) throws PlexusConfigurationException {
+        assert reader != null;
+        assert source != null;
+
+        log.debug("Loading descriptors from: {}", source);
+
+        try {
+            CommandSetDescriptor commands = CommandSetDescriptor.fromXML(reader);
+
+            log.debug("Loaded command set: {}", commands.getId());
+
+            return new ComponentSetDescriptorAdapter(commands);
+        }
+        catch (BaseException e) {
+            throw new PlexusConfigurationException("Failed to load descriptors from: " + source, e);
+        }
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandDiscoveryListener.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandDiscoveryListener.java?rev=582191&r1=582190&r2=582191&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandDiscoveryListener.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandDiscoveryListener.java Fri Oct  5 03:08:21 2007
@@ -19,16 +19,17 @@
 
 package org.apache.geronimo.gshell.plugin;
 
-import org.apache.geronimo.gshell.command.descriptor.CommandDescriptor;
-import org.apache.geronimo.gshell.command.descriptor.CommandSetDescriptor;
-import org.apache.geronimo.gshell.command.Command;
+import org.apache.geronimo.gshell.descriptor.CommandDescriptor;
+import org.apache.geronimo.gshell.descriptor.CommandSetDescriptor;
+import org.apache.geronimo.gshell.plugin.adapter.ComponentSetDescriptorAdapter;
 import org.apache.geronimo.gshell.registry.CommandRegistry;
+import org.apache.geronimo.gshell.registry.DuplicateRegistrationException;
+import org.codehaus.plexus.PlexusContainer;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
 import org.codehaus.plexus.component.discovery.ComponentDiscoveryEvent;
 import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener;
 import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
-import org.codehaus.plexus.PlexusContainer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -58,13 +59,18 @@
 
         log.trace("Event: {}", event);
 
-        ComponentSetDescriptor set = event.getComponentSetDescriptor();
+        ComponentSetDescriptor components = event.getComponentSetDescriptor();
 
-        if (set instanceof CommandSetDescriptor) {
-            CommandSetDescriptor commands = (CommandSetDescriptor) set;
+        if (components instanceof ComponentSetDescriptorAdapter) {
+            CommandSetDescriptor commands = ((ComponentSetDescriptorAdapter)components).getCommands();
 
-            for (CommandDescriptor descriptor : commands.getCommandDescriptors()) {
-                registry.register(new PlexusCommandWrapper(container, descriptor));
+            for (CommandDescriptor descriptor : commands.getCommands()) {
+                try {
+                    registry.register(new PlexusCommandWrapper(container, descriptor));
+                }
+                catch (DuplicateRegistrationException e) {
+                    log.error("Failed to register command: " + descriptor, e);
+                }
             }
         }
     }

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/PlexusCommandWrapper.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/PlexusCommandWrapper.java?rev=582191&r1=582190&r2=582191&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/PlexusCommandWrapper.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/PlexusCommandWrapper.java Fri Oct  5 03:08:21 2007
@@ -19,28 +19,30 @@
 
 package org.apache.geronimo.gshell.plugin;
 
+import java.util.UUID;
+
 import org.apache.geronimo.gshell.command.Command;
 import org.apache.geronimo.gshell.command.CommandContext;
-import org.apache.geronimo.gshell.command.descriptor.CommandDescriptor;
+import org.apache.geronimo.gshell.descriptor.CommandDescriptor;
 import org.codehaus.plexus.PlexusContainer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.UUID;
-
 /**
- * A command wrapper using the CommandDescriptor
+ * A wrapper for Plexus-based commands.
  *
  * @version $Rev: 581061 $ $Date: 2007-10-01 22:18:31 +0200 (Mon, 01 Oct 2007) $
  */
-public class PlexusCommandWrapper implements Command {
-
+public class PlexusCommandWrapper
+    implements Command
+{
     private Logger log = LoggerFactory.getLogger(getClass());
+
     private CommandDescriptor descriptor;
+
     private PlexusContainer container;
 
-    public PlexusCommandWrapper(PlexusContainer container,
-                                CommandDescriptor descriptor) {
+    public PlexusCommandWrapper(final PlexusContainer container, final CommandDescriptor descriptor) {
         this.container = container;
         this.descriptor = descriptor;
     }
@@ -53,21 +55,26 @@
         return descriptor.getDescription();
     }
 
-    public Object execute(CommandContext context, Object... args) throws Exception {
+    public Object execute(final CommandContext context, final Object... args) throws Exception {
         // Create a new child container for the invocation and lookup the command instance
         String realmId = "gshell:" + UUID.randomUUID();
 
         log.debug("Child container realm: {}", realmId);
 
-        final PlexusContainer childContainer = container.createChildContainer(realmId, container.getContainerRealm());
-        final Command command = (Command) childContainer.lookup(descriptor.getRole(), descriptor.getRoleHint());
+        PlexusContainer childContainer = container.createChildContainer(realmId, container.getContainerRealm());
+
+        Command command = (Command) childContainer.lookup(Command.class, descriptor.getId());
+
+        Object result;
 
         try {
-            return command.execute(context, args);
+            result = command.execute(context, args);
         }
         finally {
             // Nuke the child container
             container.removeChildContainer(realmId);
         }
+
+        return result;
     }
 }