ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r349641 - in /ant/core/trunk/src: etc/testcases/taskdefs/uptodate.xml main/org/apache/tools/ant/taskdefs/UpToDate.java testcases/org/apache/tools/ant/taskdefs/UpToDateTest.java
Date Tue, 29 Nov 2005 04:49:02 GMT
Author: bodewig
Date: Mon Nov 28 20:48:54 2005
New Revision: 349641

URL: http://svn.apache.org/viewcvs?rev=349641&view=rev
Log:
support for arbitrary resource collections as sources in <uptodate>

Added:
    ant/core/trunk/src/etc/testcases/taskdefs/uptodate.xml   (with props)
    ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/UpToDateTest.java   (with props)
Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/UpToDate.java

Added: ant/core/trunk/src/etc/testcases/taskdefs/uptodate.xml
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/etc/testcases/taskdefs/uptodate.xml?rev=349641&view=auto
==============================================================================
--- ant/core/trunk/src/etc/testcases/taskdefs/uptodate.xml (added)
+++ ant/core/trunk/src/etc/testcases/taskdefs/uptodate.xml Mon Nov 28 20:48:54 2005
@@ -0,0 +1,41 @@
+<project basedir=".">
+
+  <target name="setUp">
+    <touch file="source"/>
+    <sleep seconds="3"/>
+    <touch file="target"/>
+  </target>
+
+  <target name="tearDown">
+    <delete file="source"/>
+    <delete file="target"/>
+  </target>
+
+  <target name="testFilesetUpToDate" depends="setUp">
+    <uptodate property="foo" targetfile="target">
+      <srcfiles dir="." includes="source"/>
+    </uptodate>
+  </target>
+
+  <target name="testFilesetOutOfDate" depends="setUp">
+    <uptodate property="foo" targetfile="source">
+      <srcfiles dir="." includes="target"/>
+    </uptodate>
+  </target>
+
+  <target name="testRCUpToDate" depends="setUp">
+    <uptodate property="foo" targetfile="target">
+      <srcresources>
+        <fileset dir="." includes="source"/>
+      </srcresources>
+    </uptodate>
+  </target>
+
+  <target name="testRCOutOfDate" depends="setUp">
+    <uptodate property="foo" targetfile="source">
+      <srcresources>
+        <fileset dir="." includes="target"/>
+      </srcresources>
+    </uptodate>
+  </target>
+</project>
\ No newline at end of file

Propchange: ant/core/trunk/src/etc/testcases/taskdefs/uptodate.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/core/trunk/src/etc/testcases/taskdefs/uptodate.xml
------------------------------------------------------------------------------
    svn:executable = *

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/UpToDate.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/UpToDate.java?rev=349641&r1=349640&r2=349641&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/UpToDate.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/UpToDate.java Mon Nov 28 20:48:54
2005
@@ -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.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 @@
     private File sourceFile;
     private File targetFile;
     private Vector sourceFileSets = new Vector();
+    private Union sourceResources = new Union();
 
     protected Mapper mapperElement = null;
 
@@ -106,6 +111,14 @@
     }
 
     /**
+     * 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
      * @throws BuildException if more than one mapper is defined
@@ -134,15 +147,18 @@
      * @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 "
-                                     + "<srcfiles> element must be set.");
+                                     + "<srcfiles> or <srcresources> 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 <srcfiles> "
-                                     + "element.");
+                                     + "or <srcresources> element.");
         }
 
         if (targetFile == null && mapperElement == null) {
@@ -163,15 +179,7 @@
                                      + " 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 @@
                                   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 @@
      */
     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;
     }
 }

Added: ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/UpToDateTest.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/UpToDateTest.java?rev=349641&view=auto
==============================================================================
--- ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/UpToDateTest.java (added)
+++ ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/UpToDateTest.java Mon Nov 28
20:48:54 2005
@@ -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");
+    }
+}

Propchange: ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/UpToDateTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/UpToDateTest.java
------------------------------------------------------------------------------
    svn:executable = *



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message