geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r706701 - in /geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main: java/org/apache/geronimo/gshell/wisdom/command/ java/org/apache/geronimo/gshell/wisdom/completer/ resources/META-INF/spring/
Date Tue, 21 Oct 2008 18:10:41 GMT
Author: jdillon
Date: Tue Oct 21 11:10:39 2008
New Revision: 706701

URL: http://svn.apache.org/viewvc?rev=706701&view=rev
Log:
Make command completer optional
Add our own NullCompleter, which has a singleton to be used in all cases

Added:
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/completer/NullCompleter.java
  (contents, props changed)
      - copied, changed from r706683, geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/completer/AliasNameCompleter.java
Removed:
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/NullCommandCompleter.java
Modified:
    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/CommandSupport.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/completer/CommandsCompleter.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/META-INF/spring/components.xml

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=706701&r1=706700&r2=706701&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
Tue Oct 21 11:10:39 2008
@@ -54,7 +54,6 @@
 
         setAction(new AliasCommandAction());
         setDocumenter(new AliasCommandDocumenter());
-        setCompleter(new NullCommandCompleter());
         setMessages(new AliasCommandMessageSource());
     }
     

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandSupport.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandSupport.java?rev=706701&r1=706700&r2=706701&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandSupport.java
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandSupport.java
Tue Oct 21 11:10:39 2008
@@ -116,10 +116,7 @@
     }
 
     public CommandCompleter getCompleter() {
-        if (completer == null) {
-            throw new IllegalStateException("Missing required property: completer");
-        }
-        
+        // completer may be null
         return completer;
     }
 
@@ -232,12 +229,7 @@
         // Setup the command action
         try {
             // Process command line options/arguments
-            if (processArguments(io, action, args)) {
-                // Abort if we have been asked to display --help
-                throw new AbortExecutionNotification(new CommandResult.ValueResult(CommandAction.Result.SUCCESS));
-            }
-
-            // TODO: Add preferences processor
+            processArguments(io, action, args);
         }
         catch (Exception e) {
             // Abort if preparation caused a failure
@@ -245,7 +237,7 @@
         }
     }
 
-    protected boolean processArguments(final IO io, final CommandAction action, final Object[]
args) throws Exception {
+    protected void processArguments(final IO io, final CommandAction action, final Object[]
args) throws Exception {
         assert io != null;
         assert action != null;
         assert args != null;
@@ -257,10 +249,6 @@
         CommandLineProcessor clp = new CommandLineProcessor();
         clp.addBean(action);
 
-        // Attach some help context
-        CommandDocumenter documenter = getDocumenter();
-        clp.addBean(documenter);
-
         HelpSupport help = new HelpSupport();
         clp.addBean(help);
 
@@ -271,11 +259,11 @@
         if (help.displayHelp) {
             log.trace("Render command-line usage");
 
+            CommandDocumenter documenter = getDocumenter();
             documenter.renderUsage(io.out);
-            return true;
-        }
 
-        return false;
+            throw new AbortExecutionNotification(new CommandResult.ValueResult(CommandAction.Result.SUCCESS));
+        }
     }
 
     protected CommandResult executeAction(final ShellContext context, final Object[] args)
{

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=706701&r1=706700&r2=706701&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
Tue Oct 21 11:10:39 2008
@@ -42,7 +42,6 @@
         setFile(file);
         setAction(new GroupCommandAction());
         setDocumenter(new GroupCommandDocumenter());
-        setCompleter(new NullCommandCompleter());
         setMessages(new GroupCommandMessageSource());
     }
 
@@ -50,6 +49,10 @@
         this(null);
     }
 
