You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ivy-commits@incubator.apache.org by ma...@apache.org on 2007/03/18 23:08:17 UTC
svn commit: r519726 - in /incubator/ivy/core/trunk: ./
src/java/org/apache/ivy/plugins/latest/
test/java/org/apache/ivy/plugins/latest/
Author: maartenc
Date: Sun Mar 18 16:08:16 2007
New Revision: 519726
URL: http://svn.apache.org/viewvc?view=rev&rev=519726
Log:
LatestRevisionStrategy.sort() doesn't sort as specified (IVY-435)
Modified:
incubator/ivy/core/trunk/CHANGES.txt
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/latest/AbstractLatestStrategy.java
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/latest/ComparatorLatestStrategy.java
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/latest/LatestStrategy.java
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/latest/LatestRevisionStrategyTest.java
Modified: incubator/ivy/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/CHANGES.txt?view=diff&rev=519726&r1=519725&r2=519726
==============================================================================
--- incubator/ivy/core/trunk/CHANGES.txt (original)
+++ incubator/ivy/core/trunk/CHANGES.txt Sun Mar 18 16:08:16 2007
@@ -15,7 +15,9 @@
- IMPROVE: Refactoring / documentation / test of matcher package (IVY-375) (thanks to Stephane Baillez)
- IMPROVE: Add a unit test to verify that latest.integration accepts released modules (IVY-394) (thanks to Gilles Scokart)
- IMPROVE: New "modules in use" section in console report at the end of resolve (IVY-373) (thanks to John Wiliams)
+- IMPROVE: Generated XML reports now contains more information about the resolved module (IVY-408)
+- FIX: LatestRevisionStrategy.sort() doesn't sort as specified (IVY-435)
- FIX: setting m2compatible on ibiblio resolver overwrite root and pattern settings (IVY-437)
- FIX: ivy.revision property not set correctly for second resolve (IVY-429)
- FIX: NPE when no organisation or no name is provided in module element of ivyconf (IVY-422)
Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/latest/AbstractLatestStrategy.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/latest/AbstractLatestStrategy.java?view=diff&rev=519726&r1=519725&r2=519726
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/latest/AbstractLatestStrategy.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/latest/AbstractLatestStrategy.java Sun Mar 18 16:08:16 2007
@@ -18,8 +18,8 @@
package org.apache.ivy.plugins.latest;
import java.util.Date;
-import java.util.Iterator;
import java.util.List;
+import java.util.ListIterator;
import org.apache.ivy.Ivy;
import org.apache.ivy.plugins.IvyAware;
@@ -51,8 +51,11 @@
public ArtifactInfo findLatest(ArtifactInfo[] infos, Date date) {
List l = sort(infos);
- for (Iterator iter = l.iterator(); iter.hasNext();) {
- ArtifactInfo info = (ArtifactInfo) iter.next();
+
+ // the latest revision comes last, use a ListIterator to iterate the
+ // sorted list in the reverse direction.
+ for (ListIterator iter = l.listIterator(l.size()); iter.hasPrevious();) {
+ ArtifactInfo info = (ArtifactInfo) iter.previous();
if (date == null || info.getLastModified() < date.getTime()) {
return info;
}
Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/latest/ComparatorLatestStrategy.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/latest/ComparatorLatestStrategy.java?view=diff&rev=519726&r1=519725&r2=519726
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/latest/ComparatorLatestStrategy.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/latest/ComparatorLatestStrategy.java Sun Mar 18 16:08:16 2007
@@ -21,7 +21,6 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
-import java.util.Date;
import java.util.List;
@@ -37,26 +36,6 @@
_comparator = comparator;
}
- public ArtifactInfo findLatest(ArtifactInfo[] artifacts, Date date) {
- if (artifacts == null) {
- return null;
- }
- ArtifactInfo found = null;
- for (int i = 0; i < artifacts.length; i++) {
- ArtifactInfo art = artifacts[i];
- if (found == null || _comparator.compare(art, found) > 0) {
- if (date != null) {
- long lastModified = art.getLastModified();
- if (lastModified > date.getTime()) {
- continue;
- }
- }
- found = art;
- }
- }
- return found;
- }
-
public List sort(ArtifactInfo[] infos) {
List ret = new ArrayList(Arrays.asList(infos));
Collections.sort(ret, _comparator);
Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/latest/LatestStrategy.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/latest/LatestStrategy.java?view=diff&rev=519726&r1=519725&r2=519726
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/latest/LatestStrategy.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/latest/LatestStrategy.java Sun Mar 18 16:08:16 2007
@@ -35,7 +35,7 @@
*/
ArtifactInfo findLatest(ArtifactInfo[] infos, Date date);
/**
- * Sorts the given artifacts info from the latest one to the oldest one.
+ * Sorts the given artifacts info from the oldest one to the latest one.
* The definition of 'latest' depends on the strategy itself.
* Given artifacts info are all good candidate.
* @param infos
Modified: incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/latest/LatestRevisionStrategyTest.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/latest/LatestRevisionStrategyTest.java?view=diff&rev=519726&r1=519725&r2=519726
==============================================================================
--- incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/latest/LatestRevisionStrategyTest.java (original)
+++ incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/latest/LatestRevisionStrategyTest.java Sun Mar 18 16:08:16 2007
@@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.Date;
import java.util.List;
import junit.framework.TestCase;
@@ -51,6 +52,63 @@
assertEquals(Arrays.asList(revs), shuffled);
}
+ public void testSort() {
+ ArtifactInfo[] revs = toMockAI(new String[] {
+ "0.2a",
+ "0.2_b",
+ "0.2rc1",
+ "0.2-final",
+ "1.0-dev1",
+ "1.0-dev2",
+ "1.0-alpha1",
+ "1.0-alpha2",
+ "1.0-beta1",
+ "1.0-beta2",
+ "1.0-gamma",
+ "1.0-rc1",
+ "1.0-rc2",
+ "1.0",
+ "1.0.1",
+ "2.0"
+ });
+
+ List shuffled = new ArrayList(Arrays.asList(revs));
+ ArtifactInfo[] shuffledRevs = (ArtifactInfo[]) shuffled.toArray(new ArtifactInfo[revs.length]);
+
+ LatestRevisionStrategy latestRevisionStrategy = new LatestRevisionStrategy();
+ List sorted = latestRevisionStrategy.sort(shuffledRevs);
+ assertEquals(Arrays.asList(revs), sorted);
+ }
+
+ public void testFindLatest() {
+ ArtifactInfo[] revs = toMockAI(new String[] {
+ "0.2a",
+ "0.2_b",
+ "0.2rc1",
+ "0.2-final",
+ "1.0-dev1",
+ "1.0-dev2",
+ "1.0-alpha1",
+ "1.0-alpha2",
+ "1.0-beta1",
+ "1.0-beta2",
+ "1.0-gamma",
+ "1.0-rc1",
+ "1.0-rc2",
+ "1.0",
+ "1.0.1",
+ "2.0"
+ });
+
+ List shuffled = new ArrayList(Arrays.asList(revs));
+ ArtifactInfo[] shuffledRevs = (ArtifactInfo[]) shuffled.toArray(new ArtifactInfo[revs.length]);
+
+ LatestRevisionStrategy latestRevisionStrategy = new LatestRevisionStrategy();
+ ArtifactInfo latest = latestRevisionStrategy.findLatest(shuffledRevs, new Date());
+ assertNotNull(latest);
+ assertEquals("2.0", latest.getRevision());
+ }
+
public void testSpecialMeaningComparator() {
ArtifactInfo[] revs = toMockAI(new String[] {
"0.1",
@@ -97,6 +155,9 @@
return _lastModified;
}
+ public String toString() {
+ return _rev;
+ }
}
private ArtifactInfo[] toMockAI(String[] revs) {
ArtifactInfo[] artifactInfos = new ArtifactInfo[revs.length];
Re: svn commit: r519726 - in /incubator/ivy/core/trunk: ./ src/java/org/apache/ivy/plugins/latest/ test/java/org/apache/ivy/plugins/latest/
Posted by Xavier Hanin <xa...@gmail.com>.
On 3/19/07, maartenc@apache.org <ma...@apache.org> wrote:
>
> Author: maartenc
> Date: Sun Mar 18 16:08:16 2007
> New Revision: 519726
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=519726
> Log:
> LatestRevisionStrategy.sort() doesn't sort as specified (IVY-435)
>
> Modified:
> incubator/ivy/core/trunk/CHANGES.txt
>
> incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/latest/AbstractLatestStrategy.java
>
> incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/latest/ComparatorLatestStrategy.java
>
> incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/latest/LatestStrategy.java
>
> incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/latest/LatestRevisionStrategyTest.java
>
> Modified: incubator/ivy/core/trunk/CHANGES.txt
> URL:
> http://svn.apache.org/viewvc/incubator/ivy/core/trunk/CHANGES.txt?view=diff&rev=519726&r1=519725&r2=519726
>
> ==============================================================================
> --- incubator/ivy/core/trunk/CHANGES.txt (original)
> +++ incubator/ivy/core/trunk/CHANGES.txt Sun Mar 18 16:08:16 2007
> @@ -15,7 +15,9 @@
> - IMPROVE: Refactoring / documentation / test of matcher package (IVY-375)
> (thanks to Stephane Baillez)
> - IMPROVE: Add a unit test to verify that latest.integration accepts
> released modules (IVY-394) (thanks to Gilles Scokart)
> - IMPROVE: New "modules in use" section in console report at the end of
> resolve (IVY-373) (thanks to John Wiliams)
> +- IMPROVE: Generated XML reports now contains more information about the
> resolved module (IVY-408)
Are you sure you want to add this line in the CHANGES.txt as part of this
commit?
- Xavier