felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r945083 - in /felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi: BundlesCommandOptional.java RefreshBundle.java ResolveBundle.java RestartBundle.java UninstallBundle.java
Date Mon, 17 May 2010 11:14:12 GMT
Author: gnodet
Date: Mon May 17 11:14:12 2010
New Revision: 945083

URL: http://svn.apache.org/viewvc?rev=945083&view=rev
Log:
FELIX-2330: Uninstall, refresh, and resolve osgi shell commands do not support multiple bundle
ids

Added:
    felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi/BundlesCommandOptional.java
Modified:
    felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi/RefreshBundle.java
    felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi/ResolveBundle.java
    felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi/RestartBundle.java
    felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi/UninstallBundle.java

Added: felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi/BundlesCommandOptional.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi/BundlesCommandOptional.java?rev=945083&view=auto
==============================================================================
--- felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi/BundlesCommandOptional.java
(added)
+++ felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi/BundlesCommandOptional.java
Mon May 17 11:14:12 2010
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.felix.karaf.shell.osgi;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.felix.gogo.commands.Argument;
+import org.apache.felix.gogo.commands.Option;
+import org.apache.felix.karaf.shell.console.OsgiCommandSupport;
+import org.osgi.framework.Bundle;
+
+public abstract class BundlesCommandOptional extends OsgiCommandSupport {
+
+    @Argument(index = 0, name = "ids", description = "The list of bundle IDs separated by
whitespaces", required = false, multiValued = true)
+    List<Long> ids;
+
+    @Option(name = "--force", aliases = {}, description = "Forces the command to execute",
required = false, multiValued = false)
+    boolean force;
+
+    protected Object doExecute() throws Exception {
+        List<Bundle> bundles = new ArrayList<Bundle>();
+        if (ids != null && !ids.isEmpty()) {
+            for (long id : ids) {
+                Bundle bundle = getBundleContext().getBundle(id);
+                if (bundle == null) {
+                    System.err.println("Bundle ID" + id + " is invalid");
+                } else {
+                    if (force || !Util.isASystemBundle(getBundleContext(), bundle) || Util.accessToSystemBundleIsAllowed(bundle.getBundleId(),
session)) {
+                        bundles.add(bundle);
+                    }
+                }
+            }
+        }
+        doExecute(bundles);
+        return null;
+    }
+
+    protected abstract void doExecute(List<Bundle> bundles) throws Exception;
+}
\ No newline at end of file

Modified: felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi/RefreshBundle.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi/RefreshBundle.java?rev=945083&r1=945082&r2=945083&view=diff
==============================================================================
--- felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi/RefreshBundle.java
(original)
+++ felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi/RefreshBundle.java
Mon May 17 11:14:12 2010
@@ -16,6 +16,8 @@
  */
 package org.apache.felix.karaf.shell.osgi;
 
+import java.util.List;
+
 import org.apache.felix.karaf.shell.console.OsgiCommandSupport;
 import org.apache.felix.gogo.commands.Argument;
 import org.apache.felix.gogo.commands.Command;
@@ -24,39 +26,30 @@ import org.osgi.framework.ServiceReferen
 import org.osgi.service.packageadmin.PackageAdmin;
 
 @Command(scope = "osgi", name = "refresh", description = "Refresh a bundle")
-public class RefreshBundle extends OsgiCommandSupport {
-
-    @Argument(index = 0, name = "id", description = "The ID of the bundle to refresh", required
= false, multiValued = false)
-    Long id;
+public class RefreshBundle extends BundlesCommandOptional {
 
-    protected Object doExecute() throws Exception {
+    protected void doExecute(List<Bundle> bundles) throws Exception {
         // Get package admin service.
         ServiceReference ref = getBundleContext().getServiceReference(PackageAdmin.class.getName());
         if (ref == null) {
             System.out.println("PackageAdmin service is unavailable.");
-            return null;
+            return;
         }
         try {
             PackageAdmin pa = (PackageAdmin) getBundleContext().getService(ref);
             if (pa == null) {
                 System.out.println("PackageAdmin service is unavailable.");
-                return null;
+                return;
             }
-            if (id == null) {
+            if (bundles.isEmpty()) {
                 pa.refreshPackages(null);
             }
             else {
-                Bundle bundle = getBundleContext().getBundle(id);
-                if (bundle == null) {
-                    System.out.println("Bundle " + id + " not found");
-                    return null;
-                }
-                pa.refreshPackages(new Bundle[] { bundle });
+                pa.refreshPackages(bundles.toArray(new Bundle[bundles.size()]));
             }
         }
         finally {
             getBundleContext().ungetService(ref);
         }
-        return null;
     }
 }

Modified: felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi/ResolveBundle.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi/ResolveBundle.java?rev=945083&r1=945082&r2=945083&view=diff
==============================================================================
--- felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi/ResolveBundle.java
(original)
+++ felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi/ResolveBundle.java
Mon May 17 11:14:12 2010
@@ -16,15 +16,17 @@
  */
 package org.apache.felix.karaf.shell.osgi;
 
+import java.util.List;
+
 import org.osgi.framework.Bundle;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.packageadmin.PackageAdmin;
 import org.apache.felix.gogo.commands.Command;
 
 @Command(scope = "osgi", name = "resolve", description = "Resolve bundle(s)")
-public class ResolveBundle extends BundleCommand {
+public class ResolveBundle extends BundlesCommandOptional {
 
-    protected void doExecute(Bundle bundle) throws Exception {
+    protected void doExecute(List<Bundle> bundles) throws Exception {
         // Get package admin service.
         ServiceReference ref = getBundleContext().getServiceReference(PackageAdmin.class.getName());
         if (ref == null) {
@@ -37,7 +39,11 @@ public class ResolveBundle extends Bundl
                 System.out.println("PackageAdmin service is unavailable.");
                 return;
             }
-            pa.resolveBundles(new Bundle[] { bundle });
+            if (bundles.isEmpty()) {
+                pa.resolveBundles(null);
+            } else {
+                pa.resolveBundles(bundles.toArray(new Bundle[bundles.size()]));
+            }
         }
         finally {
             getBundleContext().ungetService(ref);

Modified: felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi/RestartBundle.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi/RestartBundle.java?rev=945083&r1=945082&r2=945083&view=diff
==============================================================================
--- felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi/RestartBundle.java
(original)
+++ felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi/RestartBundle.java
Mon May 17 11:14:12 2010
@@ -27,6 +27,8 @@ public class RestartBundle extends Bundl
     protected void doExecute(List<Bundle> bundles) throws Exception {
         for (Bundle bundle : bundles) {
             bundle.stop();
+        }
+        for (Bundle bundle : bundles) {
             bundle.start();
         }
     }

Modified: felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi/UninstallBundle.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi/UninstallBundle.java?rev=945083&r1=945082&r2=945083&view=diff
==============================================================================
--- felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi/UninstallBundle.java
(original)
+++ felix/trunk/karaf/shell/osgi/src/main/java/org/apache/felix/karaf/shell/osgi/UninstallBundle.java
Mon May 17 11:14:12 2010
@@ -16,14 +16,18 @@
  */
 package org.apache.felix.karaf.shell.osgi;
 
+import java.util.List;
+
 import org.osgi.framework.Bundle;
 import org.apache.felix.gogo.commands.Command;
 
-@Command(scope = "osgi", name = "uninstall", description = "Uninstall bundle")
-public class UninstallBundle extends BundleCommand {
+@Command(scope = "osgi", name = "uninstall", description = "Uninstall bundle(s)")
+public class UninstallBundle extends BundlesCommand {
 
-    protected void doExecute(Bundle bundle) throws Exception {
-        bundle.uninstall();
+    protected void doExecute(List<Bundle> bundles) throws Exception {
+        for (Bundle bundle : bundles) {
+            bundle.uninstall();
+        }
     }
 
 }



Mime
View raw message