geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r661973 - in /geronimo/gshell/trunk: gshell-commands/gshell-command-support/src/ gshell-commands/gshell-command-support/src/main/ gshell-commands/gshell-command-support/src/main/java/ gshell-commands/gshell-command-support/src/main/java/org...
Date Sat, 31 May 2008 08:02:31 GMT
Author: jdillon
Date: Sat May 31 01:02:30 2008
New Revision: 661973

URL: http://svn.apache.org/viewvc?rev=661973&view=rev
Log:
Forgot to commit this

Added:
    geronimo/gshell/trunk/gshell-commands/gshell-command-support/src/
    geronimo/gshell/trunk/gshell-commands/gshell-command-support/src/main/
    geronimo/gshell/trunk/gshell-commands/gshell-command-support/src/main/java/
    geronimo/gshell/trunk/gshell-commands/gshell-command-support/src/main/java/org/
    geronimo/gshell/trunk/gshell-commands/gshell-command-support/src/main/java/org/apache/
    geronimo/gshell/trunk/gshell-commands/gshell-command-support/src/main/java/org/apache/geronimo/
    geronimo/gshell/trunk/gshell-commands/gshell-command-support/src/main/java/org/apache/geronimo/gshell/
    geronimo/gshell/trunk/gshell-commands/gshell-command-support/src/main/java/org/apache/geronimo/gshell/command/
    geronimo/gshell/trunk/gshell-commands/gshell-command-support/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
  (with props)
Modified:
    geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/application/DefaultApplicationManager.java

Added: 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=661973&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-command-support/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
(added)
+++ geronimo/gshell/trunk/gshell-commands/gshell-command-support/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
Sat May 31 01:02:30 2008
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.command;
+
+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.command.annotation.CommandComponent;
+import org.apache.geronimo.gshell.common.Arguments;
+import org.apache.geronimo.gshell.io.IO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Provides support for {@link Command} implemenations.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class CommandSupport
+    implements Command
+{
+    protected Logger log = LoggerFactory.getLogger(getClass());
+
+    protected CommandContext context;
+
+    protected IO io;
+
+    protected Variables variables;
+    
+    @Option(name="-h", aliases={"--help"}, description="Display this help message", requireOverride=true)
+    private boolean displayHelp;
+
+    @Deprecated
+    public String getId() {
+        CommandComponent cmd = getClass().getAnnotation(CommandComponent.class);
+        if (cmd == null) {
+            throw new IllegalStateException("Command id not found");
+        }
+        return cmd.id();
+    }
+
+    @Deprecated
+    public String getDescription() {
+        CommandComponent cmd = getClass().getAnnotation(CommandComponent.class);
+        if (cmd == null) {
+            throw new IllegalStateException("Command description not found");
+        }
+        return cmd.description();
+    }
+
+    public void init(final CommandContext context) {
+        assert context != null;
+
+        this.context = context;
+        this.io = context.getIO();
+        this.variables = context.getVariables();
+
+        // Re-setup logging using our id
+        String id = getId();
+        log = LoggerFactory.getLogger(getClass().getName() + "." + id);
+    }
+
+    public Object execute(final CommandContext context, final Object... args) throws Exception
{
+        assert context != null;
+        assert args != null;
+
+        init(context);
+
+        log.info("Executing w/args: [{}]", Arguments.asString(args));
+
+        CommandLineProcessor clp = new CommandLineProcessor(this);
+        clp.process(Arguments.toStringArray(args));
+
+        // Handle --help/-h automatically for the command
+        if (displayHelp) {
+            //
+            // TODO: Make a special PrinterHandler to abstract this muck from having to process
it by hand
+            //
+            
+            displayHelp(context, clp);
+            
+            return SUCCESS;
+        }
+
+        return doExecute();
+    }
+
+    protected abstract Object doExecute() throws Exception;
+
+    protected void displayHelp(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();
+        }
+
+        //
+        // FIXME: This is uuuuuggggllyyyy
+        //
+
+        Printer printer = new Printer(clp);
+        printer.printUsage(io.out, name);
+        io.out.println();
+    }
+}

Propchange: geronimo/gshell/trunk/gshell-commands/gshell-command-support/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-commands/gshell-command-support/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-commands/gshell-command-support/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/application/DefaultApplicationManager.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/application/DefaultApplicationManager.java?rev=661973&r1=661972&r2=661973&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/application/DefaultApplicationManager.java
(original)
+++ geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/application/DefaultApplicationManager.java
Sat May 31 01:02:30 2008
@@ -20,9 +20,6 @@
 package org.apache.geronimo.gshell.application;
 
 import org.apache.geronimo.gshell.GShell;
-import org.apache.geronimo.gshell.settings.SettingsManager;
-import org.apache.geronimo.gshell.plugin.CommandDiscoverer;
-import org.apache.geronimo.gshell.plugin.CommandCollector;
 import org.apache.geronimo.gshell.artifact.ArtifactManager;
 import org.apache.geronimo.gshell.io.IO;
 import org.apache.geronimo.gshell.model.application.Application;
@@ -30,6 +27,8 @@
 import org.apache.geronimo.gshell.model.common.LocalRepository;
 import org.apache.geronimo.gshell.model.common.RemoteRepository;
 import org.apache.geronimo.gshell.plexus.GShellPlexusContainer;
+import org.apache.geronimo.gshell.plugin.CommandCollector;
+import org.apache.geronimo.gshell.plugin.CommandDiscoverer;
 import org.apache.geronimo.gshell.shell.Environment;
 import org.apache.geronimo.gshell.shell.InteractiveShell;
 import org.apache.geronimo.gshell.shell.ShellInfo;
@@ -37,8 +36,8 @@
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
 import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
-import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
 import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
+import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
 import org.codehaus.plexus.ContainerConfiguration;
 import org.codehaus.plexus.DefaultContainerConfiguration;
 import org.codehaus.plexus.PlexusConstants;
@@ -54,11 +53,11 @@
 
 import java.io.File;
 import java.net.URL;
+import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Set;
-import java.util.HashSet;
 
 /**
  * Default implementation of the {@link ApplicationManager} component.
@@ -74,9 +73,6 @@
     @Requirement
     private ArtifactManager artifactManager;
 
-    @Requirement
-    private SettingsManager settingsManager;
-
     private GShellPlexusContainer parentContainer;
 
     private GShellPlexusContainer container;



Mime
View raw message