Author: bdelacretaz Date: Thu Jan 7 17:41:31 2010 New Revision: 896938 URL: http://svn.apache.org/viewvc?rev=896938&view=rev Log: SLING-1278 - comparison was reversed
Modified: sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/bundleversion/BundleVersionInfo.java sling/trunk/bundles/commons/osgi/src/test/java/org/apache/sling/commons/osgi/bundleversion/BundleVersionComparisonTest.java Modified: sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/bundleversion/BundleVersionInfo.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/bundleversion/BundleVersionInfo.java?rev=896938&r1=896937&r2=896938&view=diff ============================================================================== --- sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/bundleversion/BundleVersionInfo.java (original) +++ sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/bundleversion/BundleVersionInfo.java Thu Jan 7 17:41:31 2010 @@ -95,9 +95,6 @@ } 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 @@ } else if(mb > ma) { result = B_GREATER; } - - // more recent ones must come before older ones - result = -result; } return result; Modified: sling/trunk/bundles/commons/osgi/src/test/java/org/apache/sling/commons/osgi/bundleversion/BundleVersionComparisonTest.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/osgi/src/test/java/org/apache/sling/commons/osgi/bundleversion/BundleVersionComparisonTest.java?rev=896938&r1=896937&r2=896938&view=diff ============================================================================== --- sling/trunk/bundles/commons/osgi/src/test/java/org/apache/sling/commons/osgi/bundleversion/BundleVersionComparisonTest.java (original) +++ sling/trunk/bundles/commons/osgi/src/test/java/org/apache/sling/commons/osgi/bundleversion/BundleVersionComparisonTest.java Thu Jan 7 17:41:31 2010 @@ -31,19 +31,35 @@ 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<?>>();