geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r701826 - in /geronimo/gshell/trunk: gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/ gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/meta/ gshell-wisdom/gshell-wis...
Date Sun, 05 Oct 2008 16:40:40 GMT
Author: jdillon
Date: Sun Oct  5 09:40:40 2008
New Revision: 701826

URL: http://svn.apache.org/viewvc?rev=701826&view=rev
Log:
Hook up the CommandResolverImpl.resolveCommands() to use meta:/commands
Hook up the HelpAction to resolve commands for listing from meta:/commands

Modified:
    geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpAction.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/meta/MetaDataInstaller.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImpl.java

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=701826&r1=701825&r2=701826&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
Sun Oct  5 09:40:40 2008
@@ -27,10 +27,10 @@
 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.CommandRegistry;
-import org.apache.geronimo.gshell.registry.NoSuchCommandException;
 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.codehaus.plexus.util.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -49,7 +49,7 @@
     private final Logger log = LoggerFactory.getLogger(getClass());
 
     @Autowired
-    private CommandRegistry commandRegistry;
+    private CommandResolver commandResolver;
 
     @Autowired
     private AliasRegistry aliasRegistry;
@@ -67,15 +67,15 @@
         return displayAvailableCommands(context);
     }
 
-    private Object displayCommandManual(final CommandContext context) {
+    private Object displayCommandManual(final CommandContext context) throws Exception {
         assert context != null;
         IO io = context.getIo();
 
         log.debug("Displaying help manual for command: {}", commandName);
 
         try {
-            assert commandRegistry != null;
-            Command command = commandRegistry.getCommand(commandName);
+            assert commandResolver != null;
+            Command command = commandResolver.resolveCommand(context.getVariables(), commandName);
 
             assert command != null;
             command.getDocumenter().renderManual(io.out);
@@ -117,23 +117,22 @@
 
         log.debug("Listing brief help for commands");
 
-        assert commandRegistry != null;
-        Collection<String> names = commandRegistry.getCommandNames();
+        assert commandResolver != null;
+        Collection<Command> commands = commandResolver.resolveCommands(context.getVariables(),
null);
 
         // Determine the maximun name length
         int maxNameLen = 0;
-        for (String name : names) {
-            if (name.length() > maxNameLen) {
-                maxNameLen = name.length();
-            }
+        for (Command command : commands) {
+            int len = command.getDocumenter().getName().length();
+            maxNameLen = Math.max(len, maxNameLen);
         }
 
         io.out.println("Available commands:");
-        for (String name : names) {
-            Command command = commandRegistry.getCommand(name);
+        for (Command command : commands) {
             CommandDocumenter documenter = command.getDocumenter();
 
-            String formattedName = StringUtils.rightPad(name, maxNameLen);
+            // TODO: Use printf
+            String formattedName = StringUtils.rightPad(documenter.getName(), maxNameLen);
             String desc = documenter.getDescription();
 
             io.out.print("  ");

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/meta/MetaDataInstaller.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/meta/MetaDataInstaller.java?rev=701826&r1=701825&r2=701826&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/meta/MetaDataInstaller.java
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/meta/MetaDataInstaller.java
Sun Oct  5 09:40:40 2008
@@ -45,9 +45,5 @@
         metaConfig.addContent("/system/runtime", new RuntimeContent());
         metaConfig.addContent("/system/properties", new SystemPropertiesContent());
         metaConfig.addContent("/system/environment", new SystemEnvironmentContent());
-
-        //
-        // TODO: Add /system/threads
-        //
     }
 }
\ No newline at end of file

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=701826&r1=701825&r2=701826&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
Sun Oct  5 09:40:40 2008
@@ -39,6 +39,8 @@
 
 import java.util.Collection;
 import java.util.Collections;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * {@link CommandResolver} component.
@@ -88,19 +90,19 @@
         }
         else {
             try {
-                FileObject commands = fileSystemAccess.resolveFile("meta:/commands");
-                assert commands.exists();
-                log.debug("Commands base: {}", commands);
-
-                FileObject file = fileSystemAccess.resolveFile(commands, path);
-                log.debug("Command file: {}", file);
-                
+                FileObject base = fileSystemAccess.resolveFile("meta:/commands");
+                assert base.exists();
+
+                FileObject file = fileSystemAccess.resolveFile(base, path);
                 if (file.exists()) {
                     command = (Command) file.getContent().getAttribute("COMMAND");
                 }
                 else {
                     throw new NoSuchCommandException(path);
                 }
+
+                base.close();
+                file.close();
             }
             catch (FileSystemException e) {
                 throw new CommandException(e);
@@ -134,12 +136,34 @@
 
     public Collection<Command> resolveCommands(final Variables variables, final String
path) throws CommandException {
         assert variables != null;
-        assert path != null;
+        // for now path can be null
 
+        log.debug("Resolving commands for path: {}", path);
+        
         //
-        // FIXME:
+        // FIXME: For now ingore path, just return all commands under meta:/commands
         //
         
-        return Collections.emptySet();
+        List<Command> commands = new ArrayList<Command>();
+
+        try {
+            FileObject base = fileSystemAccess.resolveFile("meta:/commands");
+            assert base.exists();
+
+            for (FileObject file : base.getChildren()) {
+                Command command = (Command)file.getContent().getAttribute("COMMAND");
+                commands.add(command);
+            }
+
+            base.close();
+
+        }
+        catch (FileSystemException e) {
+            throw new CommandException(e);
+        }
+
+        log.debug("Resolved {} commands: {}", commands.size(), commands);
+        
+        return commands;
     }
 }



Mime
View raw message