You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2016/09/07 09:47:24 UTC

karaf git commit: KARAF-4692 - Inconsistent behavior towards Bundle-ManifestVersion

Repository: karaf
Updated Branches:
  refs/heads/master b48888370 -> 7cc5f5032


KARAF-4692 - Inconsistent behavior towards Bundle-ManifestVersion

Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/7cc5f503
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/7cc5f503
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/7cc5f503

Branch: refs/heads/master
Commit: 7cc5f503262fad511ccac083606b1e92047c02bd
Parents: b488883
Author: Guillaume Nodet <gn...@apache.org>
Authored: Wed Sep 7 11:47:12 2016 +0200
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Wed Sep 7 11:47:12 2016 +0200

----------------------------------------------------------------------
 .../apache/karaf/bundle/command/Install.java    | 26 +++++++++++++++++---
 1 file changed, 22 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/7cc5f503/bundle/core/src/main/java/org/apache/karaf/bundle/command/Install.java
----------------------------------------------------------------------
diff --git a/bundle/core/src/main/java/org/apache/karaf/bundle/command/Install.java b/bundle/core/src/main/java/org/apache/karaf/bundle/command/Install.java
index 63fdb0a..1a8701f 100644
--- a/bundle/core/src/main/java/org/apache/karaf/bundle/command/Install.java
+++ b/bundle/core/src/main/java/org/apache/karaf/bundle/command/Install.java
@@ -33,6 +33,8 @@ import org.apache.karaf.shell.support.MultiException;
 import org.apache.karaf.util.jaas.JaasHelper;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
 import org.osgi.framework.startlevel.BundleStartLevel;
 
 @Command(scope = "bundle", name = "install", description = "Installs one or more bundles.")
@@ -50,6 +52,9 @@ public class Install implements Action {
     
     @Option(name = "--force", aliases = {"-f"}, description = "Forces the command to execute", required = false, multiValued = false)
     boolean force;
+
+    @Option(name = "--r3-bundles", description = "Allow OSGi R3 bundles")
+    boolean allowR3;
     
     @Reference
     Session session;
@@ -71,13 +76,26 @@ public class Install implements Action {
             }
         }
         // install the bundles
+        boolean r3warned = false;
         List<Exception> exceptions = new ArrayList<>();
         List<Bundle> bundles = new ArrayList<>();
         for (URI url : urls) {
             try {
-                bundles.add(bundleContext.installBundle(url.toString(), null));
+                Bundle bundle = bundleContext.installBundle(url.toString(), null);
+                if (!"2".equals(bundle.getHeaders().get(Constants.BUNDLE_MANIFESTVERSION))) {
+                    if (allowR3) {
+                        if (!r3warned) {
+                            System.err.println("WARNING: use of OSGi r3 bundles is discouraged");
+                            r3warned = true;
+                        }
+                    } else {
+                        bundle.uninstall();
+                        throw new BundleException("OSGi R3 bundle not supported");
+                    }
+                }
+                bundles.add(bundle);
             } catch (Exception e) {
-                exceptions.add(new Exception("Unable to install bundle " + url, e));
+                exceptions.add(new Exception("Unable to install bundle " + url + ": " + e.toString(), e));
             }
         }
         // optionally set start level
@@ -86,7 +104,7 @@ public class Install implements Action {
                 try {
                     bundle.adapt(BundleStartLevel.class).setStartLevel(level);
                 } catch (Exception e) {
-                    exceptions.add(new Exception("Unable to set bundle start level " + bundle.getLocation(), e));
+                    exceptions.add(new Exception("Unable to set bundle start level " + bundle.getLocation() + ": " + e.toString(), e));
                 }
             }
         }
@@ -96,7 +114,7 @@ public class Install implements Action {
                 try {
                     bundle.start();
                 } catch (Exception e) {
-                    exceptions.add(new Exception("Unable to start bundle " + bundle.getLocation(), e));
+                    exceptions.add(new Exception("Unable to start bundle " + bundle.getLocation() + ": " + e.toString(), e));
                 }
             }
         }