geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r699707 - in /geronimo/gshell/trunk: gshell-api/src/main/java/org/apache/geronimo/gshell/command/ gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/ gshell-wisdom/gshell-wisdom-core/src/main/java/org/a...
Date Sat, 27 Sep 2008 18:12:58 GMT
Author: jdillon
Date: Sat Sep 27 11:12:57 2008
New Revision: 699707

URL: http://svn.apache.org/viewvc?rev=699707&view=rev
Log:
Rename completor stuff to completer
Re-implement some of the jline "completors"

Added:
    geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/
    geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/Completer.java
  (with props)
    geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/MuxCompleter.java
  (with props)
    geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/StringsCompleter.java
  (with props)
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/
      - copied from r699660, geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completor/
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/AliasNameCompleter.java
  (with props)
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/CommandNameCompleter.java
  (with props)
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/CommandsCompleter.java
  (with props)
Removed:
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/AliasNameCompletor.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/CommandNameCompletor.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completor/
Modified:
    geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandCompleter.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ShellImpl.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/META-INF/spring/components.xml

Modified: geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandCompleter.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandCompleter.java?rev=699707&r1=699706&r2=699707&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandCompleter.java
(original)
+++ geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandCompleter.java
Sat Sep 27 11:12:57 2008
@@ -28,5 +28,9 @@
  */
 public interface CommandCompleter
 {
+    //
+    // FIXME: Use Completer here from gshell-console instead
+    //
+
     Completor createCompletor();
 }
\ No newline at end of file

Added: geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/Completer.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/Completer.java?rev=699707&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/Completer.java
(added)
+++ geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/Completer.java
Sat Sep 27 11:12:57 2008
@@ -0,0 +1,33 @@
+/*
+ * 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.console.completer;
+
+import jline.Completor;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Completer
+    extends Completor
+{
+    // int complete(String buffer, int cursor, List<String> candidates);
+}
\ No newline at end of file

Propchange: geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/Completer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/Completer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/Completer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/MuxCompleter.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/MuxCompleter.java?rev=699707&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/MuxCompleter.java
(added)
+++ geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/MuxCompleter.java
Sat Sep 27 11:12:57 2008
@@ -0,0 +1,97 @@
+/*
+ * 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.console.completer;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Completer which contains multipule completers and aggregates them together.
+ *
+ * @version $Rev$ $Date$
+ */
+public class MuxCompleter
+    implements Completer
+{
+    private final List<Completer> completers = new ArrayList<Completer>();
+
+    public MuxCompleter() {}
+
+    public MuxCompleter(final Collection<Completer> completers) {
+        assert completers != null;
+
+        getCompleters().addAll(completers);
+    }
+
+    public Collection<Completer> getCompleters() {
+        return completers;
+    }
+
+    public int complete(final String buffer, final int cursor, final List candidates) {
+        // buffer could be null
+        assert candidates != null;
+
+        List<Completion> completions = new ArrayList<Completion>(completers.size());
+
+        // Run each completer, saving its completion results
+        int max = -1;
+        for (Completer completer : completers) {
+            Completion completion = new Completion(candidates);
+            completion.complete(completer, buffer, cursor);
+
+            // Compute the max cursor position
+            max = Math.max(max, completion.cursor);
+
+            completions.add(completion);
+        }
+
+        // Append candiates from completions which have the same cursor position as max
+        for (Completion completion : completions) {
+            if (completion.cursor == max) {
+                // noinspection unchecked
+                candidates.addAll(completion.candidates);
+            }
+        }
+
+        return max;
+    }
+
+    private class Completion
+    {
+        public final List<String> candidates;
+
+        public int cursor;
+
+        public Completion(final List candidates) {
+            assert candidates != null;
+
+            // noinspection unchecked
+            this.candidates = new LinkedList<String>(candidates);
+        }
+
+        public void complete(final Completer completer, final String buffer, final int cursor)
{
+            assert completer != null;
+
+            this.cursor = completer.complete(buffer, cursor, candidates);
+        }
+    }
+}

Propchange: geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/MuxCompleter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/MuxCompleter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/MuxCompleter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/StringsCompleter.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/StringsCompleter.java?rev=699707&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/StringsCompleter.java
(added)
+++ geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/StringsCompleter.java
Sat Sep 27 11:12:57 2008
@@ -0,0 +1,73 @@
+/*
+ * 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.console.completer;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+/**
+ * Completer for a set of strings.
+ *
+ * @version $Rev$ $Date$
+ */
+public class StringsCompleter
+    implements Completer
+{
+    private final SortedSet<String> strings = new TreeSet<String>();
+
+    public StringsCompleter() {}
+
+    public StringsCompleter(final Collection<String> strings) {
+        assert strings != null;
+
+        getStrings().addAll(strings);
+    }
+
+    public Collection<String> getStrings() {
+        return strings;
+    }
+
+    public int complete(final String buffer, final int cursor, final List candidates) {
+        // buffer could be null
+        assert candidates != null;
+
+        String start = (buffer == null) ? "" : buffer;
+
+        SortedSet<String> matches = strings.tailSet(start);
+
+        for (String match : matches) {
+            if (!match.startsWith(start)) {
+                break;
+            }
+
+            // noinspection unchecked
+            candidates.add(match);
+        }
+
+        if (candidates.size() == 1) {
+            // noinspection unchecked
+            candidates.set(0, candidates.get(0) + " ");
+        }
+
+        return candidates.isEmpty() ? -1 : 0;
+    }
+}
\ No newline at end of file

