karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jans...@apache.org
Subject git commit: KARAF-2917 - Command to display bundle id
Date Wed, 16 Apr 2014 23:13:18 GMT
Repository: karaf
Updated Branches:
  refs/heads/master 63a79b5d0 -> 40ae90f9a


KARAF-2917 - Command to display bundle id


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

Branch: refs/heads/master
Commit: 40ae90f9a574386db15365254aef7161eec1664a
Parents: 63a79b5
Author: Jonathan Anstey <janstey@gmail.com>
Authored: Wed Apr 16 20:42:55 2014 -0230
Committer: Jonathan Anstey <janstey@gmail.com>
Committed: Wed Apr 16 20:42:55 2014 -0230

----------------------------------------------------------------------
 .../karaf/bundle/command/BundleCommand.java     |  2 +
 .../org/apache/karaf/bundle/command/Id.java     | 76 ++++++++++++++++++++
 .../bundle/core/internal/BundleServiceImpl.java |  3 +-
 3 files changed, 79 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/40ae90f9/bundle/core/src/main/java/org/apache/karaf/bundle/command/BundleCommand.java
----------------------------------------------------------------------
diff --git a/bundle/core/src/main/java/org/apache/karaf/bundle/command/BundleCommand.java
b/bundle/core/src/main/java/org/apache/karaf/bundle/command/BundleCommand.java
index dce0ca8..e7ce42a 100644
--- a/bundle/core/src/main/java/org/apache/karaf/bundle/command/BundleCommand.java
+++ b/bundle/core/src/main/java/org/apache/karaf/bundle/command/BundleCommand.java
@@ -56,6 +56,8 @@ public abstract class BundleCommand implements Action {
             } else {
                 System.err.println("Access to system bundle " + id + " is discouraged. You
may override with -f");
             }
+        } else {
+            System.err.println("Bundle " + id + " is not found");
         }
         return null;
     }

http://git-wip-us.apache.org/repos/asf/karaf/blob/40ae90f9/bundle/core/src/main/java/org/apache/karaf/bundle/command/Id.java
----------------------------------------------------------------------
diff --git a/bundle/core/src/main/java/org/apache/karaf/bundle/command/Id.java b/bundle/core/src/main/java/org/apache/karaf/bundle/command/Id.java
new file mode 100644
index 0000000..1e346b3
--- /dev/null
+++ b/bundle/core/src/main/java/org/apache/karaf/bundle/command/Id.java
@@ -0,0 +1,76 @@
+/*
+ * 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.karaf.bundle.command;
+
+import java.util.List;
+
+import org.apache.karaf.bundle.core.BundleService;
+import org.apache.karaf.shell.api.action.Action;
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.support.ShellUtil;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+@Command(scope = "bundle", name = "id", description = "Gets the bundle ID.")
+@Service
+public class Id implements Action {
+
+    @Argument(index = 0, name = "name", description = "The bundle name, name/version, or
location", required = true, multiValued = false)
+    String name;
+
+    @Reference
+    BundleService bundleService;
+
+    @Reference
+    BundleContext bundleContext;
+
+    public Object execute() throws Exception {
+        return doExecute(true);
+    }
+
+    protected Object doExecute(boolean force) throws Exception {
+        Bundle bundle = bundleService.getBundle(name, true);
+        
+        // if name or name/version were not successful, let's try searching by location
+        if (bundle == null) {
+            for (int i = 0; i < bundleContext.getBundles().length; i++) {
+                Bundle b = bundleContext.getBundles()[i];
+                if (name.equals(b.getLocation())) {
+                    bundle = b;
+                    break;
+                }
+            }
+        }
+        if (bundle != null) {            
+            if (force || !ShellUtil.isASystemBundle(bundleContext, bundle)) {           
    
+                return bundle.getBundleId();
+            } else {
+                System.err.println("Access to system bundle " + name + " is discouraged.
You may override with -f");
+            }
+        } else {
+            System.err.println("Bundle " + name + " is not found");
+        }
+        return null;
+    }
+
+    public void setBundleService(BundleService bundleService) {
+        this.bundleService = bundleService;
+    }
+}

http://git-wip-us.apache.org/repos/asf/karaf/blob/40ae90f9/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundleServiceImpl.java
----------------------------------------------------------------------
diff --git a/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundleServiceImpl.java
b/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundleServiceImpl.java
index fbf047f..69861e1 100644
--- a/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundleServiceImpl.java
+++ b/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundleServiceImpl.java
@@ -79,8 +79,7 @@ public class BundleServiceImpl implements BundleService {
         List<String> ids = new ArrayList<String>(1);
         ids.add(id);
         List<Bundle> bundles = selectBundles(ids, defaultAllBundles);
-        if (bundles.isEmpty()) {
-            System.err.println("Bundle " + id + " is not found");
+        if (bundles.isEmpty()) {            
             return null;
         } else {
             return bundles.get(0);


Mime
View raw message