servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ccust...@apache.org
Subject svn commit: r749203 - /servicemix/smx4/kernel/trunk/gshell/gshell-osgi/src/main/java/org/apache/servicemix/kernel/gshell/osgi/ListBundles.java
Date Mon, 02 Mar 2009 06:06:56 GMT
Author: ccustine
Date: Mon Mar  2 06:06:55 2009
New Revision: 749203

URL: http://svn.apache.org/viewvc?rev=749203&view=rev
Log:
SMX4KNL-216 - Add support for fragments in osgi commands

Modified:
    servicemix/smx4/kernel/trunk/gshell/gshell-osgi/src/main/java/org/apache/servicemix/kernel/gshell/osgi/ListBundles.java

Modified: servicemix/smx4/kernel/trunk/gshell/gshell-osgi/src/main/java/org/apache/servicemix/kernel/gshell/osgi/ListBundles.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-osgi/src/main/java/org/apache/servicemix/kernel/gshell/osgi/ListBundles.java?rev=749203&r1=749202&r2=749203&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-osgi/src/main/java/org/apache/servicemix/kernel/gshell/osgi/ListBundles.java
(original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-osgi/src/main/java/org/apache/servicemix/kernel/gshell/osgi/ListBundles.java
Mon Mar  2 06:06:55 2009
@@ -22,6 +22,8 @@
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.startlevel.StartLevel;
+import org.osgi.service.packageadmin.PackageAdmin;
+import org.springframework.util.StringUtils;
 
 public class ListBundles extends OsgiCommandSupport {
 
@@ -53,6 +55,16 @@
         if (sl == null) {
             io.out.println("StartLevel service is unavailable.");
         }
+
+        ServiceReference pkgref = getBundleContext().getServiceReference(PackageAdmin.class.getName());
+        PackageAdmin admin = null;
+        if (pkgref != null) {
+            admin = (PackageAdmin) getBundleContext().getService(pkgref);
+            if (admin == null) {
+                io.out.println("PackageAdmin service is unavailable.");
+            }
+        }
+
         Bundle[] bundles = getBundleContext().getBundles();
         if (bundles != null) {
             // Display active start level.
@@ -115,11 +127,47 @@
                     + getStateString(bundles[i])
                     + "] [" + getSpringStateString(bundles[i])
                     + "] [" + level + "] " + name);
+
+                if (admin != null) {
+                    Bundle[] fragments = admin.getFragments(bundles[i]);
+                    Bundle[] hosts = admin.getHosts(bundles[i]);
+
+                    if (fragments != null) {
+                        io.out.print("                                       Fragments: ");
+                        int ii = 0;
+                        for (Bundle fragment : fragments) {
+                            ii++;
+                            io.out.print(fragment.getBundleId());
+                            if ((fragments.length > 1) && ii < (fragments.length))
{
+                                io.out.print(",");
+                            }
+                        }
+                        io.out.println();
+                    }
+
+                    if (hosts != null) {
+                        io.out.print("                                       Hosts: ");
+                        int ii = 0;
+                        for (Bundle host : hosts) {
+                            ii++;
+                            io.out.print(host.getBundleId());
+                            if ((hosts.length > 1) && ii < (hosts.length))
{
+                                io.out.print(",");
+                            }
+                        }
+                        io.out.println();
+                    }
+
+                }
             }
         }
         else {
             io.out.println("There are no installed bundles.");
         }
+
+        getBundleContext().ungetService(ref);
+        getBundleContext().ungetService(pkgref);
+
         return Result.SUCCESS;
     }
 



Mime
View raw message