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/11 15:05:32 UTC
svn commit: r666649 - in /geronimo/gshell/trunk:
gshell-api/src/main/java/org/apache/geronimo/gshell/command/
gshell-buildsupport/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/
gshell-commands/gshell-builtins/src/main/java/o...
Author: jdillon
Date: Wed Jun 11 06:05:31 2008
New Revision: 666649
URL: http://svn.apache.org/viewvc?rev=666649&view=rev
Log:
Rip out the registry, replace with a locator, since only lookup is required (rest is container specific muck)
Drop the Command interface, prep for some refactoring of component names
Added:
geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/container/DefaultCommandContainerLocator.java
- copied, changed from r666536, geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/container/DefaultCommandContainer.java
geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/command/CommandModel.java (contents, props changed)
- copied, changed from r666536, geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/command/Command.java
Removed:
geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Command.java
geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/registry/
geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/command/Command.java
Modified:
geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandContainer.java
geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandContext.java
geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Executable.java
geronimo/gshell/trunk/gshell-buildsupport/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandExtractor.java
geronimo/gshell/trunk/gshell-buildsupport/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandGleaner.java
geronimo/gshell/trunk/gshell-buildsupport/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/DescriptorMojo.java
geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java
geronimo/gshell/trunk/gshell-commands/gshell-command-support/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/container/DefaultCommandContainer.java
geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/plugin/Plugin.java
geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/PluginCollector.java
geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/CommandContainerDescriptor.java
geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/CommandDescriptor.java
geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/PluginDescriptor.java
geronimo/gshell/trunk/gshell-support/gshell-plexus/src/main/java/org/apache/geronimo/gshell/plexus/GShellPlexusContainer.java
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=666649&r1=666648&r2=666649&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 Wed Jun 11 06:05:31 2008
@@ -35,4 +35,13 @@
// TODO: Completor
// TODO: Documentor (for --help and `help <command>`) handling
+
+ //
+ // Locator
+ //
+
+ interface Locator
+ {
+ CommandContainer locate(String id);
+ }
}
\ No newline at end of file
Modified: geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandContext.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandContext.java?rev=666649&r1=666648&r2=666649&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandContext.java (original)
+++ geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandContext.java Wed Jun 11 06:05:31 2008
@@ -33,4 +33,8 @@
Variables getVariables();
CommandInfo getInfo();
+
+ // CommandModel getModel();
+
+ // CommandContainer getContainer();
}
\ No newline at end of file
Modified: geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Executable.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Executable.java?rev=666649&r1=666648&r2=666649&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Executable.java (original)
+++ geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Executable.java Wed Jun 11 06:05:31 2008
@@ -26,8 +26,10 @@
*/
public interface Executable
{
+ @Deprecated
Result SUCCESS = Result.SUCCESS;
+ @Deprecated
Result FAILURE = Result.FAILURE;
// TODO: Change this to ExecutionContext, and/or implement a lifecycle to inject the context, and leave Executable context free?
Modified: geronimo/gshell/trunk/gshell-buildsupport/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandExtractor.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-buildsupport/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandExtractor.java?rev=666649&r1=666648&r2=666649&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-buildsupport/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandExtractor.java (original)
+++ geronimo/gshell/trunk/gshell-buildsupport/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandExtractor.java Wed Jun 11 06:05:31 2008
@@ -27,7 +27,7 @@
import java.util.Collections;
import java.util.List;
-import org.apache.geronimo.gshell.model.command.Command;
+import org.apache.geronimo.gshell.model.command.CommandModel;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.DirectoryScanner;
@@ -35,7 +35,7 @@
import org.slf4j.LoggerFactory;
/**
- * Extracts {@link Command} instances from class files.
+ * Extracts {@link org.apache.geronimo.gshell.model.command.CommandModel} instances from class files.
*
* @version $Id$
*/
@@ -51,7 +51,7 @@
private CommandGleaner gleaner = new CommandGleaner();
- public List<Command> extract(final MavenProject project, final Scope scope) throws Exception {
+ public List<CommandModel> extract(final MavenProject project, final Scope scope) throws Exception {
assert project != null;
assert scope != null;
@@ -117,11 +117,11 @@
return new URLClassLoader(urls, getClass().getClassLoader());
}
- private List<Command> extract(final File classesDir, final ClassLoader cl) throws Exception {
+ private List<CommandModel> extract(final File classesDir, final ClassLoader cl) throws Exception {
assert classesDir != null;
assert cl != null;
- List<Command> descriptors = new ArrayList<Command>();
+ List<CommandModel> descriptors = new ArrayList<CommandModel>();
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(classesDir);
@@ -142,10 +142,10 @@
log.debug("Gleaning from: {}", type);
- Command command = gleaner.glean(type);
+ CommandModel model = gleaner.glean(type);
- if (command != null) {
- descriptors.add(command);
+ if (model != null) {
+ descriptors.add(model);
}
}
catch (VerifyError e) {
Modified: geronimo/gshell/trunk/gshell-buildsupport/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandGleaner.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-buildsupport/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandGleaner.java?rev=666649&r1=666648&r2=666649&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-buildsupport/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandGleaner.java (original)
+++ geronimo/gshell/trunk/gshell-buildsupport/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandGleaner.java Wed Jun 11 06:05:31 2008
@@ -28,7 +28,7 @@
import org.apache.geronimo.gshell.command.annotation.CommandComponent;
import org.apache.geronimo.gshell.model.command.Parameter;
-import org.apache.geronimo.gshell.model.command.Command;
+import org.apache.geronimo.gshell.model.command.CommandModel;
import org.apache.geronimo.gshell.model.command.Requirement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -78,7 +78,7 @@
return buff.toString().trim().toLowerCase();
}
- public Command glean(final Class clazz) throws Exception {
+ public CommandModel glean(final Class clazz) throws Exception {
assert clazz != null;
// Cast to <?> so that we don't have to cast below
@@ -97,28 +97,28 @@
log.debug("Creating descriptor for: {}", type);
- Command command = new Command();
+ CommandModel model = new CommandModel();
- command.setId(anno.id());
+ model.setId(anno.id());
- command.setDescription(filterEmptyAsNull(anno.description()));
+ model.setDescription(filterEmptyAsNull(anno.description()));
- command.setImplementation(type.getName());
+ model.setImplementation(type.getName());
- command.setVersion(filterEmptyAsNull(anno.version()));
+ model.setVersion(filterEmptyAsNull(anno.version()));
for (Class t : getClasses(type)) {
for (Field field : t.getDeclaredFields()) {
Requirement requirement = findRequirement(field);
if (requirement != null) {
- command.addRequirement(requirement);
+ model.addRequirement(requirement);
}
Parameter parameter = findParameter(field);
if (parameter != null) {
- command.addParameter(parameter);
+ model.addParameter(parameter);
}
}
@@ -127,7 +127,7 @@
//
}
- return command;
+ return model;
}
/**
Modified: geronimo/gshell/trunk/gshell-buildsupport/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/DescriptorMojo.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-buildsupport/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/DescriptorMojo.java?rev=666649&r1=666648&r2=666649&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-buildsupport/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/DescriptorMojo.java (original)
+++ geronimo/gshell/trunk/gshell-buildsupport/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/DescriptorMojo.java Wed Jun 11 06:05:31 2008
@@ -25,7 +25,7 @@
import java.util.ArrayList;
import java.util.List;
-import org.apache.geronimo.gshell.model.command.Command;
+import org.apache.geronimo.gshell.model.command.CommandModel;
import org.apache.geronimo.gshell.model.plugin.PluginMarshaller;
import org.apache.geronimo.gshell.model.plugin.Plugin;
import org.apache.maven.artifact.handler.ArtifactHandler;
@@ -93,12 +93,12 @@
assert scope != null;
assert outputFile != null;
- List<Command> commands = new ArrayList<Command>();
+ List<CommandModel> commands = new ArrayList<CommandModel>();
CommandExtractor extractor = new CommandExtractor();
try {
- List<Command> list = extractor.extract(project, scope);
+ List<CommandModel> list = extractor.extract(project, scope);
if (list != null && !list.isEmpty()) {
commands.addAll(list);
@@ -121,8 +121,8 @@
plugin.setVersion(project.getVersion());
plugin.setDescription(project.getDescription());
- for (Command command : commands) {
- plugin.add(command);
+ for (CommandModel model : commands) {
+ plugin.add(model);
}
try {
Modified: geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java?rev=666649&r1=666648&r2=666649&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java (original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java Wed Jun 11 06:05:31 2008
@@ -21,19 +21,17 @@
import org.apache.geronimo.gshell.ansi.Code;
import org.apache.geronimo.gshell.ansi.Renderer;
+import org.apache.geronimo.gshell.application.ApplicationManager;
import org.apache.geronimo.gshell.clp.Argument;
+import org.apache.geronimo.gshell.command.CommandContainer;
+import org.apache.geronimo.gshell.command.CommandSupport;
import org.apache.geronimo.gshell.command.annotation.CommandComponent;
import org.apache.geronimo.gshell.command.annotation.Requirement;
-import org.apache.geronimo.gshell.command.CommandSupport;
-import org.apache.geronimo.gshell.command.Command;
import org.apache.geronimo.gshell.layout.LayoutManager;
import org.apache.geronimo.gshell.model.layout.AliasNode;
-import org.apache.geronimo.gshell.model.layout.GroupNode;
import org.apache.geronimo.gshell.model.layout.CommandNode;
+import org.apache.geronimo.gshell.model.layout.GroupNode;
import org.apache.geronimo.gshell.model.layout.Node;
-import org.apache.geronimo.gshell.registry.CommandRegistry;
-import org.apache.geronimo.gshell.registry.NotRegisteredException;
-import org.apache.geronimo.gshell.application.ApplicationManager;
import org.codehaus.plexus.util.StringUtils;
/**
@@ -49,7 +47,7 @@
private ApplicationManager applicationManager;
@Requirement
- private CommandRegistry commandRegistry;
+ private CommandContainer.Locator commandContainerLocator;
@Requirement
private LayoutManager layoutManager;
@@ -59,11 +57,13 @@
private Renderer renderer = new Renderer();
- public HelpCommand() {
- }
+ public HelpCommand() {}
+
+ public HelpCommand(final CommandContainer.Locator commandContainerLocator, final LayoutManager layoutManager) {
+ assert commandContainerLocator != null;
+ assert layoutManager != null;
- public HelpCommand(CommandRegistry commandRegistry, LayoutManager layoutManager) {
- this.commandRegistry = commandRegistry;
+ this.commandContainerLocator = commandContainerLocator;
this.layoutManager = layoutManager;
}
@@ -105,8 +105,10 @@
CommandNode node = (CommandNode) child;
String name = StringUtils.rightPad(node.getName(), maxNameLen);
- Command command = commandRegistry.lookup(node.getId());
- String desc = command.getDescription();
+ CommandContainer container = commandContainerLocator.locate(node.getId());
+
+ // FIXME:
+ String desc = container.toString(); // command.getDescription();
io.out.print(" ");
io.out.print(renderer.render(Renderer.encode(name, Code.BOLD)));
@@ -118,7 +120,7 @@
else {
io.out.println();
}
- } catch (NotRegisteredException e) {
+ } catch (/*NotRegistered*/Exception e) {
// Ignore those exceptions (command will not be displayed)
}
}
@@ -166,6 +168,11 @@
private void displayCommandHelp(final String path) throws Exception {
assert path != null;
+ // FIXME:
+
+ log.error("Unable to display command specific help for: {}", path);
+
+ /*
Command cmd = commandRegistry.lookup(path);
if (cmd == null) {
@@ -178,5 +185,6 @@
}
io.out.println();
+ */
}
}
Modified: geronimo/gshell/trunk/gshell-commands/gshell-command-support/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-command-support/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java?rev=666649&r1=666648&r2=666649&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-command-support/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java (original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-command-support/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java Wed Jun 11 06:05:31 2008
@@ -24,10 +24,11 @@
import org.slf4j.LoggerFactory;
/**
- * Provides support for {@link Command} implemenations.
+ * Provides support for command implemenations.
*
* @version $Rev$ $Date$
*/
+@Deprecated
public abstract class CommandSupport
implements Executable
{
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=666649&r1=666648&r2=666649&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 Wed Jun 11 06:05:31 2008
@@ -19,31 +19,29 @@
package org.apache.geronimo.gshell;
-import org.apache.geronimo.gshell.command.Command;
+import org.apache.geronimo.gshell.application.ApplicationManager;
+import org.apache.geronimo.gshell.application.DefaultVariables;
+import org.apache.geronimo.gshell.command.CommandContainer;
import org.apache.geronimo.gshell.command.CommandContext;
import org.apache.geronimo.gshell.command.CommandExecutor;
import org.apache.geronimo.gshell.command.CommandInfo;
import org.apache.geronimo.gshell.command.Variables;
import org.apache.geronimo.gshell.common.Arguments;
-import org.apache.geronimo.gshell.common.StopWatch;
import org.apache.geronimo.gshell.common.Notification;
-import org.apache.geronimo.gshell.io.SystemOutputHijacker;
+import org.apache.geronimo.gshell.common.StopWatch;
import org.apache.geronimo.gshell.io.IO;
+import org.apache.geronimo.gshell.io.SystemOutputHijacker;
import org.apache.geronimo.gshell.layout.LayoutManager;
import org.apache.geronimo.gshell.layout.NotFoundException;
import org.apache.geronimo.gshell.model.layout.AliasNode;
import org.apache.geronimo.gshell.model.layout.CommandNode;
import org.apache.geronimo.gshell.model.layout.Node;
-import org.apache.geronimo.gshell.registry.CommandRegistry;
-import org.apache.geronimo.gshell.registry.NotRegisteredException;
import org.apache.geronimo.gshell.shell.Environment;
-import org.apache.geronimo.gshell.application.ApplicationManager;
-import org.apache.geronimo.gshell.application.DefaultVariables;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
-import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+import org.codehaus.plexus.util.IOUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -57,11 +55,11 @@
import java.util.concurrent.atomic.AtomicReference;
/**
- * The default command executor.
+ * The default {@link CommandExecutor} component.
*
* @version $Rev$ $Date$
*/
-@Component(role=CommandExecutor.class, hint="default")
+@Component(role=CommandExecutor.class)
public class DefaultCommandExecutor
implements CommandExecutor, Initializable
{
@@ -74,7 +72,7 @@
private LayoutManager layoutManager;
@Requirement
- private CommandRegistry commandRegistry;
+ private CommandContainer.Locator commandContainerLocator;
@Requirement
private CommandLineBuilder commandLineBuilder;
@@ -83,15 +81,15 @@
public DefaultCommandExecutor() {}
- public DefaultCommandExecutor(final ApplicationManager applicationManager, final LayoutManager layoutManager, final CommandRegistry commandRegistry, final CommandLineBuilder commandLineBuilder) {
+ public DefaultCommandExecutor(final ApplicationManager applicationManager, final LayoutManager layoutManager, final CommandContainer.Locator commandContainerLocator, final CommandLineBuilder commandLineBuilder) {
assert applicationManager != null;
assert layoutManager != null;
- assert commandRegistry != null;
+ assert commandContainerLocator != null;
assert commandLineBuilder != null;
this.applicationManager = applicationManager;
this.layoutManager = layoutManager;
- this.commandRegistry = commandRegistry;
+ this.commandContainerLocator = commandContainerLocator;
this.commandLineBuilder = commandLineBuilder;
}
@@ -235,11 +233,11 @@
final String id = findCommandId(node);
log.debug("Command ID: {}", id);
- final Command command;
+ final CommandContainer container;
try {
- command = commandRegistry.lookup(id);
+ container = commandContainerLocator.locate(id);
}
- catch (NotRegisteredException e) {
+ catch (Exception e) {
throw new NotFoundException(e.getMessage());
}
@@ -304,7 +302,7 @@
Object result;
try {
- result = command.execute(context, args);
+ result = container.execute(context, args);
log.debug("Command completed with result: {}, after: {}", result, watch);
}
Modified: geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/container/DefaultCommandContainer.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/container/DefaultCommandContainer.java?rev=666649&r1=666648&r2=666649&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/container/DefaultCommandContainer.java (original)
+++ geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/container/DefaultCommandContainer.java Wed Jun 11 06:05:31 2008
@@ -19,17 +19,17 @@
package org.apache.geronimo.gshell.container;
-import org.apache.geronimo.gshell.command.CommandContainer;
-import org.apache.geronimo.gshell.command.CommandContext;
-import org.apache.geronimo.gshell.command.Executable;
-import org.apache.geronimo.gshell.command.Command;
-import org.apache.geronimo.gshell.plexus.GShellPlexusContainer;
-import org.apache.geronimo.gshell.common.Arguments;
import org.apache.geronimo.gshell.clp.CommandLineProcessor;
import org.apache.geronimo.gshell.clp.Option;
import org.apache.geronimo.gshell.clp.Printer;
import org.apache.geronimo.gshell.clp.ProcessingException;
+import org.apache.geronimo.gshell.command.CommandContainer;
+import org.apache.geronimo.gshell.command.CommandContext;
+import org.apache.geronimo.gshell.command.CommandInfo;
+import org.apache.geronimo.gshell.command.Executable;
+import org.apache.geronimo.gshell.common.Arguments;
import org.apache.geronimo.gshell.io.IO;
+import org.apache.geronimo.gshell.plexus.GShellPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Configuration;
@@ -94,7 +94,7 @@
// Process command line options/arguments, return if we have been asked to display --help
if (processArguments(context, executable, args)) {
- return Command.SUCCESS;
+ return Executable.Result.SUCCESS;
}
Object result = executable.execute(context, args);
@@ -137,9 +137,10 @@
assert clp != null;
// Use the alias if we have one, else use the command name
- String name = context.getInfo().getAlias();
+ CommandInfo info = context.getInfo();
+ String name = info.getAlias();
if (name == null) {
- name = context.getInfo().getName();
+ name = info.getName();
}
IO io = context.getIo();
Copied: geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/container/DefaultCommandContainerLocator.java (from r666536, geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/container/DefaultCommandContainer.java)
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/container/DefaultCommandContainerLocator.java?p2=geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/container/DefaultCommandContainerLocator.java&p1=geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/container/DefaultCommandContainer.java&r1=666536&r2=666649&rev=666649&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/container/DefaultCommandContainer.java (original)
+++ geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/container/DefaultCommandContainerLocator.java Wed Jun 11 06:05:31 2008
@@ -20,132 +20,59 @@
package org.apache.geronimo.gshell.container;
import org.apache.geronimo.gshell.command.CommandContainer;
-import org.apache.geronimo.gshell.command.CommandContext;
-import org.apache.geronimo.gshell.command.Executable;
-import org.apache.geronimo.gshell.command.Command;
import org.apache.geronimo.gshell.plexus.GShellPlexusContainer;
-import org.apache.geronimo.gshell.common.Arguments;
-import org.apache.geronimo.gshell.clp.CommandLineProcessor;
-import org.apache.geronimo.gshell.clp.Option;
-import org.apache.geronimo.gshell.clp.Printer;
-import org.apache.geronimo.gshell.clp.ProcessingException;
-import org.apache.geronimo.gshell.io.IO;
-import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.component.annotations.Component;
-import org.codehaus.plexus.component.annotations.Configuration;
+import org.codehaus.plexus.component.repository.ComponentDescriptor;
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;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
+import org.codehaus.plexus.PlexusConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * ???
+ * Default implementation of a {@link CommandContainer.Locator} component.
*
* @version $Rev$ $Date$
*/
-@Component(role=CommandContainer.class)
-public class DefaultCommandContainer
- implements CommandContainer, Contextualizable
+@Component(role=CommandContainer.Locator.class)
+public class DefaultCommandContainerLocator
+ implements CommandContainer.Locator, Contextualizable
{
private final Logger log = LoggerFactory.getLogger(getClass());
private GShellPlexusContainer container;
- @Configuration("invalid") // Just to mark what this is used for, since we have to configure a default value
- private String commandId;
-
- // Contextualizable
-
public void contextualize(final Context context) throws ContextException {
assert context != null;
container = (GShellPlexusContainer) context.get(PlexusConstants.PLEXUS_KEY);
assert container != null;
-
+
log.debug("Container: {}", container);
}
- // CommandContainer
+ public CommandContainer locate(final String id) {
+ assert id != null;
- public Executable getExecutable() {
- assert container != null;
+ log.debug("Locating container for ID: {}", id);
- try {
- return container.lookupComponent(Executable.class, commandId);
+ ComponentDescriptor descriptor = container.getComponentDescriptor(CommandContainer.class, id);
+ if (descriptor == null) {
+ // TODO: Throw typed exception
+ throw new RuntimeException("Command container not found for ID: " + id);
}
- 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);
-
- Executable executable = getExecutable();
- // TODO: Handle logging muck
-
- // TODO: Bind context, io and variables
-
- // Process command line options/arguments, return if we have been asked to display --help
- if (processArguments(context, executable, args)) {
- return Command.SUCCESS;
+ CommandContainer commandContainer;
+ try {
+ commandContainer = container.lookupComponent(CommandContainer.class, id);
}
-
- Object result = executable.execute(context, args);
-
- log.trace("Result: {}", result);
-
- return result;
- }
-
- private boolean processArguments(final CommandContext context, final Executable executable, final Object... args) throws ProcessingException {
- assert context != null;
- assert args != null;
-
- CommandLineProcessor clp = new CommandLineProcessor();
- clp.addBean(executable);
-
- // Attach some help context
- HelpSupport help = new HelpSupport();
- clp.addBean(help);
-
- // Process the arguments
- clp.process(Arguments.toStringArray(args));
-
- // Display help if option detected
- if (help.displayHelp) {
- help.display(context, clp);
- return true;
+ catch (ComponentLookupException e) {
+ // TODO: Throw typed exception
+ throw new RuntimeException("Failed to access command containe for ID: " + id, e);
}
- return false;
- }
-
- private static class HelpSupport
- {
- @Option(name="-h", aliases={"--help"}, description="Display this help message", requireOverride=true)
- public boolean displayHelp;
-
- protected void display(final CommandContext context, final CommandLineProcessor clp) {
- assert context != null;
- assert clp != null;
-
- // Use the alias if we have one, else use the command name
- String name = context.getInfo().getAlias();
- if (name == null) {
- name = context.getInfo().getName();
- }
-
- IO io = context.getIo();
- Printer printer = new Printer(clp);
- printer.printUsage(io.out, name);
- io.out.println();
- }
+ return commandContainer;
}
}
\ No newline at end of file
Copied: geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/command/CommandModel.java (from r666536, geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/command/Command.java)
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/command/CommandModel.java?p2=geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/command/CommandModel.java&p1=geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/command/Command.java&r1=666536&r2=666649&rev=666649&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/command/Command.java (original)
+++ geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/command/CommandModel.java Wed Jun 11 06:05:31 2008
@@ -31,7 +31,7 @@
* @version $Rev$ $Date$
*/
@XStreamAlias("command")
-public class Command
+public class CommandModel
extends Element
{
private String id;
Propchange: geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/command/CommandModel.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/command/CommandModel.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/command/CommandModel.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/plugin/Plugin.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/plugin/Plugin.java?rev=666649&r1=666648&r2=666649&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/plugin/Plugin.java (original)
+++ geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/plugin/Plugin.java Wed Jun 11 06:05:31 2008
@@ -20,7 +20,7 @@
package org.apache.geronimo.gshell.model.plugin;
import com.thoughtworks.xstream.annotations.XStreamAlias;
-import org.apache.geronimo.gshell.model.command.Command;
+import org.apache.geronimo.gshell.model.command.CommandModel;
import org.apache.geronimo.gshell.model.common.DescriptorSupport;
import org.apache.geronimo.gshell.model.layout.Layout;
@@ -36,22 +36,22 @@
public class Plugin
extends DescriptorSupport
{
- private List<Command> commands;
+ private List<CommandModel> commands;
private Layout layout;
- public List<Command> commands() {
+ public List<CommandModel> getCommands() {
if (commands == null) {
- commands = new ArrayList<Command>();
+ commands = new ArrayList<CommandModel>();
}
return commands;
}
- public void add(final Command command) {
- assert command != null;
+ public void add(final CommandModel model) {
+ assert model != null;
- commands().add(command);
+ getCommands().add(model);
}
public Layout getLayout() {
Modified: geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/PluginCollector.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/PluginCollector.java?rev=666649&r1=666648&r2=666649&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/PluginCollector.java (original)
+++ geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/PluginCollector.java Wed Jun 11 06:05:31 2008
@@ -19,7 +19,7 @@
package org.apache.geronimo.gshell.plugin;
-import org.apache.geronimo.gshell.model.command.Command;
+import org.apache.geronimo.gshell.model.command.CommandModel;
import org.apache.geronimo.gshell.model.plugin.Plugin;
import org.apache.geronimo.gshell.plugin.descriptor.PluginDescriptor;
import org.codehaus.plexus.component.annotations.Component;
@@ -47,7 +47,7 @@
private final List<PluginDescriptor> descriptors = new ArrayList<PluginDescriptor>();
- private final Map<String,Command> commands = new LinkedHashMap<String,Command>();
+ private final Map<String, CommandModel> commands = new LinkedHashMap<String, CommandModel>();
public String getId() {
return getClass().getSimpleName();
@@ -72,11 +72,11 @@
log.trace("Collecting plugin components for: {}", plugin.getId());
- for (Command command : plugin.commands()) {
- log.debug("Found command: {}", command.getId());
- log.trace("Command model: {}", command);
+ for (CommandModel model : plugin.getCommands()) {
+ log.debug("Found command: {}", model.getId());
+ log.trace("Command model: {}", model);
- commands.put(command.getId(), command);
+ commands.put(model.getId(), model);
}
descriptors.add(descriptor);
@@ -86,11 +86,11 @@
return descriptors;
}
- public Map<String, Command> getCommands() {
+ public Map<String, CommandModel> getCommands() {
return commands;
}
- public Command getCommand(final String id) {
+ public CommandModel getCommand(final String id) {
assert id != null;
return commands.get(id);
Modified: geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/CommandContainerDescriptor.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/CommandContainerDescriptor.java?rev=666649&r1=666648&r2=666649&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/CommandContainerDescriptor.java (original)
+++ geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/CommandContainerDescriptor.java Wed Jun 11 06:05:31 2008
@@ -22,7 +22,7 @@
import org.apache.geronimo.gshell.command.CommandContainer;
import org.apache.geronimo.gshell.common.tostring.ReflectionToStringBuilder;
import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
-import org.apache.geronimo.gshell.model.command.Command;
+import org.apache.geronimo.gshell.model.command.CommandModel;
import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
/**
@@ -33,27 +33,27 @@
public class CommandContainerDescriptor
extends ComponentDescriptorSupport
{
- private final Command command;
+ private final CommandModel model;
- public CommandContainerDescriptor(final Command command) {
- assert command != null;
+ public CommandContainerDescriptor(final CommandModel model) {
+ assert model != null;
- this.command = command;
+ this.model = model;
setRole(CommandContainer.class);
- setRoleHint(command.getId());
+ setRoleHint(model.getId());
setImplementation("org.apache.geronimo.gshell.container.DefaultCommandContainer"); // Avoid dependency on gshell-core
- setVersion(command.getVersion());
+ setVersion(model.getVersion());
setIsolatedRealm(false);
setInstantiationStrategy("singleton");
XmlPlexusConfiguration config = new XmlPlexusConfiguration("configuration");
- config.addChild(new XmlPlexusConfiguration("commandId", command.getId()));
+ config.addChild(new XmlPlexusConfiguration("commandId", model.getId()));
setConfiguration(config);
}
- public Command getCommand() {
- return command;
+ public CommandModel getCommand() {
+ return model;
}
public String toString() {
Modified: geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/CommandDescriptor.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/CommandDescriptor.java?rev=666649&r1=666648&r2=666649&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/CommandDescriptor.java (original)
+++ geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/CommandDescriptor.java Wed Jun 11 06:05:31 2008
@@ -21,7 +21,7 @@
import org.apache.geronimo.gshell.common.tostring.ReflectionToStringBuilder;
import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
-import org.apache.geronimo.gshell.model.command.Command;
+import org.apache.geronimo.gshell.model.command.CommandModel;
import org.apache.geronimo.gshell.model.command.Parameter;
import org.apache.geronimo.gshell.model.command.Requirement;
import org.apache.geronimo.gshell.command.Executable;
@@ -36,40 +36,40 @@
public class CommandDescriptor
extends ComponentDescriptorSupport
{
- private final Command command;
+ private final CommandModel model;
- public CommandDescriptor(final Command command) {
- assert command != null;
+ public CommandDescriptor(final CommandModel model) {
+ assert model != null;
- this.command = command;
+ this.model = model;
- setDescription(command.getDescription());
+ setDescription(model.getDescription());
setRole(Executable.class);
- setRoleHint(command.getId());
- setImplementation(command.getImplementation());
- setVersion(command.getVersion());
+ setRoleHint(model.getId());
+ setImplementation(model.getImplementation());
+ setVersion(model.getVersion());
setIsolatedRealm(false);
setInstantiationStrategy("per-lookup");
- if (command.hasParameters()) {
+ if (model.hasParameters()) {
XmlPlexusConfiguration root = new XmlPlexusConfiguration("configuration");
- for (Parameter param : command.getParameters()) {
+ for (Parameter param : model.getParameters()) {
root.addChild(new XmlPlexusConfiguration(param.getName(), param.getValue()));
}
setConfiguration(root);
}
- if (command.hasRequirements()) {
- for (Requirement requirement : command.getRequirements()) {
+ if (model.hasRequirements()) {
+ for (Requirement requirement : model.getRequirements()) {
addRequirement(translate(requirement));
}
}
}
- public Command getCommand() {
- return command;
+ public CommandModel getCommand() {
+ return model;
}
private ComponentRequirement translate(final Requirement source) {
Modified: geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/PluginDescriptor.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/PluginDescriptor.java?rev=666649&r1=666648&r2=666649&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/PluginDescriptor.java (original)
+++ geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/PluginDescriptor.java Wed Jun 11 06:05:31 2008
@@ -21,7 +21,7 @@
import org.apache.geronimo.gshell.common.tostring.ReflectionToStringBuilder;
import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
-import org.apache.geronimo.gshell.model.command.Command;
+import org.apache.geronimo.gshell.model.command.CommandModel;
import org.apache.geronimo.gshell.model.plugin.Plugin;
import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
import org.codehaus.plexus.component.repository.ComponentDescriptor;
@@ -44,16 +44,16 @@
setId(plugin.getId());
setIsolatedRealm(false);
- for (Command command : plugin.commands()) {
- addCommand(command);
+ for (CommandModel model : plugin.getCommands()) {
+ addCommand(model);
}
}
- private void addCommand(final Command command) {
- assert command != null;
+ private void addCommand(final CommandModel model) {
+ assert model != null;
- addComponentDescriptor(new CommandContainerDescriptor(command));
- addComponentDescriptor(new CommandDescriptor(command));
+ addComponentDescriptor(new CommandContainerDescriptor(model));
+ addComponentDescriptor(new CommandDescriptor(model));
}
public void addComponentDescriptor(final ComponentDescriptor descriptor) {
Modified: geronimo/gshell/trunk/gshell-support/gshell-plexus/src/main/java/org/apache/geronimo/gshell/plexus/GShellPlexusContainer.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-plexus/src/main/java/org/apache/geronimo/gshell/plexus/GShellPlexusContainer.java?rev=666649&r1=666648&r2=666649&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-plexus/src/main/java/org/apache/geronimo/gshell/plexus/GShellPlexusContainer.java (original)
+++ geronimo/gshell/trunk/gshell-support/gshell-plexus/src/main/java/org/apache/geronimo/gshell/plexus/GShellPlexusContainer.java Wed Jun 11 06:05:31 2008
@@ -27,6 +27,7 @@
import org.codehaus.plexus.DuplicateChildContainerException;
import org.codehaus.plexus.classworlds.ClassWorld;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.codehaus.plexus.component.repository.ComponentDescriptor;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
/**
@@ -112,4 +113,11 @@
//
// TODO: lookupComponentList, lookupComponentMap, createChildContainer
//
+
+ public ComponentDescriptor getComponentDescriptor(final Class role, final String hint) {
+ assert role != null;
+ assert hint != null;
+
+ return getComponentDescriptor(role.getName(), hint);
+ }
}