geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r703134 - in /geronimo/gshell/trunk: gshell-api/src/main/java/org/apache/geronimo/gshell/registry/ gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/ gshell-support/gshell-spring/src/test/java/org/ap...
Date Thu, 09 Oct 2008 11:13:50 GMT
Author: jdillon
Date: Thu Oct  9 04:13:50 2008
New Revision: 703134

URL: http://svn.apache.org/viewvc?rev=703134&view=rev
Log:
Path stuff is almost working... almost

Added:
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/java/org/apache/geronimo/gshell/wisdom/registry/
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImplTest.java
  (with props)
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/org/apache/geronimo/gshell/wisdom/registry/
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImplTest-context.xml
  (with props)
Modified:
    geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/registry/CommandResolver.java
    geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpAction.java
    geronimo/gshell/trunk/gshell-support/gshell-spring/src/test/java/org/apache/geronimo/gshell/spring/SpringTestSupport.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/AliasCommand.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/GroupCommand.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImpl.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/CommandLineExecutorImpl.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/META-INF/spring/components.xml
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/log4j.xml

Modified: geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/registry/CommandResolver.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/registry/CommandResolver.java?rev=703134&r1=703133&r2=703134&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/registry/CommandResolver.java
(original)
+++ geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/registry/CommandResolver.java
Thu Oct  9 04:13:50 2008
@@ -38,6 +38,10 @@
 
     String GROUP = "gshell.group";
 
+    String COMMANDS_ROOT = "meta:/commands";
+
+    String ALIASES_ROOT = "meta:/aliases";
+
     Command resolveCommand(String name, Variables variables) throws CommandException;
 
     Collection<Command> resolveCommands(String name, Variables variables) throws CommandException;