Propchange: geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/StringsCompleter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/StringsCompleter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/completer/StringsCompleter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ShellImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ShellImpl.java?rev=699707&r1=699706&r2=699707&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ShellImpl.java
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ShellImpl.java
Sat Sep 27 11:12:57 2008
@@ -19,10 +19,9 @@
 
 package org.apache.geronimo.gshell.wisdom.shell;
 
-import jline.Completor;
 import jline.History;
-import jline.MultiCompletor;
 import org.apache.geronimo.gshell.ansi.Renderer;
+import org.apache.geronimo.gshell.ansi.Code;
 import org.apache.geronimo.gshell.application.Application;
 import org.apache.geronimo.gshell.command.Variables;
 import org.apache.geronimo.gshell.commandline.CommandLineExecutor;
@@ -30,6 +29,8 @@
 import org.apache.geronimo.gshell.console.Console.ErrorHandler;
 import org.apache.geronimo.gshell.console.Console.Prompter;
 import org.apache.geronimo.gshell.console.JLineConsole;
+import org.apache.geronimo.gshell.console.completer.Completer;
+import org.apache.geronimo.gshell.console.completer.MuxCompleter;
 import org.apache.geronimo.gshell.event.Event;
 import org.apache.geronimo.gshell.event.EventListener;
 import org.apache.geronimo.gshell.event.EventManager;
@@ -75,7 +76,7 @@
     @Autowired
     private History history;
 
-    private List<Completor> completors;
+    private List<Completer> completers;
 
     private ShellContext context;
 
@@ -85,10 +86,10 @@
 
     private ErrorHandler errorHandler;
 
