From 39af747aa850411e67c0f40efe8cd16017263396 Mon Sep 17 00:00:00 2001 From: Gunnar Wagenknecht Date: Thu, 28 Mar 2013 02:12:09 +0200 Subject: Bug 403893 - implement CommandInterpreter.execute using current CommmandSession --- .../command/adapter/CommandProviderAdapter.java | 9 +++---- .../command/adapter/CustomCommandInterpreter.java | 28 ++++++++++++++++++---- .../equinox/console/commands/HelpCommand.java | 10 ++++---- 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 f78483525..d6a7ebef4 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 argList = new ArrayList(); 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 c401e361b..5feaeb436 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 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 args) { + public CustomCommandInterpreter(CommandSession commandSession, List 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 6a4461f3c..ddd59e509 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 argsList = new ArrayList(); 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; -- cgit v1.2.3