Modified: geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpAction.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpAction.java?rev=703134&r1=703133&r2=703134&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpAction.java
(original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpAction.java
Thu Oct  9 04:13:50 2008
@@ -27,10 +27,7 @@
 import org.apache.geronimo.gshell.command.CommandContext;
 import org.apache.geronimo.gshell.command.CommandDocumenter;
 import org.apache.geronimo.gshell.io.IO;
-import org.apache.geronimo.gshell.registry.AliasRegistry;
 import org.apache.geronimo.gshell.registry.CommandResolver;
-import org.apache.geronimo.gshell.registry.NoSuchAliasException;
-import org.apache.geronimo.gshell.registry.NoSuchCommandException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -50,80 +47,43 @@
     @Autowired
     private CommandResolver commandResolver;
 
-    @Autowired
-    private AliasRegistry aliasRegistry;
-
-    //
-    // TODO: Rename to path or name
-    //
-    
     @Argument
     private String commandName;
 
     public Object execute(final CommandContext context) throws Exception {
         assert context != null;
-
-        //
-        // FIXME: Resolve commands first based on path, if there is one match, then display
manual, else display brief listing
-        //
-        
-        if (commandName != null) {
-            return displayCommandManual(context);
-        }
-
-        return displayAvailableCommands(context);
-    }
-
-    private Object displayCommandManual(final CommandContext context) throws Exception {
-        assert context != null;
         IO io = context.getIo();
 
-        log.debug("Displaying help manual for command: {}", commandName);
+        Collection<Command> commands = commandResolver.resolveCommands(commandName,
context.getVariables());
 
-        try {
-            assert commandResolver != null;
-            Command command = commandResolver.resolveCommand(commandName, context.getVariables());
+        if (commands.isEmpty()) {
+            io.out.print("Command ");
+            io.out.print(Renderer.encode(commandName, Code.BOLD));
+            io.out.println(" not found.");
+
+            io.out.print("Try ");
+            io.out.print(Renderer.encode("help", Code.BOLD));
+            io.out.println(" for a list of available commands.");
 
-            assert command != null;
+            return Result.FAILURE;
+        }
+        else if (commands.size() == 1) {
+            Command command = commands.iterator().next();
             command.getDocumenter().renderManual(io.out);
-
+            
             return Result.SUCCESS;
         }
-        catch (NoSuchCommandException e) {
-            try {
-                assert aliasRegistry != null;
-                String alias = aliasRegistry.getAlias(commandName);
-                
-                io.out.print("Command ");
-                io.out.print(Renderer.encode(commandName, Code.BOLD));
-                io.out.print(" is an alias to: ");
-                io.out.println(Renderer.encode(alias, Code.BOLD));
-
-                return Result.SUCCESS;
-            }
-            catch (NoSuchAliasException e1) {
-                io.out.print("Command ");
-                io.out.print(Renderer.encode(commandName, Code.BOLD));
-                io.out.println(" not found.");
-
-                io.out.print("Try ");
-                io.out.print(Renderer.encode("help", Code.BOLD));
-                io.out.println(" for a list of available commands.");
-
-                return Result.FAILURE;
-            }
+        else {
+            return displayAvailableCommands(context, commands);
         }
     }
 
-    private Object displayAvailableCommands(final CommandContext context) throws Exception
{
+    private Object displayAvailableCommands(final CommandContext context, final Collection<Command>
commands) throws Exception {
         assert context != null;
-        IO io = context.getIo();
+        assert commands != null;
 
         log.debug("Listing brief help for commands");
 
-        assert commandResolver != null;
-        Collection<Command> commands = commandResolver.resolveCommands(null, context.getVariables());
-        
         // Determine the maximun name length
         int maxNameLen = 0;
         for (Command command : commands) {
@@ -131,6 +91,7 @@
             maxNameLen = Math.max(len, maxNameLen);
         }
 
+        IO io = context.getIo();
         io.out.println("Available commands:");
         for (Command command : commands) {
             CommandDocumenter documenter = command.getDocumenter();

Modified: geronimo/gshell/trunk/gshell-support/gshell-spring/src/test/java/org/apache/geronimo/gshell/spring/SpringTestSupport.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-spring/src/test/java/org/apache/geronimo/gshell/spring/SpringTestSupport.java?rev=703134&r1=703133&r2=703134&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-spring/src/test/java/org/apache/geronimo/gshell/spring/SpringTestSupport.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-spring/src/test/java/org/apache/geronimo/gshell/spring/SpringTestSupport.java
Thu Oct  9 04:13:50 2008
@@ -52,6 +52,10 @@
         return "classpath:" + getClass().getName().replace('.', '/') + "-context.xml";
     }
 
+    protected String getDefaultComponentsConfigLocation() {
+        return "classpath*:META-INF/spring/components.xml";
+    }
+    
     protected String[] getConfigLocations() {
         return new String[] {
             getDefaultConfigLocation()

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/AliasCommand.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/AliasCommand.java?rev=703134&r1=703133&r2=703134&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/AliasCommand.java
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/AliasCommand.java
Thu Oct  9 04:13:50 2008
@@ -28,6 +28,7 @@
 import org.apache.geronimo.gshell.i18n.ResourceBundleMessageSource;
 import org.apache.geronimo.gshell.io.IO;
 import org.apache.geronimo.gshell.shell.ShellContext;
+import org.springframework.beans.factory.annotation.Autowired;
 
 import java.util.Iterator;
 import java.util.List;
@@ -40,21 +41,19 @@
 public class AliasCommand
     extends CommandSupport
 {
-    // @Autowired
-    private final CommandLineExecutor executor;
+    @Autowired
+    private CommandLineExecutor executor;
 
-    private final String name;
+    private String name;
 
-    private final String alias;
+    private String alias;
 
-    public AliasCommand(final String name, final String alias, final CommandLineExecutor
executor) {
-        assert name != null;
-        assert alias != null;
-        assert executor != null;
+    public AliasCommand(final String name, final String alias) {
+        // name could be null
+        // alias could be null
 
         this.name = name;
         this.alias = alias;
-        this.executor = executor;
 
         setAction(new AliasCommandAction());
         setDocumenter(new AliasCommandDocumenter());
@@ -62,6 +61,29 @@
         setMessages(new AliasCommandMessageSource());
     }
 
+    public String getName() {
+        if (name == null) {
+            throw new IllegalStateException("Missing property: name");
+        }
+        return name;
+    }
+
+    public void setName(final String name) {
+        this.name = name;
+    }
+
+    public String getAlias() {
+        return alias;
+    }
+
+    public void setAlias(final String alias) {
+        if (alias == null) {
+            throw new IllegalStateException("Missing property: alias");
+        }
+
+        this.alias = alias;
+    }
+
     @Override
     protected void prepareAction(final ShellContext context, final Object[] args) {
         // HACK: Reset state for proper appendArgs muck
@@ -92,7 +114,7 @@
             };
 
             StringBuilder buff = new StringBuilder();
-            buff.append(alias);
+            buff.append(getAlias());
 
             // If we have args to append, then do it
             if (appendArgs != null && !appendArgs.isEmpty()) {
@@ -130,12 +152,12 @@
     {
         @Override
         public String getName() {
-            return name;
+            return AliasCommand.this.getName();
         }
 
         @Override
         public String getDescription() {
-            return getMessages().format(COMMAND_DESCRIPTION, alias);
+            return getMessages().format(COMMAND_DESCRIPTION, getAlias());
         }
     }
 

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/GroupCommand.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/GroupCommand.java?rev=703134&r1=703133&r2=703134&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/GroupCommand.java
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/GroupCommand.java
Thu Oct  9 04:13:50 2008
@@ -20,13 +20,11 @@
 package org.apache.geronimo.gshell.wisdom.command;
 
 import org.apache.commons.vfs.FileObject;
-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.i18n.MessageSource;
 import org.apache.geronimo.gshell.i18n.ResourceBundleMessageSource;
-
-import java.util.List;
+import org.apache.geronimo.gshell.registry.CommandResolver;
 
 /**
  * Group {@link org.apache.geronimo.gshell.command.Command} component.
@@ -36,11 +34,11 @@
 public class GroupCommand
     extends CommandSupport
 {
-    private final FileObject file;
+    private FileObject file;
 
     public GroupCommand(final FileObject file) {
-        assert file != null;
-
+        // file could be null
+        
         this.file = file;
 
         setAction(new GroupCommandAction());
@@ -49,21 +47,35 @@
         setMessages(new GroupCommandMessageSource());
     }
 
+    public GroupCommand() {
+        this(null);
+    }
+
+    public FileObject getFile() {
+        if (file == null) {
+            throw new IllegalStateException("Missing property: file");
+        }
+        return file;
+    }
+
+    public void setFile(final FileObject file) {
+        this.file = file;
+    }
+
     /**
      * Action to set the gshell group.
      */
     private class GroupCommandAction
         implements CommandAction
     {
-        @Argument
-        private List<String> appendArgs = null;
-
         public Object execute(final CommandContext context) throws Exception {
             assert context != null;
 
+            FileObject file = getFile();
+
             log.debug("Changing to group: {}", file);
             
-            context.getVariables().parent().set("gshell.group", file);
+            context.getVariables().parent().set(CommandResolver.GROUP, file);
 
             return Result.SUCCESS;
         }
@@ -77,12 +89,12 @@
     {
         @Override
         public String getName() {
-            return file.getName().getBaseName();
+            return getFile().getName().getBaseName();
         }
 
         @Override
         public String getDescription() {
-            return getMessages().format(COMMAND_DESCRIPTION, file.getName().getBaseName());
+            return getMessages().format(COMMAND_DESCRIPTION, getFile().getName().getBaseName());
         }
     }
 

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImpl.java?rev=703134&r1=703133&r2=703134&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImpl.java
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImpl.java
Thu Oct  9 04:13:50 2008
@@ -19,27 +19,23 @@
 
 package org.apache.geronimo.gshell.wisdom.registry;
 
+import org.apache.commons.vfs.FileContent;
 import org.apache.commons.vfs.FileObject;
 import org.apache.commons.vfs.FileSystemException;
 import org.apache.geronimo.gshell.command.Command;
 import org.apache.geronimo.gshell.command.CommandException;
 import org.apache.geronimo.gshell.command.Variables;
-import org.apache.geronimo.gshell.commandline.CommandLineExecutor;
-import org.apache.geronimo.gshell.registry.AliasRegistry;
 import org.apache.geronimo.gshell.registry.CommandResolver;
-import org.apache.geronimo.gshell.registry.NoSuchAliasException;
 import org.apache.geronimo.gshell.registry.NoSuchCommandException;
 import org.apache.geronimo.gshell.spring.BeanContainer;
 import org.apache.geronimo.gshell.spring.BeanContainerAware;
 import org.apache.geronimo.gshell.vfs.FileSystemAccess;
-import org.apache.geronimo.gshell.vfs.FileObjects;
-import org.apache.geronimo.gshell.wisdom.command.AliasCommand;
+import org.apache.geronimo.gshell.vfs.provider.meta.MetaFileName;
 import org.apache.geronimo.gshell.wisdom.command.GroupCommand;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 
-import javax.annotation.PostConstruct;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
@@ -55,26 +51,11 @@
     private final Logger log = LoggerFactory.getLogger(getClass());
 
     @Autowired
-    private AliasRegistry aliasRegistry;
-
-    @Autowired
     private FileSystemAccess fileSystemAccess;
 
-    @Autowired
-    private CommandLineExecutor executor;
-
-    private BeanContainer container;
-
     private FileObject commandsDirectory;
 
-    private FileObject aliasesDirectory;
-
-    @PostConstruct
-    public void init() throws Exception {
-        assert fileSystemAccess != null;
-        commandsDirectory = fileSystemAccess.resolveFile(null, "meta:/commands");
-        aliasesDirectory = fileSystemAccess.resolveFile(null, "meta:/aliases");
-    }
+    private BeanContainer container;
 
     public void setBeanContainer(final BeanContainer container) {
         assert container != null;
@@ -88,51 +69,164 @@
     //       *.gsh script, which under the covers will translate into 'source *.gsh' (or
really
     //       should be 'shell *.gsh' once we have a sub-shell command.
     //
-    
-    public Command resolveCommand(final Variables vars, final String path) throws CommandException
{
-        assert vars != null;
-        assert path != null;
 
-        log.debug("Resolving command for path: {}", path);
+    public Command resolveCommand(final String name, final Variables variables) throws CommandException
{
+        assert name != null;
+        assert variables != null;
+
+        log.debug("Resolving command name: {}", name);
+
+        Command command = null;
+        
+        try {
+            FileObject file = resolveCommandFile(name, variables);
 
-        //
-        // FIXME: For now just ask for the named stuff, eventually need a better path parser
and lookup thingy
-        //
-
-        //
-        // FIXME: Handle "/" to get to commandsDirectory.  Handle avoiding ../ leading to
group dir set to meta:/ (should never go up past meta:/commands)
-        //
-                
-        Command command = findAliasCommand(path);
+            if (file != null) {
+                command = createCommand(file);
+            }
+        }
+        catch (FileSystemException e) {
+            log.warn("Unable to resolve command for name: " + name, e);
+        }
 
         if (command == null) {
-            try {
-                FileObject dir = getGroupDirectory(vars);
-                FileObject file = fileSystemAccess.resolveFile(dir, path);
-                
-                if (file.exists()) {
-                    command = (Command) file.getContent().getAttribute("COMMAND");
-
-                    // Dynamically create group commands
-                    if (command == null && file.getType().hasChildren()) {
-                        command = createGroupCommand(file);
-                        file.getContent().setAttribute("COMMAND", command);
+            throw new NoSuchCommandException(name);
+        }
+
+        log.debug("Resolved command: {}", command);
+
+        return command;
+    }
+
+    private FileObject resolveCommandFile(final String name, final Variables variables) throws
FileSystemException {
+        assert name != null;
+        assert variables != null;
+
+        log.debug("Resolving command file: {}", name);
+
+        // Special handling for root
+        if (name.equals("/")) {
+            return getCommandsDirectory();
+        }
+        
+        String[] searchPath = getSearchPath(variables);
+
+        log.debug("Search path: {}", searchPath);
+
+        FileObject groupDir = getGroupDirectory(variables);
+
+        log.debug("Group dir: {}", groupDir);
+
+        FileObject file = null;
+
+        for (String pathElement : searchPath) {
+            log.debug("Resolving file; name={}, pathElement={}", name, pathElement);
+
+            FileObject dir = fileSystemAccess.resolveFile(null, groupDir.getName().getURI()
+ "/" + pathElement);
+
+            log.debug("Dir: {}", dir);
+
+            FileObject tmp = fileSystemAccess.resolveFile(dir, name);
+
+            log.debug("File: {}", tmp);
+
+            if (tmp.exists()) {
+                file = tmp;
+                break;
+            }
+        }
+
+        if (file != null) {
+            log.debug("Resolved file: {}", file);
+
+            // Make sure whatever file we resolved is actually a meta file
+            if (!isMetaFile(file)) {
+                log.warn("Command name '{}' did not resolve to a meta-file; found: {}", name,
file);
+                return null;
+            }
+
+            // Make sure we found a file in the meta:/commands tree
+            if (!file.getName().getPath().startsWith("/commands")) {
+                log.warn("Command name '{}' did not resolve under " + COMMANDS_ROOT + ";
found: {}", name, file);
+                return null;
+            }
+        }
+
+        return file;
+    }
+
+    private String[] getSearchPath(final Variables vars) {
+        assert vars != null;
+
+        Object tmp = vars.get(PATH);
+
+        if (tmp instanceof String) {
+            return ((String)tmp).split(PATH_SEPARATOR);
+        }
+        else if (tmp != null) {
+            log.error("Invalid type for variable '" + PATH + "'; expected String; found:
" + tmp.getClass());
+        }
+
+        // Return the default
+        return new String[] { "/" };
+    }
+
+    public Collection<Command> resolveCommands(String name, Variables variables) throws
CommandException {
+        // name may be null
+        assert variables != null;
+
+        if (name == null) {
+            name = "";
+        }
+        
+        log.debug("Resolving commands for name: {}", name);
+
+        List<Command> commands = new ArrayList<Command>();
+
+        try {
+            FileObject file = resolveCommandFile(name, variables);
+
+            log.debug("Resolved (for commands): {}", file);
+
+            if (file != null && file.exists()) {
+                if (file.getType().hasChildren()) {
+                    for (FileObject child : file.getChildren()) {
+                        Command command = createCommand(child);
+                        commands.add(command);
                     }
                 }
                 else {
-                    throw new NoSuchCommandException(path);
+                    Command command = createCommand(file);
+                    commands.add(command);
                 }
-
-                FileObjects.close(file);
             }
-            catch (FileSystemException e) {
-                throw new CommandException(e);
+        }
+        catch (FileSystemException e) {
+            log.warn("Failed to resolve commands for name: " + name, e);
+        }
+
+        log.debug("Resolved {} commands", commands.size());
+        if (log.isTraceEnabled()) {
+            for (Command command : commands) {
+                log.trace("    {}", command);
             }
         }
 
-        log.debug("Resolved command: {} -> {}", path, command);
-        
-        return command;
+        return commands;
+    }
+
+    private boolean isMetaFile(final FileObject file) {
+        assert file != null;
+
+        return MetaFileName.SCHEME.equals(file.getName().getScheme());
+    }
+
+    private FileObject getCommandsDirectory() throws FileSystemException {
+        if (commandsDirectory == null) {
+            commandsDirectory = fileSystemAccess.resolveFile(null, COMMANDS_ROOT);
+        }
+
+        return commandsDirectory;
     }
 
     private FileObject getGroupDirectory(final Variables vars) throws FileSystemException
{
@@ -140,11 +234,10 @@
 
         FileObject dir;
 
-        Object tmp = vars.get("gshell.group");
+        Object tmp = vars.get(GROUP);
 
         if (tmp == null) {
-            assert commandsDirectory != null;
-            dir = commandsDirectory;
+            dir = getCommandsDirectory();
         }
         else if (tmp instanceof String) {
             log.trace("Resolving group directory from string: {}", tmp);
@@ -155,113 +248,76 @@
         }
         else {
             // Complain, then use the default so commands still work
-            log.error("Invalid type for variable 'gshell.group'; expected String or FileObject;
found: " + tmp.getClass());
-            assert commandsDirectory != null;
-            dir = commandsDirectory;
+            log.error("Invalid type for variable '" + GROUP + "'; expected String or FileObject;
found: " + tmp.getClass());
+            dir = getCommandsDirectory();
         }
-        
-        assert dir != null;
+
+        if (!isMetaFile(dir)) {
+            log.error("Command group did not resolve to a meta-file: {}", dir);
+            dir = getCommandsDirectory();
+        }
+
         return dir;
     }
 
+    private Command createCommand(final FileObject file) throws FileSystemException, CommandException
{
+        assert file != null;
 
-    private Command findAliasCommand(final String path) throws CommandException {
-        assert path != null;
+        log.debug("Creating command for file: {}", file);
 
         Command command = null;
 
-        try {
-            assert aliasesDirectory != null;
-            FileObject file = fileSystemAccess.resolveFile(aliasesDirectory, path);
-            if (file.exists()) {
-                command = (Command)file.getContent().getAttribute("COMMAND");
-
-                // Dynamically create alias commands
-                if (command == null) {
-                    command = createAliasCommand(file);
-                    file.getContent().setAttribute("COMMAND", command);
+        if (file.exists()) {
+            FileContent content = file.getContent();
+            command = (Command)content.getAttribute("COMMAND");
+
+            if (command == null) {
+                if (file.getType().hasChildren()) {
+                    command = createGroupCommand(file);
+                    content.setAttribute("COMMAND", command);
                 }
+
+                // TODO: Try to construct AliasCommand?
             }
         }
-        catch (FileSystemException e) {
-            throw new CommandException(e);
-        }
-        catch (NoSuchAliasException e) {
-            // ignore
+
+        if (command == null) {
+            throw new CommandException("Unable to create command for file: " + file.getName());
         }
 
         return command;
     }
 
-    private Command createAliasCommand(final FileObject file) throws FileSystemException,
NoSuchAliasException {
+    /*
+    private Command createAliasCommand(final FileObject file) throws FileSystemException
{
         assert file != null;
 
         String name = file.getName().getBaseName();
-        log.debug("Creating command for alias: {}", name);
-
-        assert aliasRegistry != null;
-        String alias = aliasRegistry.getAlias(name);
-        AliasCommand command = new AliasCommand(name, alias, executor);
-
-        //
-        // FIXME: Have to inject the container because we are not wiring ^^^, and because
its support muck needs some crap
-        //        probably need to use a prototype here
-        //
-
-        assert container != null;
-        command.setBeanContainer(container);
-
-        return command;
-    }
-
-    public Collection<Command> resolveCommands(final Variables variables, final String
path) throws CommandException {
-        assert variables != null;
-        // for now path can be null
-
-        log.debug("Resolving commands for path: {}", path);
-        
-        //
-        // FIXME: For now ingore path, just return all commands under meta:/commands
-        //
-        
-        List<Command> commands = new ArrayList<Command>();
 
-        try {
-            for (FileObject file : commandsDirectory.getChildren()) {
-                Command command = (Command)file.getContent().getAttribute("COMMAND");
+        log.debug("Creating command for alias: {}", name);
 
-                // Dynamically create group commands
-                if (command == null && file.getType().hasChildren()) {
-                    command = createGroupCommand(file);
-                }
+        AliasCommand command = container.getBean(AliasCommand.class);
 
-                commands.add(command);
-            }
-        }
-        catch (FileSystemException e) {
-            throw new CommandException(e);
+        String alias = (String) file.getContent().getAttribute("ALIAS");
+        if (alias == null) {
+            throw new IllegalStateException("Alias meta-file does not contain 'ALIAS' attribute:
" + file);
         }
 
-        log.debug("Resolved {} commands: {}", commands.size(), commands);
-        
-        return commands;
+        command.setName(name);
+        command.setAlias(alias);
+
+        return command;
     }
+    */
 
     private Command createGroupCommand(final FileObject file) throws FileSystemException
{
         assert file != null;
 
         log.debug("Creating command for group: {}", file);
 
-        GroupCommand command = new GroupCommand(file);
-
-        //
-        // FIXME: Have to inject the container because we are not wiring ^^^, and because
its support muck needs some crap
-        //        probably need to use a prototype here
-        //
-
-        assert container != null;
-        command.setBeanContainer(container);
-
+        GroupCommand command = container.getBean(GroupCommand.class);
+        command.setFile(file);
+        
         return command;
     }
 }

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/CommandLineExecutorImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/CommandLineExecutorImpl.java?rev=703134&r1=703133&r2=703134&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/CommandLineExecutorImpl.java
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/CommandLineExecutorImpl.java
Thu Oct  9 04:13:50 2008
@@ -213,9 +213,9 @@
         log.debug("Executing");
 
         // Locate the command
-        Variables variables = context.getVariables();
-        Command command = commandResolver.resolveCommand(variables, path);
-
+        Variables vars = context.getVariables();
+        Command command = commandResolver.resolveCommand(path, vars);
+        
         // Hijack the system streams in the current thread's context
         IO io = context.getIo();
         SystemOutputHijacker.register(io.outputStream, io.errorStream);

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/META-INF/spring/components.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/META-INF/spring/components.xml?rev=703134&r1=703133&r2=703134&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/META-INF/spring/components.xml
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/META-INF/spring/components.xml
Thu Oct  9 04:13:50 2008
@@ -37,8 +37,12 @@
 
     <bean id="commandMetaMapper" class="org.apache.geronimo.gshell.wisdom.registry.CommandMetaMapper"/>
 
-    <bean id="commandResolver" class="org.apache.geronimo.gshell.wisdom.registry.CommandResolverImpl"
depends-on="metaFileProviderConfigurer"/>
-    
+    <bean id="commandResolver" class="org.apache.geronimo.gshell.wisdom.registry.CommandResolverImpl"/>
+
+    <bean class="org.apache.geronimo.gshell.wisdom.command.AliasCommand" scope="prototype"/>
+
+    <bean class="org.apache.geronimo.gshell.wisdom.command.GroupCommand" scope="prototype"/>
+
     <bean id="commandLineBuilder" class="org.apache.geronimo.gshell.wisdom.shell.CommandLineBuilderImpl"/>
 
     <bean id="commandLineExecutor" class="org.apache.geronimo.gshell.wisdom.shell.CommandLineExecutorImpl"/>

Added: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImplTest.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImplTest.java?rev=703134&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImplTest.java
(added)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImplTest.java
Thu Oct  9 04:13:50 2008
@@ -0,0 +1,202 @@
+/*
+ * 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.wisdom.registry;
+
+import org.apache.geronimo.gshell.command.Command;
+import org.apache.geronimo.gshell.command.Variables;
+import org.apache.geronimo.gshell.spring.SpringTestSupport;
+import org.apache.geronimo.gshell.application.plugin.Plugin;
+import org.apache.geronimo.gshell.registry.NoSuchCommandException;
+import org.apache.geronimo.gshell.registry.CommandResolver;
+import org.apache.geronimo.gshell.wisdom.command.GroupCommand;
+
+import java.util.Collection;
+
+/**
+ * Unit tests for the {@link CommandResolverImpl} class.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CommandResolverImplTest
+    extends SpringTestSupport
+{
+    private CommandResolverImpl resolver;
+
+    private Variables vars;
+
+    @Override
+    protected String[] getConfigLocations() {
+        return new String[] {
+            getDefaultComponentsConfigLocation(),
+            getDefaultConfigLocation()
+        };
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        vars = new Variables();
+
+        resolver = getBean(CommandResolverImpl.class);
+        assertNotNull(resolver);
+
+        Plugin plugin = getBean(Plugin.class);
+        plugin.activate();
+    }
+
+    protected void tearDown() throws Exception {
+        vars = null;
+        resolver = null;
+        
+        super.tearDown();
+    }
+
+    public void testResolveRoot() throws Exception {
+        Command command = resolver.resolveCommand("/", vars);
+        assertNotNull(command);
+        assertTrue(command instanceof GroupCommand);
+
+        GroupCommand group = (GroupCommand)command;
+        assertEquals("meta:/commands", group.getFile().getName().getURI());
+    }
+
+    public void testResolveDefaultPath() throws Exception {
+        Command command;
+
+        command = resolver.resolveCommand("test1", vars);
+        assertNotNull(command);
+
+        command = resolver.resolveCommand("test2", vars);
+        assertNotNull(command);
+
+        command = resolver.resolveCommand("group1/child1", vars);
+        assertNotNull(command);
+
+        command = resolver.resolveCommand("group2/child2", vars);
+        assertNotNull(command);
+
+        try {
+            resolver.resolveCommand("no-such-command", vars);
+            fail();
+        }
+        catch (NoSuchCommandException ignore) {
+            // expected
+        }
+    }
+
+    public void testResolveCustomPath() throws Exception {
+        vars.set(CommandResolver.PATH, "/:/group1");
+
+        Command command;
+
+        command = resolver.resolveCommand("test1", vars);
+        assertNotNull(command);
+
+        command = resolver.resolveCommand("test2", vars);
+        assertNotNull(command);
+
+        command = resolver.resolveCommand("child1", vars);
+        assertNotNull(command);
+
+        command = resolver.resolveCommand("child2", vars);
+        assertNotNull(command);
+
+        try {
+            resolver.resolveCommand("no-such-command", vars);
+            fail();
+        }
+        catch (NoSuchCommandException ignore) {
+            // expected
+        }
+    }
+
+    public void testResolveCustomPathInGroup() throws Exception {
+        vars.set(CommandResolver.GROUP, "meta:/commands/group1");
+        vars.set(CommandResolver.PATH, "/");
+
+        Command command;
+
+        command = resolver.resolveCommand("test1", vars);
+        assertNotNull(command);
+
+        command = resolver.resolveCommand("test2", vars);
+        assertNotNull(command);
+
+        command = resolver.resolveCommand("child1", vars);
+        assertNotNull(command);
+
+        command = resolver.resolveCommand("child2", vars);
+        assertNotNull(command);
+
+        try {
+            resolver.resolveCommand("no-such-command", vars);
+            fail();
+        }
+        catch (NoSuchCommandException ignore) {
+            // expected
+        }
+    }
+
+    public void testResolveInGroup() throws Exception {
+        vars.set(CommandResolver.GROUP, "meta:/commands/group1");
+
+        Command command;
+
+        command = resolver.resolveCommand("child1", vars);
+        assertNotNull(command);
+
+        command = resolver.resolveCommand("child2", vars);
+        assertNotNull(command);
+
+        command = resolver.resolveCommand("../test1", vars);
+        assertNotNull(command);
+    }
+
+    public void testResolveRelativeChecks() throws Exception {
+       try {
+            resolver.resolveCommand("../foo", vars);
+            fail();
+        }
+        catch (NoSuchCommandException ignore) {
+            // expected
+        }
+
+        try {
+            resolver.resolveCommand("../../bar", vars);
+            fail();
+        }
+        catch (NoSuchCommandException ignore) {
+            // expected
+        }
+        
+        vars.set(CommandResolver.GROUP, "meta:/commands/a/b/c/d");
+
+        Command command;
+
+        command = resolver.resolveCommand("../../../../test1", vars);
+        assertNotNull(command);
+    }
+
+    public void testResolveCommands() throws Exception {
+        Collection<Command> commands = resolver.resolveCommands(null, vars);
+        assertNotNull(commands);
+        assertEquals(6, commands.size());
+    }
+}
\ No newline at end of file

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImplTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImplTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/log4j.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/log4j.xml?rev=703134&r1=703133&r2=703134&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/log4j.xml (original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/log4j.xml Thu
Oct  9 04:13:50 2008
@@ -39,14 +39,22 @@
         <level value="WARN"/>
     </logger>
 
+    <logger name="org.springframework.beans.factory.support">
+        <level value="WARN"/>
+    </logger>
+
     <logger name="org.apache.geronimo.gshell.spring">
         <level value="INFO"/>
     </logger>
 
-    <logger name="org.apache.commons.vfs.cache">
+    <logger name="org.apache.geronimo.gshell.vfs.config">
         <level value="INFO"/>
     </logger>
 
+    <logger name="org.apache.commons.vfs">
+        <level value="WARN"/>
+    </logger>
+
     <root>
         <level value="DEBUG"/>
         <appender-ref ref="CONSOLE"/>

Added: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImplTest-context.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImplTest-context.xml?rev=703134&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImplTest-context.xml
(added)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImplTest-context.xml
Thu Oct  9 04:13:50 2008
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+
+<!-- $Rev$ $Date$ -->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:gshell="http://gshell.org/schema/wisdom-gshell"
+       xsi:schemaLocation="
+            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+            http://gshell.org/schema/wisdom-gshell http://gshell.org/schema/wisdom-gshell/wisdom-gshell.xsd">
+
+    <gshell:plugin name="test-plugin">
+        <gshell:command-bundle name="default">
+            <gshell:command name="test1">
+                <gshell:action class="org.apache.geronimo.gshell.wisdom.config.DummyAction"/>
+            </gshell:command>
+
+            <gshell:command name="test2">
+                <gshell:action class="org.apache.geronimo.gshell.wisdom.config.DummyAction"/>
+            </gshell:command>
+
+            <gshell:command name="test3">
+                <gshell:action class="org.apache.geronimo.gshell.wisdom.config.DummyAction"/>
+            </gshell:command>
+
+            <gshell:command name="group1/child1">
+                <gshell:action class="org.apache.geronimo.gshell.wisdom.config.DummyAction"/>
+            </gshell:command>
+
+            <gshell:command name="group1/child2">
+                <gshell:action class="org.apache.geronimo.gshell.wisdom.config.DummyAction"/>
+            </gshell:command>
+
+            <gshell:command name="group1/child3">
+                <gshell:action class="org.apache.geronimo.gshell.wisdom.config.DummyAction"/>
+            </gshell:command>
+
+            <gshell:command name="group2/child1">
+                <gshell:action class="org.apache.geronimo.gshell.wisdom.config.DummyAction"/>
+            </gshell:command>
+
+            <gshell:command name="group2/child2">
+                <gshell:action class="org.apache.geronimo.gshell.wisdom.config.DummyAction"/>
+            </gshell:command>
+
+            <gshell:command name="group2/child3">
+                <gshell:action class="org.apache.geronimo.gshell.wisdom.config.DummyAction"/>
+            </gshell:command>
+
+            <gshell:command name="a/b/c/d/e/f/g">
+                <gshell:action class="org.apache.geronimo.gshell.wisdom.config.DummyAction"/>
+            </gshell:command>
+        </gshell:command-bundle>
+    </gshell:plugin>
+
+</beans>
\ No newline at end of file

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImplTest-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImplTest-context.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImplTest-context.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message