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:00 UTC

[karaf-cellar] 01/02: [KARAF-6165] Fix bundle selector

This is an automated email from the ASF dual-hosted git repository.

jbonofre pushed a commit to branch cellar-4.1.x
in repository https://gitbox.apache.org/repos/asf/karaf-cellar.git

commit 04549fb48c83fde52cba17d6efa37f9a59d1df85
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);
                 }