aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLazar Kirchev2013-04-29 05:53:24 (EDT)
committerLazar Kirchev2013-04-29 05:53:24 (EDT)
commitc1fbe63c87f8f6adc4c6b574a30c9a535167ad5d (patch)
treed70b411339cb9683872170e492637a6bdc0bb09e
parentbe623943f73f5988a2b045b707f141f67e294770 (diff)
downloadrt.equinox.bundles-c1fbe63c87f8f6adc4c6b574a30c9a535167ad5d.zip
rt.equinox.bundles-c1fbe63c87f8f6adc4c6b574a30c9a535167ad5d.tar.gz
rt.equinox.bundles-c1fbe63c87f8f6adc4c6b574a30c9a535167ad5d.tar.bz2
Bug 403938 - [console] can't register a Gogo command when the method name contains lowercase and uppercaseI20130429-0800
-rwxr-xr-xbundles/org.eclipse.equinox.console.tests/META-INF/MANIFEST.MF2
-rwxr-xr-xbundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CommandNamesCompleterTests.java21
-rwxr-xr-xbundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CompletionHandlerTests.java10
-rwxr-xr-xbundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputScannerTests.java10
-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
9 files changed, 163 insertions, 9 deletions
diff --git a/bundles/org.eclipse.equinox.console.tests/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.console.tests/META-INF/MANIFEST.MF
index aa559b3..5eb5dd1 100755
--- a/bundles/org.eclipse.equinox.console.tests/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.console.tests/META-INF/MANIFEST.MF
@@ -7,6 +7,6 @@ Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: junit.framework;version="4.8.1",
org.apache.sshd.client.future,
- org.easymock;version="2.4.0",
+ org.easymock;version="3.0.0",
org.junit;version="4.8.1"
Fragment-Host: org.eclipse.equinox.console
diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CommandNamesCompleterTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CommandNamesCompleterTests.java
index 390ffa7..0797570 100755
--- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CommandNamesCompleterTests.java
+++ b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CommandNamesCompleterTests.java
@@ -18,15 +18,22 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import org.apache.felix.service.command.CommandProcessor;
import org.apache.felix.service.command.CommandSession;
+import org.eclipse.equinox.console.commands.CommandsTracker;
import org.junit.Test;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
public class CommandNamesCompleterTests {
private static final String COMMANDS = ".commands";
@Test
- public void testGetCandidates() {
+ public void testGetCandidates() throws Exception {
Set<String> commands = new HashSet<String>();
commands.add("equinox:bundles");
commands.add("equinox:diag");
@@ -39,7 +46,17 @@ public class CommandNamesCompleterTests {
expect(session.get(COMMANDS)).andReturn(commands).times(4);
replay(session);
- CommandNamesCompleter completer = new CommandNamesCompleter(session);
+ Filter filter = createMock(Filter.class);
+ replay(filter);
+
+ BundleContext context = createMock(BundleContext.class);
+// expect(context.createFilter(String.format("(&(%s=*)(%s=*))", CommandProcessor.COMMAND_SCOPE, CommandProcessor.COMMAND_FUNCTION))).andReturn(filter);
+ expect(context.createFilter("(objectClass=org.eclipse.equinox.console.commands.CommandsTracker)")).andReturn(filter);
+ context.addServiceListener(anyObject(ServiceListener.class), anyObject(String.class));
+ expect(context.getServiceReferences("org.eclipse.equinox.console.commands.CommandsTracker", null)).andReturn(new ServiceReference[]{});
+ replay(context);
+
+ CommandNamesCompleter completer = new CommandNamesCompleter(context, session);
Map<String, Integer> candidates;
candidates = completer.getCandidates("se", 2);
diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CompletionHandlerTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CompletionHandlerTests.java
index e71be0c..3a043a3 100755
--- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CompletionHandlerTests.java
+++ b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CompletionHandlerTests.java
@@ -28,6 +28,9 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
public class CompletionHandlerTests {
@@ -58,8 +61,15 @@ public class CompletionHandlerTests {
@Test
public void testGetCandidates() throws Exception {
+ Filter filter = createMock(Filter.class);
+ replay(filter);
+
BundleContext context = createMock(BundleContext.class);
expect(context.getServiceReferences(Completer.class.getName(), null)).andReturn(null).anyTimes();
+ expect(context.createFilter("(objectClass=org.eclipse.equinox.console.commands.CommandsTracker)")).andReturn(filter).anyTimes();
+ context.addServiceListener(anyObject(ServiceListener.class), anyObject(String.class));
+ expectLastCall().anyTimes();
+ expect(context.getServiceReferences("org.eclipse.equinox.console.commands.CommandsTracker", null)).andReturn(new ServiceReference[]{}).anyTimes();
replay(context);
Set<String> variables = new HashSet<String>();
diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputScannerTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputScannerTests.java
index d03838c..eedbf5c 100755
--- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputScannerTests.java
+++ b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputScannerTests.java
@@ -11,6 +11,7 @@
package org.eclipse.equinox.console.supportability;
+import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
@@ -30,6 +31,9 @@ import org.eclipse.equinox.console.completion.common.Completer;
import org.junit.Assert;
import org.junit.Test;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
import java.io.ByteArrayOutputStream;
import java.util.HashMap;
@@ -180,8 +184,14 @@ public class ConsoleInputScannerTests {
res = byteOut.toString();
Assert.assertTrue("Error processing Ins; expected las, actual " + res.substring(res.length() - 4), res.endsWith("lasa"));
+ Filter filter = createMock(Filter.class);
+ replay(filter);
+
BundleContext context = createMock(BundleContext.class);
expect(context.getServiceReferences(Completer.class.getName(), null)).andReturn(null).anyTimes();
+ expect(context.createFilter("(objectClass=org.eclipse.equinox.console.commands.CommandsTracker)")).andReturn(filter);
+ context.addServiceListener(anyObject(ServiceListener.class), anyObject(String.class));
+ expect(context.getServiceReferences("org.eclipse.equinox.console.commands.CommandsTracker", null)).andReturn(new ServiceReference[]{});
replay(context);
Set<String> commands = new HashSet<String>();
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 350ee36..82238f6 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;
@@ -233,6 +234,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 0000000..2b5f68c
--- /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 ddd59e5..eef1fa8 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 5199a33..f7b496d 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 b805aee..b2f9e3b 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());
}
}