ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r806442 - in /ant/core/trunk/src: main/org/apache/tools/ant/taskdefs/Delete.java tests/antunit/taskdefs/copy-test.xml tests/antunit/taskdefs/delete-test.xml tests/antunit/taskdefs/move-test.xml
Date Fri, 21 Aug 2009 07:59:55 GMT
Author: bodewig
Date: Fri Aug 21 07:59:55 2009
New Revision: 806442

URL: http://svn.apache.org/viewvc?rev=806442&view=rev
Log:
delete was scanning the same fileset three times, making modified selector useless.  PR 43574

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Delete.java
    ant/core/trunk/src/tests/antunit/taskdefs/copy-test.xml
    ant/core/trunk/src/tests/antunit/taskdefs/delete-test.xml
    ant/core/trunk/src/tests/antunit/taskdefs/move-test.xml

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Delete.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Delete.java?rev=806442&r1=806441&r2=806442&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Delete.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Delete.java Fri Aug 21 07:59:55
2009
@@ -597,15 +597,30 @@
                 fs = (FileSet) fs.clone();
                 fs.setProject(getProject());
             }
-            File fsDir = fs.getDir();
+            final File fsDir = fs.getDir();
             if (fsDir == null) {
                 throw new BuildException(
                         "File or Resource without directory or file specified");
             } else if (!fsDir.isDirectory()) {
                 handle("Directory does not exist: " + fsDir);
             } else {
-                resourcesToDelete.add(fs);
                 DirectoryScanner ds = fs.getDirectoryScanner();
+                // the previous line has already scanned the
+                // filesystem, in order to avoid a rescan when later
+                // iterating, capture the results now and store them
+                final String[] files = ds.getIncludedFiles();
+                resourcesToDelete.add(new ResourceCollection() {
+                        public boolean isFilesystemOnly() {
+                            return true;
+                        }
+                        public int size() {
+                            return files.length;
+                        }
+                        public Iterator iterator() {
+                            return new FileResourceIterator(getProject(),
+                                                            fsDir, files);
+                        }
+                    });
                 if (includeEmpty) {
                     filesetDirs.add(new ReverseDirs(getProject(), fsDir,
                                                     ds

Modified: ant/core/trunk/src/tests/antunit/taskdefs/copy-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/copy-test.xml?rev=806442&r1=806441&r2=806442&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/copy-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/copy-test.xml Fri Aug 21 07:59:55 2009
@@ -150,4 +150,42 @@
       </copy>
     </au:expectfailure>
   </target>
+
+  <target name="testNotModifiedSelector"
+          description="https://issues.apache.org/bugzilla/show_bug.cgi?id=43574"
+          >
+    <mkdir dir="${input}/images"/>
+    <mkdir dir="${input}/cache"/>
+    <touch file="${input}/images/foo.jpg"/>
+    <mkdir dir="${output}"/>
+    <selector id="cache.selector">
+      <not>
+        <modified update="true"
+                  seldirs="false"
+                  cache="propertyfile"
+                  algorithm="digest"
+                  comparator="equal">
+          <param name="cache.cachefile"
+                 value="${input}/cache/cache.properties"/>
+          <param name="algorithm.algorithm" value="MD5"/>
+        </modified>
+      </not>
+    </selector>
+    <au:assertFileDoesntExist file="${input}/cache/cache.properties"/>
+    <copy todir="${output}" overwrite="true">
+      <fileset dir="${input}/images">
+        <include name="*.jpg" />
+        <selector refid="cache.selector" />
+      </fileset>
+    </copy>
+    <au:assertFileExists file="${input}/cache/cache.properties"/>
+    <au:assertFileDoesntExist file="${output}/foo.jpg"/>
+    <copy todir="${output}" overwrite="true">
+      <fileset dir="${input}/images">
+        <include name="*.jpg" />
+        <selector refid="cache.selector" />
+      </fileset>
+    </copy>
+    <au:assertFileExists file="${output}/foo.jpg"/>
+  </target>
 </project>

Modified: ant/core/trunk/src/tests/antunit/taskdefs/delete-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/delete-test.xml?rev=806442&r1=806441&r2=806442&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/delete-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/delete-test.xml Fri Aug 21 07:59:55 2009
@@ -94,4 +94,41 @@
     <touch file="${output}/foo"/>
     <au:assertFileDoesntExist file="${output}/link" />
   </target>
+
+  <target name="testNotModifiedSelector"
+          description="https://issues.apache.org/bugzilla/show_bug.cgi?id=43574"
+          >
+    <mkdir dir="${input}/images"/>
+    <mkdir dir="${input}/cache"/>
+    <touch file="${input}/images/foo.jpg"/>
+    <selector id="cache.selector">
+      <not>
+        <modified update="true"
+                  seldirs="false"
+                  cache="propertyfile"
+                  algorithm="digest"
+                  comparator="equal">
+          <param name="cache.cachefile"
+                 value="${input}/cache/cache.properties"/>
+          <param name="algorithm.algorithm" value="MD5"/>
+        </modified>
+      </not>
+    </selector>
+    <au:assertFileDoesntExist file="${input}/cache/cache.properties"/>
+    <delete>
+      <fileset dir="${input}/images">
+        <include name="*.jpg" />
+        <selector refid="cache.selector" />
+      </fileset>
+    </delete>
+    <au:assertFileExists file="${input}/cache/cache.properties"/>
+    <au:assertFileExists file="${input}/images/foo.jpg"/>
+    <delete>
+      <fileset dir="${input}/images">
+        <include name="*.jpg" />
+        <selector refid="cache.selector" />
+      </fileset>
+    </delete>
+    <au:assertFileDoesntExist file="${input}/images/foo.jpg"/>
+  </target>
 </project>

Modified: ant/core/trunk/src/tests/antunit/taskdefs/move-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/move-test.xml?rev=806442&r1=806441&r2=806442&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/move-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/move-test.xml Fri Aug 21 07:59:55 2009
@@ -59,4 +59,43 @@
     <au:assertFileExists file="${output}/foo/bar/baz.txt"/>
   </target>
 
+  <target name="testNotModifiedSelector"
+          description="https://issues.apache.org/bugzilla/show_bug.cgi?id=43574"
+          >
+    <mkdir dir="${input}/images"/>
+    <mkdir dir="${input}/cache"/>
+    <touch file="${input}/images/foo.jpg"/>
+    <mkdir dir="${output}"/>
+    <selector id="cache.selector">
+      <not>
+        <modified update="true"
+                  seldirs="false"
+                  cache="propertyfile"
+                  algorithm="digest"
+                  comparator="equal">
+          <param name="cache.cachefile"
+                 value="${input}/cache/cache.properties"/>
+          <param name="algorithm.algorithm" value="MD5"/>
+        </modified>
+      </not>
+    </selector>
+    <au:assertFileDoesntExist file="${input}/cache/cache.properties"/>
+    <move todir="${output}" overwrite="true">
+      <fileset dir="${input}/images">
+        <include name="*.jpg" />
+        <selector refid="cache.selector" />
+      </fileset>
+    </move>
+    <au:assertFileExists file="${input}/cache/cache.properties"/>
+    <au:assertFileExists file="${input}/images/foo.jpg"/>
+    <au:assertFileDoesntExist file="${output}/foo.jpg"/>
+    <move todir="${output}" overwrite="true">
+      <fileset dir="${input}/images">
+        <include name="*.jpg" />
+        <selector refid="cache.selector" />
+      </fileset>
+    </move>
+    <au:assertFileDoesntExist file="${input}/images/foo.jpg"/>
+    <au:assertFileExists file="${output}/foo.jpg"/>
+  </target>
 </project>



Mime
View raw message