Modified refresh command to accept bundle IDs.


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@547339 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/shell/src/main/java/org/apache/felix/shell/impl/RefreshCommandImpl.java b/shell/src/main/java/org/apache/felix/shell/impl/RefreshCommandImpl.java
index 247732d..b52e817 100644
--- a/shell/src/main/java/org/apache/felix/shell/impl/RefreshCommandImpl.java
+++ b/shell/src/main/java/org/apache/felix/shell/impl/RefreshCommandImpl.java
@@ -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
+}