+    //
+    // FIXME: Make this a plain string, hind the mata:/commands stuff
+    //
+    
     public FileObject getFile() {
         if (file == null) {
             throw new IllegalStateException("Missing property: file");

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/completer/CommandsCompleter.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/completer/CommandsCompleter.java?rev=706701&r1=706700&r2=706701&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/completer/CommandsCompleter.java
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/completer/CommandsCompleter.java
Tue Oct 21 11:10:39 2008
@@ -21,8 +21,8 @@
 
 import jline.ArgumentCompletor;
 import jline.Completor;
-import jline.NullCompletor;
 import org.apache.geronimo.gshell.command.Command;
+import org.apache.geronimo.gshell.command.CommandCompleter;
 import org.apache.geronimo.gshell.console.completer.AggregateCompleter;
 import org.apache.geronimo.gshell.console.completer.StringsCompleter;
 import org.apache.geronimo.gshell.event.Event;
@@ -102,19 +102,20 @@
         children.add(new StringsCompleter(new String[] { name }));
 
         // Then attach any command specific completers
-        Collection<Completor> commandCompleters = command.getCompleter().createCompletors();
-        if (commandCompleters != null) {
-            for (Completor completer : commandCompleters) {
-                if (completer != null) {
-                    children.add(completer);
-                }
-                else {
-                    children.add(new NullCompletor());
+        CommandCompleter commandCompleter = command.getCompleter();
+        if (commandCompleter != null) {
+            Collection<Completor> commandCompleters = commandCompleter.createCompletors();
+            if (commandCompleters != null) {
+                for (Completor completer : commandCompleters) {
+                    children.add(completer != null ? completer : NullCompleter.INSTANCE);
                 }
             }
+            else {
+                children.add(NullCompleter.INSTANCE);
+            }
         }
         else {
-            children.add(new NullCompletor());
+            children.add(NullCompleter.INSTANCE);
         }
 
         // Setup the root completer for the command

Copied: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/completer/NullCompleter.java
(from r706683, geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/completer/AliasNameCompleter.java)
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/completer/NullCompleter.java?p2=geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/completer/NullCompleter.java&p1=geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/completer/AliasNameCompleter.java&r1=706683&r2=706701&rev=706701&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/completer/AliasNameCompleter.java
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/completer/NullCompleter.java
Tue Oct 21 11:10:39 2008
@@ -19,64 +19,15 @@
 
 package org.apache.geronimo.gshell.wisdom.completer;
 
-import jline.Completor;
-import org.apache.geronimo.gshell.console.completer.StringsCompleter;
-import org.apache.geronimo.gshell.event.Event;
-import org.apache.geronimo.gshell.event.EventListener;
-import org.apache.geronimo.gshell.event.EventManager;
-import org.apache.geronimo.gshell.registry.AliasRegistry;
-import org.apache.geronimo.gshell.wisdom.registry.AliasRegisteredEvent;
-import org.apache.geronimo.gshell.wisdom.registry.AliasRemovedEvent;
-
-import javax.annotation.PostConstruct;
-import java.util.Collection;
-import java.util.List;
-
 /**
- * {@link Completor} for alias names.
+ * Null or terminal completer.
  *
  * Keeps up to date automatically by handling alias-related events.
  *
  * @version $Rev$ $Date$
  */
-public class AliasNameCompleter
-    implements Completor
+public final class NullCompleter
+    extends jline.NullCompletor
 {
-    private final EventManager eventManager;
-
-    private final AliasRegistry aliasRegistry;
-
-    private final StringsCompleter delegate = new StringsCompleter();
-
-    public AliasNameCompleter(final EventManager eventManager, final AliasRegistry aliasRegistry)
{
-        assert eventManager != null;
-        this.eventManager = eventManager;
-        assert aliasRegistry != null;
-        this.aliasRegistry = aliasRegistry;
-    }
-
-    @PostConstruct
-    public void init() {
-        // Populate the initial list of alias names
-        Collection<String> names = aliasRegistry.getAliasNames();
-        delegate.getStrings().addAll(names);
-
-        // Register for updates to alias registrations
-        eventManager.addListener(new EventListener() {
-            public void onEvent(final Event event) throws Exception {
-                if (event instanceof AliasRegisteredEvent) {
-                    AliasRegisteredEvent targetEvent = (AliasRegisteredEvent)event;
-                    delegate.getStrings().add(targetEvent.getName());
-                }
-                else if (event instanceof AliasRemovedEvent) {
-                    AliasRemovedEvent targetEvent = (AliasRemovedEvent)event;
-                    delegate.getStrings().remove(targetEvent.getName());
-                }
-            }
-        });
-    }
-
-    public int complete(final String buffer, final int cursor, final List candidates) {
-        return delegate.complete(buffer, cursor, candidates);
-    }
+    public static final NullCompleter INSTANCE = new NullCompleter();
 }
\ No newline at end of file

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/completer/NullCompleter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/completer/NullCompleter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/completer/NullCompleter.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/completer/NullCompleter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=706701&r1=706700&r2=706701&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
Tue Oct 21 11:10:39 2008
@@ -284,15 +284,11 @@
         </property>
     </bean>
 
-    <bean id="defaultCommandCompleter" class="org.apache.geronimo.gshell.wisdom.command.NullCommandCompleter"
lazy-init="true"/>
-
     <bean id="statelessCommandTemplate" class="org.apache.geronimo.gshell.wisdom.command.StatelessCommand"
abstract="true">
         <property name="documenter">
             <bean class="org.apache.geronimo.gshell.wisdom.command.MessageSourceCommandDocumenter"/>
         </property>
 
-        <property name="completer" ref="defaultCommandCompleter"/>
-
         <property name="messages">
             <bean class="org.apache.geronimo.gshell.wisdom.command.CommandMessageSource"/>
         </property>
@@ -303,8 +299,6 @@
             <bean class="org.apache.geronimo.gshell.wisdom.command.MessageSourceCommandDocumenter"/>
         </property>
 
-        <property name="completer" ref="defaultCommandCompleter"/>
-
         <property name="messages">
             <bean class="org.apache.geronimo.gshell.wisdom.command.CommandMessageSource"/>
         </property>



Mime
View raw message