diff --git a/src/main/org/apache/tools/ant/taskdefs/DependSet.java b/src/main/org/apache/tools/ant/taskdefs/DependSet.java index 43bb245d6..424fc622e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/DependSet.java +++ b/src/main/org/apache/tools/ant/taskdefs/DependSet.java @@ -94,22 +94,7 @@ public class DependSet extends MatchingTask { super.add(NOT_EXISTS); } } - private static class Xest extends Sort { - private Xest(ResourceCollection rc, ResourceComparator c) { - super.add(c); - super.add(rc); - } - } - private static class Oldest extends Xest { - private Oldest(ResourceCollection rc) { - super(rc, DATE_ASC); - } - } - private static class Newest extends Xest { - private Newest(ResourceCollection rc) { - super(rc, DATE_DESC); - } - } + private static class HideMissingBasedir implements ResourceCollection { private FileSet fs; @@ -220,7 +205,7 @@ public class DependSet extends MatchingTask { log(neTargets + " nonexistent targets", Project.MSG_VERBOSE); return false; } - FileResource oldestTarget = (FileResource) (new Oldest(targets).iterator().next()); + FileResource oldestTarget = (FileResource) getOldest(targets); log(oldestTarget + " is oldest target file", Project.MSG_VERBOSE); logFuture(sources, datesel); @@ -230,7 +215,7 @@ public class DependSet extends MatchingTask { log(neSources + " nonexistent sources", Project.MSG_VERBOSE); return false; } - Resource newestSource = (Resource) (new Newest(sources).iterator().next()); + Resource newestSource = (Resource) getNewest(sources); log(newestSource.toLongString() + " is newest source", Project.MSG_VERBOSE); return oldestTarget.getLastModified() >= newestSource.getLastModified(); } @@ -243,4 +228,29 @@ public class DependSet extends MatchingTask { log("Warning: " + i.next() + " modified in the future.", Project.MSG_WARN); } } + + private Resource getXest(ResourceCollection rc, ResourceComparator c) { + Iterator i = rc.iterator(); + if (!i.hasNext()) { + return null; + + } + Resource xest = (Resource) i.next(); + while (i.hasNext()) { + Resource next = (Resource) i.next(); + if (c.compare(xest, next) < 0) { + xest = next; + } + } + return xest; + } + + private Resource getOldest(ResourceCollection rc) { + return getXest(rc, DATE_ASC); + } + + private Resource getNewest(ResourceCollection rc) { + return getXest(rc, DATE_DESC); + } + } diff --git a/src/main/org/apache/tools/ant/types/resources/Sort.java b/src/main/org/apache/tools/ant/types/resources/Sort.java index c6cb015eb..593f24f9f 100644 --- a/src/main/org/apache/tools/ant/types/resources/Sort.java +++ b/src/main/org/apache/tools/ant/types/resources/Sort.java @@ -35,6 +35,10 @@ import org.apache.tools.ant.types.resources.comparators.DelegatedResourceCompara /** * ResourceCollection that sorts another ResourceCollection. + * + * Note that Sort must not be used in cases where the ordering of the objects + * being sorted might change during the sorting process. + * * @since Ant 1.7 */ public class Sort extends BaseResourceCollectionWrapper {