diff --git a/src/etc/testcases/taskdefs/uptodate.xml b/src/etc/testcases/taskdefs/uptodate.xml
new file mode 100755
index 000000000..1521dd177
--- /dev/null
+++ b/src/etc/testcases/taskdefs/uptodate.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/org/apache/tools/ant/taskdefs/UpToDate.java b/src/main/org/apache/tools/ant/taskdefs/UpToDate.java
index c2a628182..446196bba 100644
--- a/src/main/org/apache/tools/ant/taskdefs/UpToDate.java
+++ b/src/main/org/apache/tools/ant/taskdefs/UpToDate.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,10 +25,14 @@ import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.condition.Condition;
+import org.apache.tools.ant.types.Resource;
+import org.apache.tools.ant.types.ResourceCollection;
import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.types.resources.Union;
import org.apache.tools.ant.types.Mapper;
import org.apache.tools.ant.util.FileNameMapper;
import org.apache.tools.ant.util.MergingMapper;
+import org.apache.tools.ant.util.ResourceUtils;
import org.apache.tools.ant.util.SourceFileScanner;
/**
@@ -47,6 +51,7 @@ public class UpToDate extends Task implements Condition {
private File sourceFile;
private File targetFile;
private Vector sourceFileSets = new Vector();
+ private Union sourceResources = new Union();
protected Mapper mapperElement = null;
@@ -105,6 +110,14 @@ public class UpToDate extends Task implements Condition {
sourceFileSets.addElement(fs);
}
+ /**
+ * Nested resource collections as sources.
+ * @since Ant 1.7
+ */
+ public Union createSrcResources() {
+ return sourceResources;
+ }
+
/**
* Defines the FileNameMapper to use (nested mapper element).
* @return a mapper to be configured
@@ -134,15 +147,18 @@ public class UpToDate extends Task implements Condition {
* @return true if the target(s) is/are up-to-date
*/
public boolean eval() {
- if (sourceFileSets.size() == 0 && sourceFile == null) {
+ if (sourceFileSets.size() == 0 && sourceResources.size() == 0
+ && sourceFile == null) {
throw new BuildException("At least one srcfile or a nested "
- + " element must be set.");
+ + " or element "
+ + "must be set.");
}
- if (sourceFileSets.size() > 0 && sourceFile != null) {
+ if ((sourceFileSets.size() > 0 || sourceResources.size() > 0)
+ && sourceFile != null) {
throw new BuildException("Cannot specify both the srcfile "
+ "attribute and a nested "
- + "element.");
+ + "or element.");
}
if (targetFile == null && mapperElement == null) {
@@ -163,15 +179,7 @@ public class UpToDate extends Task implements Condition {
+ " not found.");
}
- Enumeration e = sourceFileSets.elements();
boolean upToDate = true;
- while (upToDate && e.hasMoreElements()) {
- FileSet fs = (FileSet) e.nextElement();
- DirectoryScanner ds = fs.getDirectoryScanner(getProject());
- upToDate = upToDate && scanDir(fs.getDir(getProject()),
- ds.getIncludedFiles());
- }
-
if (sourceFile != null) {
if (mapperElement == null) {
upToDate = upToDate
@@ -184,6 +192,27 @@ public class UpToDate extends Task implements Condition {
mapperElement.getImplementation()).length == 0);
}
}
+
+ // filesets are separate from the rest for performance
+ // reasons. If we use the code for union below, we'll always
+ // scan all filesets, even if we know the target is out of
+ // date after the first test.
+ Enumeration e = sourceFileSets.elements();
+ while (upToDate && e.hasMoreElements()) {
+ FileSet fs = (FileSet) e.nextElement();
+ DirectoryScanner ds = fs.getDirectoryScanner(getProject());
+ upToDate = upToDate && scanDir(fs.getDir(getProject()),
+ ds.getIncludedFiles());
+ }
+
+ if (upToDate) {
+ Resource[] r = sourceResources.listResources();
+ upToDate = upToDate &&
+ (ResourceUtils.selectOutOfDateSources(this, r, getMapper(),
+ getProject()).length
+ == 0);
+ }
+
return upToDate;
}
@@ -219,16 +248,23 @@ public class UpToDate extends Task implements Condition {
*/
protected boolean scanDir(File srcDir, String[] files) {
SourceFileScanner sfs = new SourceFileScanner(this);
- FileNameMapper mapper = null;
+ FileNameMapper mapper = getMapper();
File dir = srcDir;
+ if (mapperElement == null) {
+ dir = null;
+ }
+ return sfs.restrict(files, srcDir, dir, mapper).length == 0;
+ }
+
+ private FileNameMapper getMapper() {
+ FileNameMapper mapper = null;
if (mapperElement == null) {
MergingMapper mm = new MergingMapper();
mm.setTo(targetFile.getAbsolutePath());
mapper = mm;
- dir = null;
} else {
mapper = mapperElement.getImplementation();
}
- return sfs.restrict(files, srcDir, dir, mapper).length == 0;
+ return mapper;
}
}
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/UpToDateTest.java b/src/testcases/org/apache/tools/ant/taskdefs/UpToDateTest.java
new file mode 100755
index 000000000..a321f1db0
--- /dev/null
+++ b/src/testcases/org/apache/tools/ant/taskdefs/UpToDateTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.taskdefs;
+
+import org.apache.tools.ant.BuildFileTest;
+
+public class UpToDateTest extends BuildFileTest {
+
+ public UpToDateTest(String name) {
+ super(name);
+ }
+
+ public void setUp() {
+ configureProject("src/etc/testcases/taskdefs/uptodate.xml");
+ }
+
+ public void tearDown() {
+ executeTarget("tearDown");
+ }
+
+ public void testFilesetUpToDate() {
+ expectPropertySet("testFilesetUpToDate", "foo");
+ }
+
+ public void testFilesetOutOfDate() {
+ expectPropertyUnset("testFilesetOutOfDate", "foo");
+ }
+
+ public void testRCUpToDate() {
+ expectPropertySet("testRCUpToDate", "foo");
+ }
+
+ public void testRCOutOfDate() {
+ expectPropertyUnset("testRCOutOfDate", "foo");
+ }
+}