You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2013/08/18 03:06:21 UTC
svn commit: r1515053 - in
/karaf/branches/karaf-2.x/shell/osgi/src/main/java/org/apache/karaf/shell/osgi:
BundleCommand.java BundleSelector.java
Author: jbonofre
Date: Sun Aug 18 01:06:21 2013
New Revision: 1515053
URL: http://svn.apache.org/r1515053
Log:
[KARAF-2443] Allow to use bundle name in bundle commands
Modified:
karaf/branches/karaf-2.x/shell/osgi/src/main/java/org/apache/karaf/shell/osgi/BundleCommand.java
karaf/branches/karaf-2.x/shell/osgi/src/main/java/org/apache/karaf/shell/osgi/BundleSelector.java
Modified: karaf/branches/karaf-2.x/shell/osgi/src/main/java/org/apache/karaf/shell/osgi/BundleCommand.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/shell/osgi/src/main/java/org/apache/karaf/shell/osgi/BundleCommand.java?rev=1515053&r1=1515052&r2=1515053&view=diff
==============================================================================
--- karaf/branches/karaf-2.x/shell/osgi/src/main/java/org/apache/karaf/shell/osgi/BundleCommand.java (original)
+++ karaf/branches/karaf-2.x/shell/osgi/src/main/java/org/apache/karaf/shell/osgi/BundleCommand.java Sun Aug 18 01:06:21 2013
@@ -23,25 +23,23 @@ import org.osgi.framework.Bundle;
public abstract class BundleCommand extends OsgiCommandSupport {
- @Argument(index = 0, name = "id", description = "The bundle ID", required = true, multiValued = false)
- long id;
+ @Argument(index = 0, name = "id", description = "The bundle ID or name or name/version", required = true, multiValued = false)
+ String id;
@Option(name = "--force", aliases = {}, description = "Forces the command to execute", required = false, multiValued = false)
boolean force;
protected Object doExecute() throws Exception {
- Bundle bundle = getBundleContext().getBundle(id);
+ BundleSelector selector = new BundleSelector(getBundleContext(), session);
+ Bundle bundle = selector.getBundle(id, force);
+
if (bundle == null) {
- System.out.println("Bundle " + id + " not found");
+ System.err.println("Bundle " + id + " not found");
return null;
}
- if (!force && Util.isASystemBundle(getBundleContext(), bundle) && !Util.accessToSystemBundleIsAllowed(bundle.getBundleId(), session)) {
- return null;
- } else {
- doExecute(bundle);
- return null;
- }
+ doExecute(bundle);
+ return null;
}
protected abstract void doExecute(Bundle bundle) throws Exception;
Modified: karaf/branches/karaf-2.x/shell/osgi/src/main/java/org/apache/karaf/shell/osgi/BundleSelector.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/shell/osgi/src/main/java/org/apache/karaf/shell/osgi/BundleSelector.java?rev=1515053&r1=1515052&r2=1515053&view=diff
==============================================================================
--- karaf/branches/karaf-2.x/shell/osgi/src/main/java/org/apache/karaf/shell/osgi/BundleSelector.java (original)
+++ karaf/branches/karaf-2.x/shell/osgi/src/main/java/org/apache/karaf/shell/osgi/BundleSelector.java Sun Aug 18 01:06:21 2013
@@ -85,6 +85,24 @@ public class BundleSelector {
return bundles;
}
+ /**
+ * Get a bundle by ID, or name, or name/version.
+ *
+ * @param id bundle ID, or name, or name/version.
+ * @param force forces the command to execute.
+ * @return the bundle or null if not found.
+ * @throws Exception
+ */
+ public Bundle getBundle(String id, boolean force) throws Exception {
+ List<String> ids = new ArrayList<String>(1);
+ ids.add(id);
+ List<Bundle> bundles = selectBundles(ids, force);
+ if (bundles.isEmpty()) {
+ return null;
+ }
+ return bundles.get(0);
+ }
+
private void addBundle(Bundle bundle, String id, boolean force, List<Bundle> bundles) throws Exception {
if (bundle == null) {
// if the bundle is null here, it's because we didn't find it