Adopt the new console
diff --git a/org.eclipse.virgo.ide.management.remote/META-INF/MANIFEST.MF b/org.eclipse.virgo.ide.management.remote/META-INF/MANIFEST.MF
index 6f29a22..fea9558 100644
--- a/org.eclipse.virgo.ide.management.remote/META-INF/MANIFEST.MF
+++ b/org.eclipse.virgo.ide.management.remote/META-INF/MANIFEST.MF
@@ -15,7 +15,8 @@
  org.springframework.jmx.export,

  org.springframework.jmx.export.annotation,

  org.springframework.jmx.export.assembler,

- org.springframework.jmx.export.naming

+ org.springframework.jmx.export.naming,

+ org.apache.felix.service.command;status=provisional

 Bundle-Vendor: Eclipse.org - Virgo

 Export-Package: org.eclipse.virgo.ide.management.remote

 Bundle-RequiredExecutionEnvironment: J2SE-1.5

diff --git a/org.eclipse.virgo.ide.management.remote/META-INF/spring/module-config.xml b/org.eclipse.virgo.ide.management.remote/META-INF/spring/module-config.xml
index 102af6e..3f73f5d 100644
--- a/org.eclipse.virgo.ide.management.remote/META-INF/spring/module-config.xml
+++ b/org.eclipse.virgo.ide.management.remote/META-INF/spring/module-config.xml
@@ -5,7 +5,6 @@
 
 	<bean id="standardBundleAdmin" class="org.eclipse.virgo.ide.management.remote.StandardBundleAdmin">
 		<constructor-arg ref="platformAdmin" />
-		<constructor-arg ref="packageAdmin" />
 		<constructor-arg ref="bundleContext" /> 
 	</bean> 
   
diff --git a/org.eclipse.virgo.ide.management.remote/META-INF/spring/osgi-config.xml b/org.eclipse.virgo.ide.management.remote/META-INF/spring/osgi-config.xml
index 7dfcffd..8965fff 100644
--- a/org.eclipse.virgo.ide.management.remote/META-INF/spring/osgi-config.xml
+++ b/org.eclipse.virgo.ide.management.remote/META-INF/spring/osgi-config.xml
@@ -8,7 +8,4 @@
 	<osgi:reference id="platformAdmin"
 		interface="org.eclipse.osgi.service.resolver.PlatformAdmin" />
 
-	<osgi:reference id="packageAdmin"
-		interface="org.osgi.service.packageadmin.PackageAdmin" />
-
 </beans>
