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/06 23:03:22 UTC
svn commit: r573378 - in /geronimo/sandbox/gshell/trunk:
gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/descriptor/
gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/
gshell-commands/gshell-...
Author: jdillon
Date: Thu Sep 6 14:03:21 2007
New Revision: 573378
URL: http://svn.apache.org/viewvc?rev=573378&view=rev
Log:
Build a map of the discovered command descriptors, use the collector to render help
Modified:
geronimo/sandbox/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/descriptor/CommandSetDescriptor.java
geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java
geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/gshell/commands.xml
geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/PluginCollector.java
Modified: geronimo/sandbox/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/descriptor/CommandSetDescriptor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/descriptor/CommandSetDescriptor.java?rev=573378&r1=573377&r2=573378&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/descriptor/CommandSetDescriptor.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/descriptor/CommandSetDescriptor.java Thu Sep 6 14:03:21 2007
@@ -19,6 +19,8 @@
package org.apache.geronimo.gshell.command.descriptor;
+import java.util.List;
+
import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
/**
@@ -55,5 +57,9 @@
assert desc != null;
addComponentDescriptor(desc);
+ }
+
+ public List<CommandDescriptor> getCommandDescriptors() {
+ return getComponents();
}
}
Modified: geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java?rev=573378&r1=573377&r2=573378&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java Thu Sep 6 14:03:21 2007
@@ -19,15 +19,14 @@
package org.apache.geronimo.gshell.commands.builtins;
-import java.util.List;
+import java.util.Collection;
-import org.apache.geronimo.gshell.command.Command;
import org.apache.geronimo.gshell.command.CommandSupport;
-import org.apache.geronimo.gshell.command.descriptor.CommandDescriptor;
import org.apache.geronimo.gshell.command.annotation.CommandComponent;
-import org.codehaus.plexus.PlexusContainer;
+import org.apache.geronimo.gshell.command.descriptor.CommandDescriptor;
+import org.apache.geronimo.gshell.layout.LayoutManager;
+import org.apache.geronimo.gshell.plugin.PluginCollector;
import org.codehaus.plexus.component.annotations.Requirement;
-import org.codehaus.plexus.component.repository.ComponentDescriptor;
/**
* Display help
@@ -39,21 +38,24 @@
extends CommandSupport
{
@Requirement
- private PlexusContainer container;
+ private PluginCollector pluginCollector;
+
+ @Requirement
+ private LayoutManager layoutManager;
protected Object doExecute() throws Exception {
- assert container != null;
+ assert pluginCollector != null;
+ assert layoutManager != null;
io.out.println("Available commands:");
- //noinspection unchecked
- List<CommandDescriptor> list = container.getComponentDescriptorList(Command.class.getName());
+ Collection<CommandDescriptor> commands = pluginCollector.getCommandDescriptors();
//
// TODO: Need to ask the LayoutManager...
//
- for (CommandDescriptor desc : list) {
+ for (CommandDescriptor desc : commands) {
io.out.print(" ");
io.out.print(desc.getId());
io.out.println();
Modified: geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/gshell/commands.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/gshell/commands.xml?rev=573378&r1=573377&r2=573378&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/gshell/commands.xml (original)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/gshell/commands.xml Thu Sep 6 14:03:21 2007
@@ -13,8 +13,12 @@
<implementation>org.apache.geronimo.gshell.commands.builtins.HelpCommand</implementation>
<requirements>
<requirement>
- <role>org.codehaus.plexus.PlexusContainer</role>
- <field-id>container</field-id>
+ <role>org.apache.geronimo.gshell.plugin.PluginCollector</role>
+ <field-id>pluginCollector</field-id>
+ </requirement>
+ <requirement>
+ <role>org.apache.geronimo.gshell.layout.LayoutManager</role>
+ <field-id>layoutManager</field-id>
</requirement>
</requirements>
</command>
Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/PluginCollector.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/PluginCollector.java?rev=573378&r1=573377&r2=573378&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/PluginCollector.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/PluginCollector.java Thu Sep 6 14:03:21 2007
@@ -19,11 +19,16 @@
package org.apache.geronimo.gshell.plugin;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.geronimo.gshell.command.descriptor.CommandDescriptor;
+import org.apache.geronimo.gshell.command.descriptor.CommandSetDescriptor;
import org.codehaus.plexus.component.annotations.Component;
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.component.repository.ComponentDescriptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,7 +44,9 @@
public static final String ID = "gshell-plugin-collector";
private final Logger log = LoggerFactory.getLogger(getClass());
-
+
+ private Map<String,CommandDescriptor> commandDescriptors = new HashMap<String,CommandDescriptor>();
+
public String getId() {
return ID;
}
@@ -49,14 +56,24 @@
ComponentSetDescriptor setDescriptor = event.getComponentSetDescriptor();
- for (Object obj : setDescriptor.getComponents()) {
- ComponentDescriptor componentDescriptor = (ComponentDescriptor)obj;
+ if (setDescriptor instanceof CommandSetDescriptor) {
+ CommandSetDescriptor commands = (CommandSetDescriptor) setDescriptor;
- //
- // TODO: Do something useful here... for now just log what we have found
- //
-
- log.debug("Component discovered: {}", componentDescriptor.getHumanReadableKey());
+ for (CommandDescriptor desc : commands.getCommandDescriptors()) {
+ String id = desc.getId();
+
+ if (commandDescriptors.containsKey(id)) {
+ log.error("Ignoring duplicate command id: {}", id);
+ }
+ else {
+ log.debug("Command discovered; id: {}", id);
+ commandDescriptors.put(id, desc);
+ }
+ }
}
+ }
+
+ public Collection<CommandDescriptor> getCommandDescriptors() {
+ return commandDescriptors.values();
}
}