-    public void setCompletors(final List<Completor> completors) {
-        assert completors != null;
+    public void setCompleters(final List<Completer> completers) {
+        assert completers != null;
 
-        this.completors = completors;
+        this.completers = completers;
     }
 
     public ShellContext getContext() {
@@ -198,10 +199,10 @@
         console.setErrorHandler(getErrorHandler());
         console.setHistory(history);
 
-        // Attach completors if there are any
-        if (completors != null) {
-            // Have to use MultiCompletor here to get the completion list to update properly
-            console.addCompleter(new MultiCompletor(completors));
+        // Attach completers if there are any
+        if (completers != null) {
+            // Have to use mux here to get the completion list to update properly
+            console.addCompleter(new MuxCompleter(completers));
         }
 
         // Unless the user wants us to shut up, then display a nice welcome banner
@@ -254,15 +255,22 @@
             public String prompt() {
                 assert shellInfo != null;
 
+                // FIXME: Need to use some sort of format based on branding, for now hardcode
this
                 String userName = shellInfo.getUserName();
                 String hostName = shellInfo.getLocalHost().getHostName();
 
-                //
-                // HACK: There is no path... yet ;-)
-                //
-                String path = "/";
+                // FIXME: Get this from Branding/Application
+                String appName = "gshell";
+
+                StringBuilder buff = new StringBuilder();
+                buff.append(Renderer.encode(userName, Code.BOLD));
+                buff.append("@");
+                buff.append(hostName);
+                buff.append(":");
+                buff.append(Renderer.encode(appName, Code.BOLD));
+                buff.append(">");
 
-                return renderer.render("@|bold " + userName + "|@" + hostName + ":@|bold
" + path + "|> ");
+                return renderer.render(buff.toString());
             }
         };
     }

Added: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/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/shell/completer/AliasNameCompleter.java?rev=699707&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/AliasNameCompleter.java
(added)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/AliasNameCompleter.java
Sat Sep 27 11:12:57 2008
@@ -0,0 +1,82 @@
+/*
+ * 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.shell.completer;
+
+import org.apache.geronimo.gshell.console.completer.Completer;
+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 org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import javax.annotation.PostConstruct;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * {@link Completer} for alias names.
+ *
+ * @version $Rev$ $Date$
+ */
+public class AliasNameCompleter
+    implements Completer
+{
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Autowired
+    private EventManager eventManager;
+
+    @Autowired
+    private AliasRegistry aliasRegistry;
+
+    private final StringsCompleter delegate = new StringsCompleter();
+
+    @PostConstruct
+    public void init() {
+        log.debug("Initializing");
+
+        // 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);
+    }
+}
\ No newline at end of file

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

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/AliasNameCompleter.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/shell/completer/AliasNameCompleter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/CommandNameCompleter.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/CommandNameCompleter.java?rev=699707&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/CommandNameCompleter.java
(added)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/CommandNameCompleter.java
Sat Sep 27 11:12:57 2008
@@ -0,0 +1,82 @@
+/*
+ * 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.shell.completer;
+
+import org.apache.geronimo.gshell.console.completer.Completer;
+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.CommandRegistry;
+import org.apache.geronimo.gshell.wisdom.registry.CommandRegisteredEvent;
+import org.apache.geronimo.gshell.wisdom.registry.CommandRemovedEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import javax.annotation.PostConstruct;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * {@link Completer} for command names.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CommandNameCompleter
+    implements Completer
+{
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Autowired
+    private EventManager eventManager;
+
+    @Autowired
+    private CommandRegistry commandRegistry;
+
+    private final StringsCompleter delegate = new StringsCompleter();
+
+    @PostConstruct
+    public void init() {
+        log.debug("Initializing");
+
+        // Populate the initial list of command names
+        Collection<String> names = commandRegistry.getCommandNames();
+        delegate.getStrings().addAll(names);
+
+        // Register for updates to command registrations
+        eventManager.addListener(new EventListener() {
+            public void onEvent(final Event event) throws Exception {
+                if (event instanceof CommandRegisteredEvent) {
+                    CommandRegisteredEvent targetEvent = (CommandRegisteredEvent)event;
+                    delegate.getStrings().add(targetEvent.getName());
+                }
+                else if (event instanceof CommandRemovedEvent) {
+                    CommandRemovedEvent targetEvent = (CommandRemovedEvent)event;
+                    delegate.getStrings().remove(targetEvent.getName());
+                }
+            }
+        });
+    }
+
+    public int complete(final String buffer, final int cursor, final List candidates) {
+        return delegate.complete(buffer, cursor, candidates);
+    }
+}
\ No newline at end of file

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

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/CommandNameCompleter.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/shell/completer/CommandNameCompleter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/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/shell/completer/CommandsCompleter.java?rev=699707&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/CommandsCompleter.java
(added)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/CommandsCompleter.java
Sat Sep 27 11:12:57 2008
@@ -0,0 +1,80 @@
+/*
+ * 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.shell.completer;
+
+import org.apache.geronimo.gshell.console.completer.Completer;
+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.CommandRegistry;
+import org.apache.geronimo.gshell.wisdom.registry.CommandRegisteredEvent;
+import org.apache.geronimo.gshell.wisdom.registry.CommandRemovedEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import javax.annotation.PostConstruct;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * {@link Completer} for commands.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CommandsCompleter
+    implements Completer
+{
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Autowired
+    private EventManager eventManager;
+
+    @Autowired
+    private CommandRegistry commandRegistry;
+
+    @PostConstruct
+    public void init() {
+        log.debug("Initializing");
+
+        // Populate the initial list of command names
+        Collection<String> names = commandRegistry.getCommandNames();
+        // TODO:
+
+        // Register for updates to command registrations
+        eventManager.addListener(new EventListener() {
+            public void onEvent(final Event event) throws Exception {
+                if (event instanceof CommandRegisteredEvent) {
+                    CommandRegisteredEvent targetEvent = (CommandRegisteredEvent)event;
+                    // TODO:
+                }
+                else if (event instanceof CommandRemovedEvent) {
+                    CommandRemovedEvent targetEvent = (CommandRemovedEvent)event;
+                    // TODO:
+                }
+            }
+        });
+    }
+
+    public int complete(final String buffer, final int cursor, final List candidates) {
+        // TODO:
+        return -1;
+    }
+}
\ No newline at end of file

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

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/CommandsCompleter.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/shell/completer/CommandsCompleter.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=699707&r1=699706&r2=699707&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
Sat Sep 27 11:12:57 2008
@@ -42,13 +42,10 @@
     <bean id="shellInfo" class="org.apache.geronimo.gshell.wisdom.shell.ShellInfoImpl"/>
 
     <bean id="shell" class="org.apache.geronimo.gshell.wisdom.shell.ShellImpl">
-        <property name="completors">
+        <property name="completers">
             <list>
-                <bean class="org.apache.geronimo.gshell.wisdom.shell.completor.CommandNameCompletor"/>
-                <bean class="org.apache.geronimo.gshell.wisdom.shell.completor.AliasNameCompletor"/>
-                <!--
-                TODO: Need to hook up support for Command-specific completors.
-                -->
+                <bean class="org.apache.geronimo.gshell.wisdom.shell.completer.CommandNameCompleter"/>
+                <bean class="org.apache.geronimo.gshell.wisdom.shell.completer.AliasNameCompleter"/>
             </list>
         </property>
     </bean>



Mime
View raw message