diff --git a/org.eclipse.virgo.ide.management.remote/src/org/eclipse/virgo/ide/management/remote/ServerCommandInterpreter.java b/org.eclipse.virgo.ide.management.remote/src/org/eclipse/virgo/ide/management/remote/ServerCommandInterpreter.java
deleted file mode 100644
index 6733fbf..0000000
--- a/org.eclipse.virgo.ide.management.remote/src/org/eclipse/virgo/ide/management/remote/ServerCommandInterpreter.java
+++ /dev/null
@@ -1,317 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2012 SpringSource, a divison of VMware, Inc.
- * 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:
- *     SpringSource, a divison of VMware, Inc. - initial API and implementation
- *******************************************************************************/
-package org.eclipse.virgo.ide.management.remote;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintWriter;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.net.URL;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.StringTokenizer;
-
-import org.eclipse.osgi.framework.console.CommandInterpreter;
-import org.eclipse.osgi.framework.console.CommandProvider;
-import org.eclipse.osgi.framework.internal.core.ConsoleMsg;
-import org.eclipse.osgi.framework.internal.core.Util;
-import org.eclipse.osgi.util.NLS;
-import org.osgi.framework.Bundle;
-
-/**
- * @author Christian Dupuis
- */
-@SuppressWarnings("restriction")
-public class ServerCommandInterpreter implements CommandInterpreter {
-	private static final String WS_DELIM = " \t\n\r\f"; //$NON-NLS-1$
-
-	/** The command line in StringTokenizer form */
-	private final StringTokenizer tok;
-
-	/** The active CommandProviders */
-	private final Object[] commandProviders;
-
-	/** Strings used to format other strings */
-	private final String tab = "\t"; //$NON-NLS-1$
-
-	private final String newline = "\r\n"; //$NON-NLS-1$
-
-	private final PrintWriter out;
-
-	public ServerCommandInterpreter(String cmdLine, Object[] commandProviders, PrintWriter writer) {
-		this.commandProviders = commandProviders;
-		this.tok = new StringTokenizer(cmdLine);
-		this.out = writer;
-	}
-
-	/**
-	 * Get the next argument in the input. E.g. if the commandline is hello world, the _hello method will get "world" as
-	 * the first argument.
-	 * 
-	 * @return A string containing the next argument on the command line
-	 */
-	public String nextArgument() {
-		if (tok == null || !tok.hasMoreElements()) {
-			return null;
-		}
-
-		String arg = tok.nextToken();
-		if (arg.startsWith("\"")) { //$NON-NLS-1$
-			if (arg.endsWith("\"")) { //$NON-NLS-1$
-				if (arg.length() >= 2) {
-					// strip the beginning and ending quotes
-					return arg.substring(1, arg.length() - 1);
-				}
-			}
-			String remainingArg = tok.nextToken("\""); //$NON-NLS-1$
-			arg = arg.substring(1) + remainingArg;
-			// skip to next whitespace separated token
-			tok.nextToken(WS_DELIM);
-		} else if (arg.startsWith("'")) { //$NON-NLS-1$ 
-			if (arg.endsWith("'")) { //$NON-NLS-1$
-				if (arg.length() >= 2) {
-					// strip the beginning and ending quotes
-					return arg.substring(1, arg.length() - 1);
-				}
-			}
-			String remainingArg = tok.nextToken("'"); //$NON-NLS-1$
-			arg = arg.substring(1) + remainingArg;
-			// skip to next whitespace separated token
-			tok.nextToken(WS_DELIM);
-		}
-		return arg;
-	}
-
-	/**
-	 * Execute a command line as if it came from the end user. Searches the list of command providers using
-	 * introspection until it finds one that contains a matching method. It searches for a method with the name "_cmd"
-	 * where cmd is the command to execute. For example, for a command of "launch" execute searches for a method called
-	 * "_launch".
-	 * 
-	 * @param cmd
-	 *            The name of the command to execute.
-	 * @return The object returned by the method executed.
-	 */
-	public Object execute(String cmd) {
-		Object retval = null;
-		@SuppressWarnings("rawtypes")
-		Class[] parameterTypes = new Class[] { CommandInterpreter.class };
-		Object[] parameters = new Object[] { this };
-		boolean executed = false;
-		int size = commandProviders.length;
-		for (int i = 0; !executed && (i < size); i++) {
-			try {
-				Object target = commandProviders[i];
-				Method method = target.getClass().getMethod("_" + cmd, parameterTypes); //$NON-NLS-1$
-				retval = method.invoke(target, parameters);
-				executed = true; // stop after the command has been found
-			} catch (NoSuchMethodException ite) {
-				// keep going - maybe another command provider will be able to
-				// execute this command
-			} catch (InvocationTargetException ite) {
-				executed = true; // don't want to keep trying - we found the
-				// method but got an error
-				printStackTrace(ite.getTargetException());
-			} catch (Exception ee) {
-				executed = true; // don't want to keep trying - we got an error
-				// we don't understand
-				printStackTrace(ee);
-			}
-		}
-		// if no command was found to execute, display help for all registered
-		// command providers
-		if (!executed) {
-			for (int i = 0; i < size; i++) {
-				try {
-					CommandProvider commandProvider = (CommandProvider) commandProviders[i];
-					out.print(commandProvider.getHelp());
-					out.flush();
-				} catch (Exception ee) {
-					printStackTrace(ee);
-				}
-			}
-			// call help for the more command provided by this class
-			out.print(getHelp());
-			out.flush();
-		}
-		return retval;
-	}
-
-	/**
-	 * Prints a string to the output medium (appended with newline character).
-	 * <p>
-	 * This method does not increment the line counter for the 'more' prompt.
-	 * 
-	 * @param o
-	 *            the string to be printed
-	 */
-	private void printline(Object o) {
-		print(o + newline);
-	}
-
-	/**
-	 * Prints an object to the outputstream
-	 * 
-	 * @param o
-	 *            the object to be printed
-	 */
-	public void print(Object o) {
-		synchronized (out) {
-			out.print(o);
-			out.flush();
-		}
-	}
-
-	/**
-	 * Prints a empty line to the outputstream
-	 */
-	public void println() {
-		println(""); //$NON-NLS-1$
-	}
-
-	/**
-	 * Print a stack trace including nested exceptions.
-	 * 
-	 * @param t
-	 *            The offending exception
-	 */
-	public void printStackTrace(Throwable t) {
-		t.printStackTrace(out);
-
-		Method[] methods = t.getClass().getMethods();
-
-		int size = methods.length;
-		Class<Throwable> throwable = Throwable.class;
-
-		for (int i = 0; i < size; i++) {
-			Method method = methods[i];
-
-			if (Modifier.isPublic(method.getModifiers())
-					&& method.getName().startsWith("get") && throwable.isAssignableFrom(method.getReturnType()) && (method.getParameterTypes().length == 0)) { //$NON-NLS-1$
-				try {
-					Throwable nested = (Throwable) method.invoke(t, new Object[0]);
-
-					if ((nested != null) && (nested != t)) {
-						out.println(ConsoleMsg.CONSOLE_NESTED_EXCEPTION);
-						printStackTrace(nested);
-					}
-				} catch (IllegalAccessException e) {
-				} catch (InvocationTargetException e) {
-				}
-			}
-		}
-	}
-
-	/**
-	 * Prints an object to the output medium (appended with newline character).
-	 * <p>
-	 * If running on the target environment, the user is prompted with '--more' if more than the configured number of
-	 * lines have been printed without user prompt. This enables the user of the program to have control over scrolling.
-	 * <p>
-	 * For this to work properly you should not embed "\n" etc. into the string.
-	 * 
-	 * @param o
-	 *            the object to be printed
-	 */
-	public void println(Object o) {
-		if (o == null) {
-			return;
-		}
-		synchronized (out) {
-			printline(o);
-		}
-	}
-
-	/**
-	 * Prints the given dictionary sorted by keys.
-	 * 
-	 * @param dic
-	 *            the dictionary to print
-	 * @param title
-	 *            the header to print above the key/value pairs
-	 */
-	public void printDictionary(Dictionary<?, ?> dic, String title) {
-		if (dic == null) {
-			return;
-		}
-
-		int count = dic.size();
-		String[] keys = new String[count];
-		Enumeration<?> keysEnum = dic.keys();
-		int i = 0;
-		while (keysEnum.hasMoreElements()) {
-			keys[i++] = (String) keysEnum.nextElement();
-		}
-		Util.sortByString(keys);
-
-		if (title != null) {
-			println(title);
-		}
-		for (i = 0; i < count; i++) {
-			println(" " + keys[i] + " = " + dic.get(keys[i])); //$NON-NLS-1$//$NON-NLS-2$
-		}
-		println();
-	}
-
-	/**
-	 * Prints the given bundle resource if it exists
-	 * 
-	 * @param bundle
-	 *            the bundle containing the resource
-	 * @param resource
-	 *            the resource to print
-	 */
-	public void printBundleResource(Bundle bundle, String resource) {
-		URL entry = null;
-		entry = bundle.getEntry(resource);
-		if (entry != null) {
-			try {
-				println(resource);
-				InputStream in = entry.openStream();
-				byte[] buffer = new byte[1024];
-				int read = 0;
-				try {
-					while ((read = in.read(buffer)) != -1) {
-						print(new String(buffer, 0, read));
-					}
-				} finally {
-					if (in != null) {
-						try {
-							in.close();
-						} catch (IOException e) {
-						}
-					}
-				}
-			} catch (Exception e) {
-				System.err.println(NLS.bind(ConsoleMsg.CONSOLE_ERROR_READING_RESOURCE, resource));
-			}
-		} else {
-			println(NLS.bind(ConsoleMsg.CONSOLE_RESOURCE_NOT_IN_BUNDLE, resource, bundle.toString()));
-		}
-	}
-
-	/**
-	 * Answer a string (may be as many lines as you like) with help texts that explain the command.
-	 */
-	public String getHelp() {
-		StringBuffer help = new StringBuffer(256);
-		help.append(ConsoleMsg.CONSOLE_HELP_CONTROLLING_CONSOLE_HEADING);
-		help.append(newline);
-		help.append(tab);
-		help.append("more - "); //$NON-NLS-1$
-		help.append(ConsoleMsg.CONSOLE_HELP_MORE);
-		help.append(newline);
-		return help.toString();
-	}
-
-}
diff --git a/org.eclipse.virgo.ide.management.remote/src/org/eclipse/virgo/ide/management/remote/StandardBundleAdmin.java b/org.eclipse.virgo.ide.management.remote/src/org/eclipse/virgo/ide/management/remote/StandardBundleAdmin.java
index cf90105..f762aee 100644
--- a/org.eclipse.virgo.ide.management.remote/src/org/eclipse/virgo/ide/management/remote/StandardBundleAdmin.java
+++ b/org.eclipse.virgo.ide.management.remote/src/org/eclipse/virgo/ide/management/remote/StandardBundleAdmin.java
@@ -7,28 +7,29 @@
  * 
  * Contributors:
  *     SpringSource, a divison of VMware, Inc. - initial API and implementation
