You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:24:22 UTC

[sling-org-apache-sling-commons-osgi] 18/29: SLING-1278 - comparison was reversed

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

rombert pushed a commit to annotated tag org.apache.sling.commons.osgi-2.0.6
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-osgi.git

commit db6757595fa9fa07d25348cecb1c0ea9e09459bd
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Thu Jan 7 17:41:31 2010 +0000

    SLING-1278 - comparison was reversed
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/commons/osgi@896938 13f79535-47bb-0310-9956-ffa450edef68
---
 .../osgi/bundleversion/BundleVersionInfo.java      |  6 ----
 .../bundleversion/BundleVersionComparisonTest.java | 34 ++++++++++++++++------
 2 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/src/main/java/org/apache/sling/commons/osgi/bundleversion/BundleVersionInfo.java b/src/main/java/org/apache/sling/commons/osgi/bundleversion/BundleVersionInfo.java
index 983b0f0..7346ed6 100644
--- a/src/main/java/org/apache/sling/commons/osgi/bundleversion/BundleVersionInfo.java
+++ b/src/main/java/org/apache/sling/commons/osgi/bundleversion/BundleVersionInfo.java
@@ -95,9 +95,6 @@ public abstract class BundleVersionInfo<T> implements Comparable<BundleVersionIn
             } else {
                 result = va.compareTo(vb);
             }
-            
-            // more recent ones must come before older ones
-            result = -result;
         }
         
         // Then, if snapshots, compare modification times, more recent comes first
@@ -109,9 +106,6 @@ public abstract class BundleVersionInfo<T> implements Comparable<BundleVersionIn
             } else if(mb > ma) {
                 result = B_GREATER;
             }
-            
-            // more recent ones must come before older ones
-            result = -result;
         }
         
         return result;
diff --git a/src/test/java/org/apache/sling/commons/osgi/bundleversion/BundleVersionComparisonTest.java b/src/test/java/org/apache/sling/commons/osgi/bundleversion/BundleVersionComparisonTest.java
index 7f57b3f..37da592 100644
--- a/src/test/java/org/apache/sling/commons/osgi/bundleversion/BundleVersionComparisonTest.java
+++ b/src/test/java/org/apache/sling/commons/osgi/bundleversion/BundleVersionComparisonTest.java
@@ -31,19 +31,35 @@ import org.junit.Test;
 public class BundleVersionComparisonTest {
     
     @Test
+    public void testSimpleCompare() {
+        // We want more recent bundles to be "greater" than older ones
+        {
+            final MockBundleVersionInfo a = new MockBundleVersionInfo("a.name", "1.1", 1);
+            final MockBundleVersionInfo b = new MockBundleVersionInfo("a.name", "1.0", 1);
+            assertEquals("a is more recent than b", 1, a.compareTo(b));
+        }
+        {
+            final MockBundleVersionInfo a = new MockBundleVersionInfo("b", "1.2.0.SNAPSHOT", 2);
+            final MockBundleVersionInfo b = new MockBundleVersionInfo("b", "1.2.0.SNAPSHOT", 1);
+            assertEquals("SNAPSHOT a is more recent than b", 1, a.compareTo(b));
+        }
+    }
+    
+    @Test
     public void testSortBundles() {
+        // The comparator sorts bundles in ascending order
+        // of their symbolic names and versions
         final MockBundleVersionInfo [] sorted = {
-                new MockBundleVersionInfo("a.name", "1.1", 1),
                 new MockBundleVersionInfo("a.name", "1.0", 1),
-                new MockBundleVersionInfo("b", "1.2.0.SNAPSHOT", 2),
-                new MockBundleVersionInfo("b", "1.2.0.SNAPSHOT", 1),
-                new MockBundleVersionInfo("b", "1.1", 1),
-                new MockBundleVersionInfo("b", "1.0.1.SNAPSHOT", 2),
-                new MockBundleVersionInfo("b", "1.0.1.SNAPSHOT", 1),
-                new MockBundleVersionInfo("b", "1.0", 1),
-                new MockBundleVersionInfo("b", "0.9", 1),
+                new MockBundleVersionInfo("a.name", "1.1", 1),
                 new MockBundleVersionInfo("b", "0.8.1", 1),
-                new MockBundleVersionInfo("b", "0.8.0", 1)
+                new MockBundleVersionInfo("b", "0.9", 1),
+                new MockBundleVersionInfo("b", "1.0", 1),
+                new MockBundleVersionInfo("b", "1.0.1.SNAPSHOT", 1),
+                new MockBundleVersionInfo("b", "1.0.1.SNAPSHOT", 2),
+                new MockBundleVersionInfo("b", "1.1", 1),
+                new MockBundleVersionInfo("b", "1.2.0.SNAPSHOT", 1),
+                new MockBundleVersionInfo("b", "1.2.0.SNAPSHOT", 2),
         };
         
         final List<BundleVersionInfo<?>> list = new ArrayList<BundleVersionInfo<?>>();

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.