[KARAF-6165] Fix bundle selector
diff --git a/bundle/src/main/java/org/apache/karaf/cellar/bundle/management/internal/CellarBundleMBeanImpl.java b/bundle/src/main/java/org/apache/karaf/cellar/bundle/management/internal/CellarBundleMBeanImpl.java
index abd76f4..a8c03c7 100644
--- a/bundle/src/main/java/org/apache/karaf/cellar/bundle/management/internal/CellarBundleMBeanImpl.java
+++ b/bundle/src/main/java/org/apache/karaf/cellar/bundle/management/internal/CellarBundleMBeanImpl.java
@@ -535,14 +535,13 @@
}
protected void addMatchingBundles(String nameId, List<String> bundles, Map<String, ExtendedBundleState> clusterBundles) {
-
// id is a number
Pattern pattern = Pattern.compile("^\\d+$");
Matcher matcher = pattern.matcher(nameId);
if (matcher.matches()) {
- int idInt = Integer.parseInt(nameId);
+ int id = Integer.parseInt(nameId);
for (String bundle : clusterBundles.keySet()) {
- if (clusterBundles.get(bundle).getId() == idInt) {
+ if (clusterBundles.get(bundle).getId() == id) {
bundles.add(bundle);
break;
}
@@ -587,14 +586,26 @@
if (matcher.matches()) {
bundles.add(bundle);
} else {
- // no match on bundle name, fall back to symbolic name and check if it matches the regex
+ // no match on bundle name, fall back to id and check if it matches the regex
+ matcher = namePattern.matcher(bundleSplit[0]);
+ if (matcher.matches()) {
+ bundles.add(bundle);
+ }
+ }
+ } else if (state.getSymbolicName() != null) {
+ // bundle symbolic name is populated, check if it matches the regex
+ matcher = namePattern.matcher(state.getSymbolicName());
+ if (matcher.matches()) {
+ bundles.add(bundle);
+ } else {
+ // no match on bundle symbolic name, fall back to id and check if it matches the regex
matcher = namePattern.matcher(bundleSplit[0]);
if (matcher.matches()) {
bundles.add(bundle);
}
}
} else {
- // no bundle name, fall back to symbolic name and check if it matches the regex
+ // no bundle name, fall back to id and check if it matches the regex
matcher = namePattern.matcher(bundleSplit[0]);
if (matcher.matches()) {
bundles.add(bundle);
@@ -617,15 +628,30 @@
if (matcher.matches()) {
bundles.add(bundle);
} else {
- // no match on bundle name, fall back to symbolic name and check if it matches the regex
- matcher = namePattern.matcher(bundle);
+ // no match on bundle name, fall back to id and check if it matches the regex
+ String[] idSplit = bundle.split("/");
+ matcher = namePattern.matcher(idSplit[0]);
+ if (matcher.matches()) {
+ bundles.add(bundle);
+ }
+ }
+ } else if (state.getSymbolicName() != null) {
+ // bundle symbolic name is populated, check if it matches the regex
+ matcher = namePattern.matcher(state.getSymbolicName());
+ if (matcher.matches()) {
+ bundles.add(bundle);
+ } else {
+ // no match on bundle symbolic name, fall back to id and check if it matches the regex
+ String[] idSplit = bundle.split("/");
+ matcher = namePattern.matcher(idSplit[0]);
if (matcher.matches()) {
bundles.add(bundle);
}
}
} else {
- // no bundle name, fall back to symbolic name and check if it matches the regex
- matcher = namePattern.matcher(bundle);
+ // no bundle name, fall back to id and check if it matches the regex
+ String[] idSplit = bundle.split("/");
+ matcher = namePattern.matcher(idSplit[0]);
if (matcher.matches()) {
bundles.add(bundle);
}
diff --git a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/BundleCommandSupport.java b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/BundleCommandSupport.java
index be5d5df..d16806a 100644
--- a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/BundleCommandSupport.java
+++ b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/BundleCommandSupport.java
@@ -121,14 +121,26 @@
if (matcher.matches()) {
bundles.add(bundle);
} else {
- // no match on bundle name, fall back to symbolic name and check if it matches the regex
+ // no match on bundle name, fall back to id and check if it matches the regex
+ matcher = namePattern.matcher(bundleSplit[0]);
+ if (matcher.matches()) {
+ bundles.add(bundle);
+ }
+ }
+ } else if (state.getSymbolicName() != null) {
+ // bundle symbolic name is populated, check if it matches the regex
+ matcher = namePattern.matcher(state.getSymbolicName());
+ if (matcher.matches()) {
+ bundles.add(bundle);
+ } else {
+ // no match on bundle symbolic name, fall back to id and check if it matches the regex
matcher = namePattern.matcher(bundleSplit[0]);
if (matcher.matches()) {
bundles.add(bundle);
}
}
} else {
- // no bundle name, fall back to symbolic name and check if it matches the regex
+ // no bundle name, fall back to id and check if it matches the regex
matcher = namePattern.matcher(bundleSplit[0]);
if (matcher.matches()) {
bundles.add(bundle);
@@ -151,15 +163,30 @@
if (matcher.matches()) {
bundles.add(bundle);
} else {
- // no match on bundle name, fall back to symbolic name and check if it matches the regex
- matcher = namePattern.matcher(bundle);
+ // no match on bundle name, fall back to id and check if it matches the regex
+ String[] idSplit = bundle.split("/");
+ matcher = namePattern.matcher(idSplit[0]);
+ if (matcher.matches()) {
+ bundles.add(bundle);
+ }
+ }
+ } else if (state.getSymbolicName() != null) {
+ // bundle symbolic name is populated, check if it matches the regex
+ matcher = namePattern.matcher(state.getSymbolicName());
+ if (matcher.matches()) {
+ bundles.add(bundle);
+ } else {
+ // no match on bundle symbolic name, fall back to id and check if it matches the regex
+ String[] idSplit = bundle.split("/");
+ matcher = namePattern.matcher(idSplit[0]);
if (matcher.matches()) {
bundles.add(bundle);
}
}
} else {
- // no bundle name, fall back to symbolic name and check if it matches the regex
- matcher = namePattern.matcher(bundle);
+ // no bundle name, fall back to id and check if it matches the regex
+ String[] idSplit = bundle.split("/");
+ matcher = namePattern.matcher(idSplit[0]);
if (matcher.matches()) {
bundles.add(bundle);
}