You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2008/09/27 16:53:56 UTC
svn commit: r699660 - in /geronimo/gshell/trunk:
gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/
gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/
gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo...
Author: jdillon
Date: Sat Sep 27 07:53:56 2008
New Revision: 699660
URL: http://svn.apache.org/viewvc?rev=699660&view=rev
Log:
Hooked up basic alias and command name completion
Added:
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/completor/AliasNameCompletor.java (with props)
geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completor/CommandNameCompletor.java (with props)
Modified:
geronimo/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/JLineConsole.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-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java?rev=699660&r1=699659&r2=699660&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java (original)
+++ geronimo/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java Sat Sep 27 07:53:56 2008
@@ -148,6 +148,10 @@
private void setTerminalType(String type) {
type = type.toLowerCase();
+ //
+ // FIXME: Provide an abstraction over the jline term stuff and its warts, and/or fork it and re-implement it to not be so broken
+ //
+
if ("unix".equals(type)) {
type = "jline.UnixTerminal";
}
@@ -159,6 +163,7 @@
//
// HACK: Disable ANSI, for some reason UnsupportedTerminal reports ANSI as enabled, when it shouldn't
+ // as a temporary solution, could provide a Terminal instance which can delegate and fix warts like this
//
ANSI.setEnabled(false);
}
Modified: geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/JLineConsole.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/JLineConsole.java?rev=699660&r1=699659&r2=699660&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/JLineConsole.java (original)
+++ geronimo/gshell/trunk/gshell-support/gshell-console/src/main/java/org/apache/geronimo/gshell/console/JLineConsole.java Sat Sep 27 07:53:56 2008
@@ -21,6 +21,8 @@
import jline.ConsoleReader;
import jline.History;
+import jline.Completor;
+import jline.CandidateListCompletionHandler;
import org.apache.geronimo.gshell.io.IO;
import java.io.IOException;
@@ -41,24 +43,28 @@
assert io != null;
+ // TODO: Expose bindings
+
reader = new ConsoleReader(io.inputStream, new PrintWriter(io.outputStream, true), /*bindings*/null, io.getTerminal());
reader.setUsePagination(true);
-
- // TODO: Install completion handler
+ reader.setCompletionHandler(new CandidateListCompletionHandler());
}
- public void run() {
- // TODO: Update/install/whatever the completion handler
-
- // And then actually run
- super.run();
+ public void addCompleter(final Completor completer) {
+ assert completer != null;
+
+ reader.addCompletor(completer);
}
public void setHistory(final History history) {
+ assert history != null;
+
reader.setHistory(history);
}
protected String readLine(final String prompt) throws IOException {
+ // prompt may be null
+
return reader.readLine(prompt);
}
}
\ No newline at end of file
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=699660&r1=699659&r2=699660&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 07:53:56 2008
@@ -19,7 +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.application.Application;
import org.apache.geronimo.gshell.command.Variables;
@@ -48,6 +50,7 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
+import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
/**
@@ -72,6 +75,8 @@
@Autowired
private History history;
+ private List<Completor> completors;
+
private ShellContext context;
private Branding branding;
@@ -80,6 +85,12 @@
private ErrorHandler errorHandler;
+ public void setCompletors(final List<Completor> completors) {
+ assert completors != null;
+
+ this.completors = completors;
+ }
+
public ShellContext getContext() {
if (context == null) {
throw new IllegalStateException("Shell context has not been initialized");
@@ -181,22 +192,18 @@
IO io = getContext().getIo();
- // Ya, bust out the sexy JLine console baby!
+ // Setup the console runner
JLineConsole console = new JLineConsole(executor, io);
-
- //
- // TODO: Hook up completer bits here
- //
-
- // Setup the prompt
console.setPrompter(getPrompter());
-
- // Delegate errors for display and then continue
console.setErrorHandler(getErrorHandler());
-
- // Hook up a nice history file (we gotta hold on to the history object at some point so the 'history' command can get to it)
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));
+ }
+
// Unless the user wants us to shut up, then display a nice welcome banner
if (!io.isQuiet()) {
String message = branding.getWelcomeMessage();
Added: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completor/AliasNameCompletor.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completor/AliasNameCompletor.java?rev=699660&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completor/AliasNameCompletor.java (added)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completor/AliasNameCompletor.java Sat Sep 27 07:53:56 2008
@@ -0,0 +1,87 @@
+/*
+ * 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.completor;
+
+import jline.Completor;
+import jline.SimpleCompletor;
+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.wisdom.registry.AliasRegisteredEvent;
+import org.apache.geronimo.gshell.wisdom.registry.AliasRemovedEvent;
+import org.apache.geronimo.gshell.registry.AliasRegistry;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.PostConstruct;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.Collection;
+
+/**
+ * {@link Completor} for alias names.
+ *
+ * @version $Rev$ $Date$
+ */
+public class AliasNameCompletor
+ implements Completor
+{
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ @Autowired
+ private EventManager eventManager;
+
+ @Autowired
+ private AliasRegistry aliasRegistry;
+
+ private final SimpleCompletor delegate = new SimpleCompletor(new String[0]);
+
+ private final SortedSet<String> candidates = new TreeSet<String>();
+
+ @PostConstruct
+ public void init() {
+ log.debug("Initializing");
+
+ // Populate the initial list of alias names
+ Collection<String> names = aliasRegistry.getAliasNames();
+ candidates.addAll(names);
+ delegate.setCandidates(candidates);
+
+ // 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;
+ candidates.add(targetEvent.getName());
+ }
+ else if (event instanceof AliasRemovedEvent) {
+ AliasRemovedEvent targetEvent = (AliasRemovedEvent)event;
+ candidates.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/completor/AliasNameCompletor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completor/AliasNameCompletor.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/completor/AliasNameCompletor.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completor/CommandNameCompletor.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completor/CommandNameCompletor.java?rev=699660&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completor/CommandNameCompletor.java (added)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completor/CommandNameCompletor.java Sat Sep 27 07:53:56 2008
@@ -0,0 +1,87 @@
+/*
+ * 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.completor;
+
+import jline.Completor;
+import jline.SimpleCompletor;
+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;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+/**
+ * {@link Completor} for command names.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CommandNameCompletor
+ implements Completor
+{
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ @Autowired
+ private EventManager eventManager;
+
+ @Autowired
+ private CommandRegistry commandRegistry;
+
+ private final SimpleCompletor delegate = new SimpleCompletor(new String[0]);
+
+ private final SortedSet<String> candidates = new TreeSet<String>();
+
+ @PostConstruct
+ public void init() {
+ log.debug("Initializing");
+
+ // Populate the initial list of command names
+ Collection<String> names = commandRegistry.getCommandNames();
+ candidates.addAll(names);
+ delegate.setCandidates(candidates);
+
+ // 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;
+ candidates.add(targetEvent.getName());
+ }
+ else if (event instanceof CommandRemovedEvent) {
+ CommandRemovedEvent targetEvent = (CommandRemovedEvent)event;
+ candidates.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/completor/CommandNameCompletor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completor/CommandNameCompletor.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/completor/CommandNameCompletor.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=699660&r1=699659&r2=699660&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 07:53:56 2008
@@ -41,7 +41,17 @@
<bean id="shellInfo" class="org.apache.geronimo.gshell.wisdom.shell.ShellInfoImpl"/>
- <bean id="shell" class="org.apache.geronimo.gshell.wisdom.shell.ShellImpl"/>
+ <bean id="shell" class="org.apache.geronimo.gshell.wisdom.shell.ShellImpl">
+ <property name="completors">
+ <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.
+ -->
+ </list>
+ </property>
+ </bean>
<bean id="pluginTemplate" class="org.apache.geronimo.gshell.wisdom.plugin.PluginImpl" abstract="true">
<property name="activationRules">