+ *     SAP AG - support for new equinox console
  *******************************************************************************/
 package org.eclipse.virgo.ide.management.remote;
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
+import java.io.PrintStream;
+import java.io.StringBufferInputStream;
 import java.util.Arrays;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.felix.service.command.CommandProcessor;
+import org.apache.felix.service.command.CommandSession;
 import org.eclipse.gemini.blueprint.util.OsgiServiceReferenceUtils;
-import org.eclipse.osgi.framework.console.CommandProvider;
-import org.eclipse.osgi.framework.internal.core.Util;
 import org.eclipse.osgi.service.resolver.BundleDescription;
 import org.eclipse.osgi.service.resolver.ExportPackageDescription;
 import org.eclipse.osgi.service.resolver.PlatformAdmin;
 import org.eclipse.virgo.ide.management.remote.ServiceReference.Type;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
-import org.osgi.service.packageadmin.PackageAdmin;
 import org.osgi.util.tracker.ServiceTracker;
 import org.springframework.jmx.export.annotation.ManagedOperation;
 import org.springframework.jmx.export.annotation.ManagedResource;
@@ -41,19 +42,16 @@
 
 	private final PlatformAdmin platformAdmin;
 
-	@SuppressWarnings("unused")
-	private final PackageAdmin packageAdmin;
-
 	private final BundleContext bundleContext;
 
