Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2013-05-02 18:37:42 +0000
committerThomas Watson2013-05-02 18:37:42 +0000
commit40f848bcf19ab53a63ebcdcc8fa4d45e975e8895 (patch)
treebc3fefb00ffb820161916d5dca13b85a7ea53c80 /bundles/org.eclipse.equinox.console
parentd3b5a297ef7a233004535e26c9cec5929e666620 (diff)
parent8cbda223069c62390bfa22a266dad5d7a9b9526c (diff)
downloadrt.equinox.bundles-40f848bcf19ab53a63ebcdcc8fa4d45e975e8895.tar.gz
rt.equinox.bundles-40f848bcf19ab53a63ebcdcc8fa4d45e975e8895.tar.xz
rt.equinox.bundles-40f848bcf19ab53a63ebcdcc8fa4d45e975e8895.zip
Merge branch 'master' into twatson/container
Diffstat (limited to 'bundles/org.eclipse.equinox.console')
-rwxr-xr-xbundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/command/adapter/Activator.java4
-rwxr-xr-xbundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/CommandsTracker.java87
-rwxr-xr-xbundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/HelpCommand.java16
-rwxr-xr-xbundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/completion/CommandNamesCompleter.java20
-rwxr-xr-xbundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/completion/CompletionHandler.java2
5 files changed, 123 insertions, 6 deletions
diff --git a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/command/adapter/Activator.java b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/command/adapter/Activator.java
index 11d8e2d69..4be3b5de7 100755
--- a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/command/adapter/Activator.java
+++ b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/command/adapter/Activator.java
@@ -23,6 +23,7 @@ import java.util.List;
import org.apache.felix.service.command.CommandProcessor;
import org.apache.felix.service.command.CommandSession;
+import org.eclipse.equinox.console.commands.CommandsTracker;
import org.eclipse.equinox.console.commands.DisconnectCommand;
import org.eclipse.equinox.console.commands.EquinoxCommandProvider;
import org.eclipse.equinox.console.commands.HelpCommand;
@@ -228,6 +229,9 @@ public class Activator implements BundleActivator {
DisconnectCommand disconnectCommand = new DisconnectCommand(context);
disconnectCommand.startService();
+
+ CommandsTracker commandsTracker = new CommandsTracker(context);
+ context.registerService(CommandsTracker.class.getName(), commandsTracker, null);
startBundle("org.apache.felix.gogo.runtime", true);
startBundle("org.apache.felix.gogo.shell", true);
diff --git a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/CommandsTracker.java b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/CommandsTracker.java
new file mode 100755
index 000000000..2b5f68c6a
--- /dev/null
+++ b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/CommandsTracker.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2013 SAP AG.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Lazar Kirchev, SAP AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.console.commands;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.felix.service.command.CommandProcessor;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+public class CommandsTracker {
+ private Set<String> commandNames;
+ private ServiceTracker<Object, Set<String>> commandsTracker = null;
+ private static final Object lock = new Object();
+
+ public CommandsTracker(BundleContext bundleContext) {
+ commandNames = Collections.synchronizedSet(new HashSet<String>());
+ try {
+ Filter filter = bundleContext.createFilter(String.format("(&(%s=*)(%s=*))", CommandProcessor.COMMAND_SCOPE, CommandProcessor.COMMAND_FUNCTION));
+ commandsTracker = new ServiceTracker<Object, Set<String>>(bundleContext, filter, new CommandsTrackerCustomizer());
+ commandsTracker.open();
+ } catch (InvalidSyntaxException e) {
+ //do nothing;
+ }
+ }
+
+ public Set<String> getCommands() {
+ synchronized (lock) {
+ return new HashSet<String>(commandNames);
+ }
+ }
+
+ class CommandsTrackerCustomizer implements ServiceTrackerCustomizer<Object, Set<String>> {
+ public Set<String> addingService(ServiceReference<Object> reference) {
+ Object scope = reference.getProperty(CommandProcessor.COMMAND_SCOPE);
+ Object function = reference.getProperty(CommandProcessor.COMMAND_FUNCTION);
+
+ if (scope != null && function != null) {
+ synchronized (lock) {
+ if (function.getClass().isArray()) {
+ for (Object func : ((Object[]) function)) {
+ commandNames.add(scope.toString() + ":" + func.toString());
+ }
+ } else {
+ commandNames.add(scope.toString() + ":" + function.toString());
+ }
+ return commandNames;
+ }
+ }
+ return null;
+ }
+
+ public void modifiedService(ServiceReference<Object> reference, Set<String> commandNames) {
+ // nothing to do
+ }
+
+ public void removedService(ServiceReference<Object> reference, Set<String> commandNames) {
+ Object scope = reference.getProperty(CommandProcessor.COMMAND_SCOPE);
+ Object function = reference.getProperty(CommandProcessor.COMMAND_FUNCTION);
+
+ if (scope != null && function != null) {
+ if (!function.getClass().isArray()) {
+ commandNames.remove(scope.toString() + ":" + function.toString());
+ } else {
+ for (Object func : (Object[]) function) {
+ commandNames.remove(scope.toString() + ":" + func.toString());
+ }
+ }
+ }
+ }
+
+ }
+}
diff --git a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/HelpCommand.java b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/HelpCommand.java
index ddd59e509..eef1fa864 100755
--- a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/HelpCommand.java
+++ b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/HelpCommand.java
@@ -37,6 +37,7 @@ public class HelpCommand {
private BundleContext context;
private Set<CommandProvider> legacyCommandProviders;
private ServiceTracker<CommandProvider, Set<CommandProvider>> commandProvidersTracker;
+ private ServiceTracker<CommandsTracker, CommandsTracker> commandsTrackerTracker;
private static final String COMMANDS = ".commands";
public class CommandProviderCustomizer implements ServiceTrackerCustomizer<CommandProvider, Set<CommandProvider>> {
@@ -76,6 +77,8 @@ public class HelpCommand {
legacyCommandProviders = new HashSet<CommandProvider>();
commandProvidersTracker = new ServiceTracker<CommandProvider, Set<CommandProvider>>(context, CommandProvider.class.getName(), new CommandProviderCustomizer(context));
commandProvidersTracker.open();
+ commandsTrackerTracker = new ServiceTracker<CommandsTracker, CommandsTracker>(context, CommandsTracker.class.getName(), null);
+ commandsTrackerTracker.open();
}
public void startService() {
@@ -142,9 +145,17 @@ public class HelpCommand {
}
}
+ @SuppressWarnings("unchecked")
private void printAllGogoCommandsHelp(final CommandSession session, String scope) throws Exception {
- @SuppressWarnings("unchecked")
- Set<String> commandNames = (Set<String>) session.get(COMMANDS);
+ CommandsTracker commandsTracker = commandsTrackerTracker.getService();
+ Set<String> commandNames = null;
+ if (commandsTracker != null) {
+ commandNames = commandsTracker.getCommands();
+ }
+
+ if (commandNames == null || commandNames.isEmpty()) {
+ commandNames = (Set<String>) session.get(COMMANDS);
+ }
try {
for (String commandName : commandNames) {
@@ -201,4 +212,5 @@ public class HelpCommand {
System.out.println("Cannot find felix:help command; bundle org.apache.felix.gogo.command is not started");
}
}
+
}
diff --git a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/completion/CommandNamesCompleter.java b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/completion/CommandNamesCompleter.java
index 5199a3360..f7b496d8b 100755
--- a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/completion/CommandNamesCompleter.java
+++ b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/completion/CommandNamesCompleter.java
@@ -17,7 +17,10 @@ import java.util.Map;
import java.util.Set;
import org.apache.felix.service.command.CommandSession;
+import org.eclipse.equinox.console.commands.CommandsTracker;
import org.eclipse.equinox.console.completion.common.Completer;
+import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
/**
* This class provides completion for command names.
@@ -26,16 +29,27 @@ import org.eclipse.equinox.console.completion.common.Completer;
public class CommandNamesCompleter implements Completer {
private CommandSession session;
+ private ServiceTracker<CommandsTracker, CommandsTracker> commandsTrackerTracker;
private static final String COMMANDS = ".commands";
- public CommandNamesCompleter(CommandSession session) {
+ public CommandNamesCompleter(BundleContext context, CommandSession session) {
this.session = session;
+ commandsTrackerTracker = new ServiceTracker<CommandsTracker, CommandsTracker>(context, CommandsTracker.class.getName(), null);
+ commandsTrackerTracker.open();
}
+ @SuppressWarnings("unchecked")
public Map<String, Integer> getCandidates(String buffer, int cursor) {
+ CommandsTracker commandsTracker = commandsTrackerTracker.getService();
+ Set<String> commandNames = null;
+ if (commandsTracker != null) {
+ commandNames = commandsTracker.getCommands();
+ }
+
// CommandSession.get(".commands") returns the names of all registered commands
- @SuppressWarnings("unchecked")
- Set<String> commandNames = (Set<String>) session.get(COMMANDS);
+ if (commandNames == null || commandNames.isEmpty()) {
+ commandNames = (Set<String>) session.get(COMMANDS);
+ }
// command names are stored in the session in lower case
String currentToken = CommandLineParser.getCurrentToken(buffer, cursor).toLowerCase();
diff --git a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/completion/CompletionHandler.java b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/completion/CompletionHandler.java
index b805aeebe..b2f9e3b08 100755
--- a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/completion/CompletionHandler.java
+++ b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/completion/CompletionHandler.java
@@ -56,7 +56,7 @@ public class CompletionHandler {
if ((cursor - currentToken.length() > 0) && (buf[cursor - currentToken.length() - 1] == VARIABLE_PREFIX)){
completers.add(new VariableNamesCompleter(session));
}else {
- completers.add(new CommandNamesCompleter(session));
+ completers.add(new CommandNamesCompleter(context, session));
completers.add(new FileNamesCompleter());
}
}

Back to the top