Index: shell/osgi/src/main/java/org/apache/karaf/shell/osgi/BundlesCommand.java =================================================================== --- shell/osgi/src/main/java/org/apache/karaf/shell/osgi/BundlesCommand.java (revision 1086099) +++ shell/osgi/src/main/java/org/apache/karaf/shell/osgi/BundlesCommand.java (working copy) @@ -24,10 +24,13 @@ import org.apache.felix.gogo.commands.Option; import org.osgi.framework.Bundle; +import java.util.regex.Pattern; +import java.util.regex.Matcher; + public abstract class BundlesCommand extends OsgiCommandSupport { @Argument(index = 0, name = "ids", description = "The list of bundle IDs separated by whitespaces", required = true, multiValued = true) - List ids; + List ids; @Option(name = "--force", aliases = {}, description = "Forces the command to execute", required = false, multiValued = false) boolean force; @@ -35,15 +38,47 @@ protected Object doExecute() throws Exception { List bundles = new ArrayList(); 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); + for (String id : ids) { + //Parse id if id number like 253 + String s = "^\\d+$"; + Pattern pattern = Pattern.compile(s); + Matcher matcher = pattern.matcher(id); + if( matcher.find()){ + Long bundleId = Long.valueOf(id); + Bundle bundle = getBundleContext().getBundle(bundleId); + 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); + } } } + + //Parse id if id range like 34-91 + s = "^(\\d+)-(\\d+)$"; + pattern = Pattern.compile(s); + matcher = pattern.matcher(id); + + if(matcher.find()){ + int index = id.indexOf("-"); + Long startId = Long.valueOf(id.substring(0, index)); + Long endId = Long.valueOf(id.substring(index + 1, id.length())); + if (startId < endId) { + for(long i = startId; i <= endId; i ++){ + Bundle bundle = getBundleContext().getBundle(i); + 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); + } + } + } + } + } + + //To do parse id if regular expression on the name like osgi:start myb* or osgi:start myb*/version } } doExecute(bundles);