summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGunnar Wagenknecht2013-03-27 20:12:09 (EDT)
committer Lazar Kirchev2013-03-27 20:12:09 (EDT)
commit39af747aa850411e67c0f40efe8cd16017263396 (patch)
tree93d2ab6f7e3e4cf0f3b258eff454c6d441df0451
parent8b767d47756ce793565a884c3e0ae894f5609a63 (diff)
downloadrt.equinox.bundles-39af747aa850411e67c0f40efe8cd16017263396.zip
rt.equinox.bundles-39af747aa850411e67c0f40efe8cd16017263396.tar.gz
rt.equinox.bundles-39af747aa850411e67c0f40efe8cd16017263396.tar.bz2
Bug 403893 - implement CommandInterpreter.execute using current CommmandSession
-rwxr-xr-xbundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/command/adapter/CommandProviderAdapter.java9
-rwxr-xr-xbundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/command/adapter/CustomCommandInterpreter.java28
-rwxr-xr-xbundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/HelpCommand.java10
3 files changed, 33 insertions, 14 deletions
diff --git a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/command/adapter/CommandProviderAdapter.java b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/command/adapter/CommandProviderAdapter.java
index f784835..d6a7ebe 100755
--- a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/command/adapter/CommandProviderAdapter.java
+++ b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/command/adapter/CommandProviderAdapter.java
@@ -16,6 +16,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import org.apache.felix.service.command.CommandSession;
import org.eclipse.osgi.framework.console.CommandProvider;
/**
@@ -36,14 +37,14 @@ public class CommandProviderAdapter {
this.commands = commands;
}
- public Object main(Object[] args) throws Exception {
+ public Object main(CommandSession commandSession, Object[] args) throws Exception {
try {
// first argument is the command
Method command = findCommand("_" + args[0]);
ArrayList<Object> argList = new ArrayList<Object>();
for (int i = 1; i < args.length; i++)
argList.add(args[i]);
- return command.invoke(commandProvider, new CustomCommandInterpreter(argList));
+ return command.invoke(commandProvider, new CustomCommandInterpreter(commandSession, argList));
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof Exception)
throw (Exception) e.getTargetException();
@@ -60,7 +61,7 @@ public class CommandProviderAdapter {
}
// TODO Felix gogo seems to search for _main
- public Object _main(Object[] args) throws Exception {
- return main(args);
+ public Object _main(CommandSession commandSession, Object[] args) throws Exception {
+ return main(commandSession, args);
}
}
diff --git a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/command/adapter/CustomCommandInterpreter.java b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/command/adapter/CustomCommandInterpreter.java
index c401e36..5feaeb4 100755
--- a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/command/adapter/CustomCommandInterpreter.java
+++ b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/command/adapter/CustomCommandInterpreter.java
@@ -11,10 +11,20 @@
*******************************************************************************/
package org.eclipse.equinox.console.command.adapter;
-import java.io.*;
-import java.lang.reflect.*;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import java.net.URL;
-import java.util.*;
+import java.util.Arrays;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.felix.service.command.CommandSession;
import org.eclipse.osgi.framework.console.CommandInterpreter;
import org.osgi.framework.Bundle;
@@ -29,6 +39,7 @@ public class CustomCommandInterpreter implements CommandInterpreter {
private String tab = "\t"; //$NON-NLS-1$
private String newline = "\r\n"; //$NON-NLS-1$
private final Iterator<Object> arguments;
+ private final CommandSession commandSession;
/**
* The maximum number of lines to print without user prompt.
* 0 means no user prompt is required, the window is scrollable.
@@ -38,12 +49,19 @@ public class CustomCommandInterpreter implements CommandInterpreter {
/** The number of lines printed without user prompt.*/
protected int currentLineCount;
- public CustomCommandInterpreter(List<Object> args) {
+ public CustomCommandInterpreter(CommandSession commandSession, List<Object> args) {
+ this.commandSession = commandSession;
arguments = args.iterator();
}
public Object execute(String cmd) {
- return null;
+ try {
+ return commandSession.execute(cmd);
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
}
public String nextArgument() {
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 6a4461f..ddd59e5 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
@@ -18,8 +18,6 @@ import java.util.HashSet;
import java.util.Hashtable;
import java.util.Set;
-import org.apache.felix.service.command.CommandProcessor;
-import org.apache.felix.service.command.CommandSession;
import org.eclipse.equinox.console.command.adapter.CustomCommandInterpreter;
import org.eclipse.osgi.framework.console.CommandInterpreter;
import org.eclipse.osgi.framework.console.CommandProvider;
@@ -29,6 +27,8 @@ import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
+import org.apache.felix.service.command.CommandProcessor;
+import org.apache.felix.service.command.CommandSession;
/**
* This class provides help for the legacy equinox commands, which are adapted to Gogo commands.
@@ -116,7 +116,7 @@ public class HelpCommand {
}
if (command != null) {
- printLegacyCommandHelp(command);
+ printLegacyCommandHelp(session, command);
printGogoCommandHelp(session, command);
return;
}
@@ -158,7 +158,7 @@ public class HelpCommand {
}
}
- private void printLegacyCommandHelp(String command) {
+ private void printLegacyCommandHelp(final CommandSession session, String command) {
for (CommandProvider provider : legacyCommandProviders) {
Method[] methods = provider.getClass().getMethods();
for (Method method : methods) {
@@ -168,7 +168,7 @@ public class HelpCommand {
Method helpMethod = provider.getClass().getMethod("_help", CommandInterpreter.class);
ArrayList<Object> argsList = new ArrayList<Object>();
argsList.add(command);
- retval = helpMethod.invoke(provider, new CustomCommandInterpreter(argsList));
+ retval = helpMethod.invoke(provider, new CustomCommandInterpreter(session, argsList));
} catch (Exception e) {
System.out.println(provider.getHelp());
break;