shell now works both in eclipse and equinox

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@888331 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/shell/src/main/java/org/apache/felix/dm/shell/Activator.java b/dependencymanager/shell/src/main/java/org/apache/felix/dm/shell/Activator.java
index 733fc8c..d30f2d1 100644
--- a/dependencymanager/shell/src/main/java/org/apache/felix/dm/shell/Activator.java
+++ b/dependencymanager/shell/src/main/java/org/apache/felix/dm/shell/Activator.java
@@ -18,10 +18,8 @@
  */
 package org.apache.felix.dm.shell;
 
-import org.apache.felix.shell.Command;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
 
 /**
  * Bundle activator for the dependency manager shell command.
@@ -29,13 +27,19 @@
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
 public class Activator implements BundleActivator {
-    private ServiceRegistration m_serviceRegistration;
-
     public void start(BundleContext context) throws Exception {
-        m_serviceRegistration = context.registerService(Command.class.getName(), new DMCommand(context), null);
+        try {
+            context.registerService("org.apache.felix.shell.Command", new DMCommand(context), null);
+        }
+        catch (Throwable t) {
+        }
+        try {
+            context.registerService("org.eclipse.osgi.framework.console.CommandProvider", new EquinoxDMCommand(context), null);
+        }
+        catch (Throwable t) {
+        }
     }
 
     public void stop(BundleContext context) throws Exception {
-        m_serviceRegistration.unregister();
     }
 }
diff --git a/dependencymanager/shell/src/main/java/org/apache/felix/dm/shell/DMCommand.java b/dependencymanager/shell/src/main/java/org/apache/felix/dm/shell/DMCommand.java
index 9923ce7..2455f42 100644
--- a/dependencymanager/shell/src/main/java/org/apache/felix/dm/shell/DMCommand.java
+++ b/dependencymanager/shell/src/main/java/org/apache/felix/dm/shell/DMCommand.java
@@ -26,7 +26,6 @@
 
 import org.apache.felix.dm.management.ServiceComponent;
 import org.apache.felix.dm.management.ServiceComponentDependency;
-import org.apache.felix.shell.Command;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
@@ -38,7 +37,7 @@
  * 
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
-public class DMCommand implements Command {
+public class DMCommand {
     private static final BundleIdSorter SORTER = new BundleIdSorter();
     private final BundleContext m_context;
 
diff --git a/dependencymanager/shell/src/main/java/org/apache/felix/dm/shell/EquinoxDMCommand.java b/dependencymanager/shell/src/main/java/org/apache/felix/dm/shell/EquinoxDMCommand.java
new file mode 100644
index 0000000..d7e1c73
--- /dev/null
+++ b/dependencymanager/shell/src/main/java/org/apache/felix/dm/shell/EquinoxDMCommand.java
@@ -0,0 +1,34 @@
+package org.apache.felix.dm.shell;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+import org.eclipse.osgi.framework.console.CommandInterpreter;
+import org.eclipse.osgi.framework.console.CommandProvider;
+import org.osgi.framework.BundleContext;
+
+public class EquinoxDMCommand extends DMCommand implements CommandProvider {
+    public EquinoxDMCommand(BundleContext context) {
+        super(context);
+    }
+    
+    public void _dm(CommandInterpreter ci) {
+        StringBuffer line = new StringBuffer("");
+        String arg = ci.nextArgument();
+        while (arg != null) {
+            if (line.length() > 0) {
+                line.append(' ');
+            }
+            line.append(arg);
+            arg = ci.nextArgument();
+        }
+        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+        ByteArrayOutputStream errorBytes = new ByteArrayOutputStream();
+        super.execute(line.toString(), new PrintStream(bytes), new PrintStream(errorBytes));
+        ci.print(new String(bytes.toByteArray()));
+    }
+
+    public String getHelp() {
+        return "\t" + super.getUsage() + " - " + super.getShortDescription() + "\n";
+    }
+}
diff --git a/dependencymanager/shell/src/main/java/org/apache/felix/dm/shell/FelixDMCommand.java b/dependencymanager/shell/src/main/java/org/apache/felix/dm/shell/FelixDMCommand.java
new file mode 100644
index 0000000..bab04b5
--- /dev/null
+++ b/dependencymanager/shell/src/main/java/org/apache/felix/dm/shell/FelixDMCommand.java
@@ -0,0 +1,10 @@
+package org.apache.felix.dm.shell;
+
+import org.apache.felix.shell.Command;
+import org.osgi.framework.BundleContext;
+
+public class FelixDMCommand extends DMCommand implements Command {
+    public FelixDMCommand(BundleContext context) {
+        super(context);
+    }
+}