brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [25/27] brooklyn-server git commit: address PR comment about sort order in BundleFinder
Date Fri, 30 Jun 2017 14:03:13 GMT
address PR comment about sort order in BundleFinder


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/7a6e06f8
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/7a6e06f8
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/7a6e06f8

Branch: refs/heads/master
Commit: 7a6e06f83d62138d08c33eaf6cd02dd8512e61ab
Parents: e742da7
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Fri Jun 30 14:56:13 2017 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Fri Jun 30 14:56:13 2017 +0100

----------------------------------------------------------------------
 .../org/apache/brooklyn/util/core/osgi/Osgis.java | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/7a6e06f8/core/src/main/java/org/apache/brooklyn/util/core/osgi/Osgis.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/osgi/Osgis.java b/core/src/main/java/org/apache/brooklyn/util/core/osgi/Osgis.java
index c1a40f8..c6f66a7 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/osgi/Osgis.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/osgi/Osgis.java
@@ -41,7 +41,9 @@ import org.apache.brooklyn.util.osgi.OsgiUtils;
 import org.apache.brooklyn.util.osgi.VersionedName;
 import org.apache.brooklyn.util.stream.Streams;
 import org.apache.brooklyn.util.text.BrooklynVersionSyntax;
+import org.apache.brooklyn.util.text.NaturalOrderComparator;
 import org.apache.brooklyn.util.text.Strings;
+import org.apache.brooklyn.util.text.VersionComparator;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Version;
@@ -152,7 +154,17 @@ public class Osgis {
             if (requireExactlyOne && result.size()>1)
                 return Maybe.absent("Multiple bundles ("+result.size()+") matching "+getConstraintsDescription());
             
-            return Maybe.of(result.get(0));
+            // take the highest version of the first symbolic name alphabetically
+            Bundle r1 = result.get(0);
+            for (int i=1; i<result.size(); i++) {
+                if (result.get(i).getSymbolicName().equals(r1.getSymbolicName())) {
+                    r1 = result.get(i);
+                } else {
+                    // was in order so no more symbolic names
+                    break;
+                }
+            }
+            return Maybe.of(r1);
         }
         
         /** Finds all matching bundles, in decreasing version order. */
@@ -212,7 +224,9 @@ public class Osgis {
             Collections.sort(result, new Comparator<Bundle>() {
                 @Override
                 public int compare(Bundle o1, Bundle o2) {
-                    return o2.getVersion().compareTo(o1.getVersion());
+                    int r = NaturalOrderComparator.INSTANCE.compare(o1.getSymbolicName(),
o2.getSymbolicName());
+                    if (r!=0) return r;
+                    return VersionComparator.INSTANCE.compare(o1.getVersion().toString(),
o2.getVersion().toString());
                 }
             });
             


Mime
View raw message