You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2007/06/14 20:08:46 UTC

svn commit: r547339 - /felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/RefreshCommandImpl.java

Author: rickhall
Date: Thu Jun 14 11:08:45 2007
New Revision: 547339

URL: http://svn.apache.org/viewvc?view=rev&rev=547339
Log:
Modified refresh command to accept bundle IDs.

Modified:
    felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/RefreshCommandImpl.java

Modified: felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/RefreshCommandImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/RefreshCommandImpl.java?view=diff&rev=547339&r1=547338&r2=547339
==============================================================================
--- felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/RefreshCommandImpl.java (original)
+++ felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/RefreshCommandImpl.java Thu Jun 14 11:08:45 2007
@@ -19,8 +19,12 @@
 package org.apache.felix.shell.impl;
 
 import java.io.PrintStream;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.StringTokenizer;
 
 import org.apache.felix.shell.Command;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.packageadmin.PackageAdmin;
@@ -41,7 +45,7 @@
 
     public String getUsage()
     {
-        return "refresh";
+        return "refresh [<id> ...]";
     }
 
     public String getShortDescription()
@@ -51,6 +55,43 @@
 
     public void execute(String s, PrintStream out, PrintStream err)
     {
+        StringTokenizer st = new StringTokenizer(s, " ");
+
+        // Ignore the command name.
+        st.nextToken();
+
+        // Refresh the specified bundles or all if none are specified.
+        List bundleList = new ArrayList();
+        if (st.hasMoreTokens())
+        {
+            while (st.hasMoreTokens())
+            {
+                String id = st.nextToken().trim();
+
+                try
+                {
+                    long l = Long.parseLong(id);
+                    Bundle bundle = m_context.getBundle(l);
+                    if (bundle != null)
+                    {
+                        bundleList.add(bundle);
+                    }
+                    else
+                    {
+                        err.println("Bundle ID " + id + " is invalid.");
+                    }
+                }
+                catch (NumberFormatException ex)
+                {
+                    err.println("Unable to parse id '" + id + "'.");
+                }
+                catch (Exception ex)
+                {
+                    err.println(ex.toString());
+                }
+            }
+        }
+
         // Get package admin service.
         ServiceReference ref = m_context.getServiceReference(
             org.osgi.service.packageadmin.PackageAdmin.class.getName());
@@ -67,6 +108,8 @@
             return;
         }
 
-        pa.refreshPackages(null);
+        pa.refreshPackages((bundleList.size() == 0)
+            ? null
+            : (Bundle[]) bundleList.toArray(new Bundle[bundleList.size()]));
     }
-}
\ No newline at end of file
+}