Added support for Gogo shell
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@956255 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/shell/pom.xml b/dependencymanager/shell/pom.xml
index 9e120d1..43bf3cb 100644
--- a/dependencymanager/shell/pom.xml
+++ b/dependencymanager/shell/pom.xml
@@ -55,6 +55,11 @@
<artifactId>osgi</artifactId>
<version>3.1.1</version>
</dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.apache.felix.gogo.runtime</artifactId>
+ <version>0.6.0</version>
+ </dependency>
</dependencies>
<build>
<plugins>
@@ -72,7 +77,12 @@
<Bundle-Vendor>The Apache Software Foundation</Bundle-Vendor>
<Export-Package></Export-Package>
<Private-Package>org.apache.felix.dm.shell</Private-Package>
- <Import-Package>org.apache.felix.dm.management;version="[3.0.0,4.0.0)",org.apache.felix.shell;version="1.0";resolution:=optional,org.osgi.framework;version="1.3",org.eclipse.osgi.framework.console;resolution:=optional</Import-Package>
+ <Import-Package>org.apache.felix.dm.management;version="[3.0.0,4.0.0)",
+ org.apache.felix.shell;version="1.0";resolution:=optional,
+ org.osgi.framework;version="1.3",
+ org.eclipse.osgi.framework.console;resolution:=optional,
+ org.apache.felix.service.command;resolution:=optional
+ </Import-Package>
</instructions>
</configuration>
</plugin>
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 df992db..8446daf 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,6 +18,8 @@
*/
package org.apache.felix.dm.shell;
+import java.util.Hashtable;
+
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -28,18 +30,30 @@
*/
public class Activator implements BundleActivator {
public void start(BundleContext context) throws Exception {
+ // Provide DependencyManager shell commands for the old Felix Shell.
try {
context.registerService("org.apache.felix.shell.Command", new FelixDMCommand(context), null);
}
catch (Throwable t) {
}
+ // Provide DependencyManager shell commands for the Equinox Shell.
try {
context.registerService("org.eclipse.osgi.framework.console.CommandProvider", new EquinoxDMCommand(context), null);
}
catch (Throwable t) {
}
+ // Provide DependencyManager shell commands for the Gogo Shell.
+ try {
+ Hashtable props = new Hashtable();
+ props.put(org.apache.felix.service.command.CommandProcessor.COMMAND_SCOPE, "dependencymanager");
+ props.put(org.apache.felix.service.command.CommandProcessor.COMMAND_FUNCTION,
+ new String[] { "dmhelp", "dm", "dmnodeps", "dmnotavail", "dmcompact" });
+ context.registerService(GogoDMCommand.class.getName(), new GogoDMCommand(context), props);
+ }
+ catch (Throwable t) {
+ }
}
public void stop(BundleContext context) throws Exception {
- }
+ }
}
diff --git a/dependencymanager/shell/src/main/java/org/apache/felix/dm/shell/GogoDMCommand.java b/dependencymanager/shell/src/main/java/org/apache/felix/dm/shell/GogoDMCommand.java
new file mode 100644
index 0000000..64d4163
--- /dev/null
+++ b/dependencymanager/shell/src/main/java/org/apache/felix/dm/shell/GogoDMCommand.java
@@ -0,0 +1,81 @@
+package org.apache.felix.dm.shell;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.PrintStream;
+
+import org.osgi.framework.BundleContext;
+
+/**
+ * This class provides DependencyManager commands for the Gogo shell.
+ */
+public class GogoDMCommand extends DMCommand
+{
+ public GogoDMCommand(BundleContext context)
+ {
+ super(context);
+ }
+
+ public void dmhelp() {
+ System.out.println("dependencymanager:dm -> list DM component diagnostics.");
+ System.out.println("dependencymanager:dm bundleId -> list DM component diagnostics for a given bundle.");
+ System.out.println("dependencymanager:dmnotavail -> list unavailable DM components.");
+ System.out.println("dependencymanager:dmnotavail bundleId -> list unavailable DM components for a given bundle.");
+ System.out.println("dependencymanager:dmnodeps -> list DM component diagnostics without dependencies.");
+ System.out.println("dependencymanager:dmnodeps bundleId-> list DM component diagnostics without dependencies for a given bundle.");
+ System.out.println("dependencymanager:dmcompact -> list DM component compact diagnostics.");
+ System.out.println("dependencymanager:dmcompact bundleId -> list DM component compact diagnostics for a given bundle.");
+ }
+
+ public void dm() {
+ execute("dm", new String[0]);
+ }
+
+ public void dm(int bundleId) {
+ execute("dm", new String[] { String.valueOf(bundleId) });
+ }
+
+ public void dmnodeps() {
+ execute("dm nodeps", new String[0]);
+ }
+
+ public void dmnodeps(int bundleId) {
+ execute("dm nodeps", new String[] { String.valueOf(bundleId) });
+ }
+
+ public void dmnotavail() {
+ execute("dm notavail", new String[0]);
+ }
+
+ public void dmnotavail(int bundleId) {
+ execute("dm notavail", new String[] { String.valueOf(bundleId) });
+ }
+
+ public void dmcompact() {
+ execute("dm compact", new String[0]);
+ }
+
+ public void dmcompact(int bundleId) {
+ execute("dm compact", new String[] { String.valueOf(bundleId) });
+ }
+
+ private void execute(String line, String[] args) {
+ ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ ByteArrayOutputStream errorBytes = new ByteArrayOutputStream();
+ PrintStream out = new PrintStream(bytes);
+ PrintStream err = new PrintStream(errorBytes);
+
+ if (args != null && args.length > 0) {
+ line += " " + args[0]; // Add bundle Id
+ }
+
+ super.execute(line.toString(), out, err);
+ if (bytes.size() > 0) {
+ System.out.println(new String(bytes.toByteArray()));
+ }
+ if (errorBytes.size() > 0) {
+ System.out.print("Error:\n");
+ System.out.println(new String(errorBytes.toByteArray()));
+ }
+ }
+}