-	private final ServiceTracker consoleProviderTracker;
+	private final ServiceTracker<CommandProcessor, CommandProcessor> commandProcessorTracker;
 
-	public StandardBundleAdmin(PlatformAdmin platformAdmin, PackageAdmin packageAdmin, BundleContext bundleContext) {
+	public StandardBundleAdmin(PlatformAdmin platformAdmin, /*PackageAdmin packageAdmin,*/BundleContext bundleContext) {
 		this.platformAdmin = platformAdmin;
-		this.packageAdmin = packageAdmin;
 		this.bundleContext = bundleContext;
-		this.consoleProviderTracker = new ServiceTracker(bundleContext, CommandProvider.class.getName(), null);
-		this.consoleProviderTracker.open();
+		this.commandProcessorTracker = new ServiceTracker<CommandProcessor, CommandProcessor>(bundleContext,
+				CommandProcessor.class, null);
+		this.commandProcessorTracker.open();
 	}
 
 	@ManagedOperation(description = "Stop the given bundle")
@@ -78,21 +76,32 @@
 
 	@ManagedOperation(description = "Executes the given command")
 	public String execute(String cmdLine) {
-		StringWriter writer = new StringWriter();
-		PrintWriter printWriter = new PrintWriter(writer);
+		@SuppressWarnings("deprecation")
+		StringBufferInputStream in = new StringBufferInputStream("");
+		ByteArrayOutputStream output = new ByteArrayOutputStream();
+		PrintStream out = new PrintStream(output);
+
 		try {
-			ServerCommandInterpreter interpreter = new ServerCommandInterpreter(cmdLine, getServices(), printWriter);
-			interpreter.execute(interpreter.nextArgument());
-			try {
-				writer.close();
-				printWriter.close();
-			} catch (IOException e) {
+			CommandProcessor commandProcessor = commandProcessorTracker.getService();
+			if (commandProcessor != null) {
+				CommandSession commandSession = commandProcessor.createSession(in, out, out);
+				Object result = null;
+				try {
+					result = commandSession.execute(cmdLine);
+				} catch (Exception e) {
+					e.printStackTrace(out);
+					return output.toString();
+				}
+				if (result == null) {
+					result = "";
+				}
+				return output.toString() + "\n" + result.toString();
 			}
-			return writer.toString();
+			return "No CommandProcessor registered; cannot execute commands";
 		} finally {
 			try {
-				writer.close();
-				printWriter.close();
+				out.close();
+				output.close();
 			} catch (IOException e) {
 			}
 		}
@@ -191,20 +200,6 @@
 		return bundles;
 	}
 
-	private Object[] getServices() {
-		ServiceReference[] serviceRefs = consoleProviderTracker.getServiceReferences();
-		if (serviceRefs == null) {
-			return new Object[0];
-		}
-		Util.dsort(serviceRefs, 0, serviceRefs.length);
-
-		Object[] serviceObjects = new Object[serviceRefs.length];
-		for (int i = 0; i < serviceRefs.length; i++) {
-			serviceObjects[i] = bundleContext.getService(serviceRefs[i]);
-		}
-		return serviceObjects;
-	}
-
 	private String getState(org.osgi.framework.Bundle b) {
 		switch (b.getState()) {
 		case org.osgi.framework.Bundle.ACTIVE: