geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r698992 - in /geronimo/gshell/trunk: gshell-api/src/main/java/org/apache/geronimo/gshell/alias/ gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/ gshell-support/gshell-io/src/main/java/org/apache/ge...
Date Thu, 25 Sep 2008 14:56:22 GMT
Author: jdillon
Date: Thu Sep 25 07:56:21 2008
New Revision: 698992

URL: http://svn.apache.org/viewvc?rev=698992&view=rev
Log:
More alias work, still not yet functional

Modified:
    geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/alias/Alias.java
    geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/alias/AliasManager.java
    geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/AliasAction.java
    geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/UnaliasAction.java
    geronimo/gshell/trunk/gshell-support/gshell-io/src/main/java/org/apache/geronimo/gshell/io/IO.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/alias/AliasManagerImpl.java

Modified: geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/alias/Alias.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/alias/Alias.java?rev=698992&r1=698991&r2=698992&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/alias/Alias.java
(original)
+++ geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/alias/Alias.java
Thu Sep 25 07:56:21 2008
@@ -26,4 +26,11 @@
  */
 public interface Alias
 {
+    String getName();
+
+    String getTarget();
+
+    // Command getCommand()
+
+    // boolean isMasking()
 }

Modified: geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/alias/AliasManager.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/alias/AliasManager.java?rev=698992&r1=698991&r2=698992&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/alias/AliasManager.java
(original)
+++ geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/alias/AliasManager.java
Thu Sep 25 07:56:21 2008
@@ -19,11 +19,20 @@
 
 package org.apache.geronimo.gshell.alias;
 
+import java.util.Collection;
+
 /**
- * ???
+ * Component to manage {@link Alias} instances.
  *
  * @version $Rev$ $Date$
  */
 public interface AliasManager
 {
+    Collection<Alias> getAliases();
+
+    boolean isAliasDefined(String name);
+
+    Alias defineAlias(String name, String target);
+
+    void undefineAlias(String name);
 }
\ No newline at end of file

