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 2019/02/19 17:11:40 UTC
[karaf-cellar] 02/02: [KARAF-6165] Fix bundle selector
This is an automated email from the ASF dual-hosted git repository.
jbonofre pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/karaf-cellar.git
commit e7ef804b8e8a28e081e182d0018a73b60a872e0f
Author: Jean-Baptiste Onofré <jb...@apache.org>
AuthorDate: Tue Feb 19 18:07:09 2019 +0100
[KARAF-6165] Fix bundle selector
---
.../management/internal/CellarBundleMBeanImpl.java | 44 +++++++++++++++++-----
.../cellar/bundle/shell/BundleCommandSupport.java | 39 ++++++++++++++++---
2 files changed, 68 insertions(+), 15 deletions(-)
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 @@ public class CellarBundleMBeanImpl extends StandardMBean implements CellarBundle
}
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 @@ public class CellarBundleMBeanImpl extends StandardMBean implements CellarBundle
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 @@ public class CellarBundleMBeanImpl extends StandardMBean implements CellarBundle
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 @@ public abstract class BundleCommandSupport extends CellarCommandSupport {
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 @@ public abstract class BundleCommandSupport extends CellarCommandSupport {
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);
}