Modified: geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/AliasAction.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/AliasAction.java?rev=698992&r1=698991&r2=698992&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/AliasAction.java
(original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/AliasAction.java
Thu Sep 25 07:56:21 2008
@@ -19,16 +19,19 @@
 
 package org.apache.geronimo.gshell.commands.builtins;
 
+import org.apache.geronimo.gshell.alias.Alias;
+import org.apache.geronimo.gshell.alias.AliasManager;
+import org.apache.geronimo.gshell.clp.Argument;
 import org.apache.geronimo.gshell.command.CommandAction;
 import org.apache.geronimo.gshell.command.CommandContext;
-import org.apache.geronimo.gshell.clp.Argument;
-import org.apache.geronimo.gshell.io.IO;
 import org.apache.geronimo.gshell.i18n.MessageSource;
-import org.apache.geronimo.gshell.alias.AliasManager;
+import org.apache.geronimo.gshell.io.IO;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import java.util.Collection;
+
 /**
  * Define an alias.
  *
@@ -55,8 +58,19 @@
 
         if (name == null) {
             log.debug("Listing defined aliases");
+
+            Collection<Alias> aliases = aliasManager.getAliases();
             
-            // TODO: List aliases
+            if (aliases.isEmpty()) {
+                io.verbose("No aliases have been defined");
+            }
+            else {
+                io.info("Defined aliases:");
+
+                for (Alias alias : aliases) {
+                    io.info("  {}='{}'", alias.getName(), alias.getTarget());
+                }
+            }
         }
         else if (target == null) {
             io.error("Missing argument: {}", messages.getMessage("command.argument.target.token"));
@@ -65,7 +79,9 @@
         else {
             log.debug("Defining alias: {} -> {}", name, target);
 
-            // TODO: Define alias
+            Alias alias = aliasManager.defineAlias(name, target);
+
+            log.debug("Alias: {}", alias);
         }
 
         return Result.SUCCESS;

Modified: geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/UnaliasAction.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/UnaliasAction.java?rev=698992&r1=698991&r2=698992&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/UnaliasAction.java
(original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/UnaliasAction.java
Thu Sep 25 07:56:21 2008
@@ -23,6 +23,7 @@
 import org.apache.geronimo.gshell.command.CommandContext;
 import org.apache.geronimo.gshell.clp.Argument;
 import org.apache.geronimo.gshell.alias.AliasManager;
+import org.apache.geronimo.gshell.io.IO;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -45,10 +46,16 @@
 
     public Object execute(final CommandContext context) throws Exception {
         assert context != null;
+        IO io = context.getIo();
 
         log.debug("Undefining alias: {}", name);
 
-        // TODO:
+        if (!aliasManager.isAliasDefined(name)) {
+            io.error("No alias defined with name: {}", name);
+            return Result.FAILURE;
+        }
+
+        aliasManager.undefineAlias(name);
 
         return Result.SUCCESS;
     }

Modified: geronimo/gshell/trunk/gshell-support/gshell-io/src/main/java/org/apache/geronimo/gshell/io/IO.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-io/src/main/java/org/apache/geronimo/gshell/io/IO.java?rev=698992&r1=698991&r2=698992&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-io/src/main/java/org/apache/geronimo/gshell/io/IO.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-io/src/main/java/org/apache/geronimo/gshell/io/IO.java
Thu Sep 25 07:56:21 2008
@@ -288,6 +288,8 @@
     //
     // Output Helpers
     //
+    // TODO: Hook up a MessageSource to make it even easier to handle i18n via these helpers
+    //
 
     public void debug(final String msg) {
         if (isDebug()) {

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/alias/AliasManagerImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/alias/AliasManagerImpl.java?rev=698992&r1=698991&r2=698992&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/alias/AliasManagerImpl.java
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/alias/AliasManagerImpl.java
Thu Sep 25 07:56:21 2008
@@ -19,15 +19,20 @@
 
 package org.apache.geronimo.gshell.wisdom.alias;
 
-import org.apache.geronimo.gshell.command.CommandResult;
-import org.apache.geronimo.gshell.shell.ShellContext;
-import org.apache.geronimo.gshell.wisdom.command.CommandSupport;
+import org.apache.geronimo.gshell.alias.Alias;
 import org.apache.geronimo.gshell.alias.AliasManager;
+import org.apache.geronimo.gshell.command.CommandRegistry;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
 
 /**
- * Implementation of the {@link AliasManager} component.
+ * {@link AliasManager} component.
  *
  * @version $Rev$ $Date$
  */
@@ -36,5 +41,58 @@
 {
     private final Logger log = LoggerFactory.getLogger(getClass());
 
-    // TODO:
+    @Autowired
+    private CommandRegistry commandRegistry;
+
+    private Map<String,Alias> aliases = new LinkedHashMap<String,Alias>();
+
+    public Collection<Alias> getAliases() {
+        return Collections.unmodifiableCollection(aliases.values());
+    }
+
+    public boolean isAliasDefined(final String name) {
+        assert name != null;
+
+        return aliases.containsKey(name);
+    }
+
+    public Alias defineAlias(final String name, final String target) {
+        assert name != null;
+
+        log.debug("Defining alias: {} -> {}", name, target);
+
+        Alias alias = new Alias() {
+            public String getName() {
+                return name;
+            }
+
+            public String getTarget() {
+                return target;
+            }
+        };
+
+        aliases.put(name, alias);
+
+        // TODO: Register AliasCommand
+
+        // TODO: Fire event?
+
+        return alias;
+    }
+
+    public void undefineAlias(final String name) {
+        assert name != null;
+
+        log.debug("Undefining alias: {}", name);
+
+        Alias alias = aliases.remove(name);
+        if (alias == null) {
+            log.debug("No alias defined; ignoring");
+        }
+        else {
+            // TODO: Unregister AliasCommand
+
+            // TODO: Fire event?
+        }
+    }
 }



Mime
View raw message