ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r349637 - in /ant/core/trunk: docs/manual/CoreTasks/touch.html src/etc/testcases/taskdefs/touch.xml src/main/org/apache/tools/ant/taskdefs/Touch.java src/testcases/org/apache/tools/ant/taskdefs/TouchTest.java
Date Tue, 29 Nov 2005 04:43:03 GMT
Author: bodewig
Date: Mon Nov 28 20:42:55 2005
New Revision: 349637

URL: http://svn.apache.org/viewcvs?rev=349637&view=rev
Log:
support for Touchable resource collections in <touch>

Modified:
    ant/core/trunk/docs/manual/CoreTasks/touch.html
    ant/core/trunk/src/etc/testcases/taskdefs/touch.xml
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Touch.java
    ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/TouchTest.java

Modified: ant/core/trunk/docs/manual/CoreTasks/touch.html
URL: http://svn.apache.org/viewcvs/ant/core/trunk/docs/manual/CoreTasks/touch.html?rev=349637&r1=349636&r2=349637&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/touch.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/touch.html Mon Nov 28 20:42:55 2005
@@ -10,11 +10,14 @@
 
 <h2><a name="touch">Touch</a></h2>
 <h3>Description</h3>
-<p>Changes the modification time of a file and possibly creates it at
-the same time. In addition to working with a single file, this Task
-can also work a <a href="../CoreTypes/fileset.html">Fileset</a> (which
-also includes directories)
-or a <a href="../CoreTypes/filelist.html">Filelist</a> (since Ant 1.6).</p>
+
+<p>Changes the modification time of a resource and possibly creates it
+at the same time. In addition to working with a single file, this Task
+can also work on <a href="../CoreTypes/resource.html">resource</a> and
+resource collections (which also includes directories).  Prior to Ant
+1.7 only FileSet or <a href="../CoreTypes/filelist.html">Filelist</a>
+(since Ant 1.6) have been supported.</p>
+
 <h3>Parameters</h3>
 <table border="1" cellpadding="2" cellspacing="0">
   <tr>
@@ -25,8 +28,8 @@
   <tr>
     <td valign="top">file</td>
     <td valign="top">The name of the file.</td>
-    <td valign="top" align="center">Unless a nested fileset element
-       or a nested filelist element has been specified.</td>
+    <td valign="top" align="center">Unless a nested resource collection element
+       has been specified.</td>
   </tr>
   <tr>
     <td valign="top">millis</td>
@@ -60,15 +63,20 @@
   </tr>
 </table>
 <h3>Parameters specified as nested elements</h3>
-<h4>fileset</h4>
-<p>You can use any number of nested <code>&lt;fileset&gt;</code>
-elements to define the files for this task and refer to
-<code>&lt;fileset&gt;</code>s defined elsewhere.</p>
-<h4>filelist</h4>
-<p><em>Since Ant 1.6</em></p>
-<p>You can use any number of nested <code>&lt;filelist&gt;</code>
-elements to define the files for this task and refer to
-<code>&lt;filelist&gt;</code>s defined elsewhere.</p>
+<h4>any resource collection</h4>
+
+<p>You can use any number of nested resource collection elements to
+define the resource for this task and refer to resources defined
+elsewhere.  <b>Note:</b> resource passed to this task must implement
+the <code>org.apache.tools.ant.types.resources.Touchable</code>
+interface, this is true for all filesystem-based resources like those
+returned by path, fileset ot filelist.</p>
+
+<p>For backwards compatibility directories matched by nested filesets
+will be "touched" as well, use a &lt;type&gt; selector to suppress
+this.  This only applies to filesets nested into the task directly,
+not to filesets nested into a path or any other resource
+collection.</p>
 
 <h4>mapper</h4>
 <p><em>Since Ant 1.6.3,</em> a nested <a href="../CoreTypes/mapper.html">

Modified: ant/core/trunk/src/etc/testcases/taskdefs/touch.xml
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/etc/testcases/taskdefs/touch.xml?rev=349637&r1=349636&r2=349637&view=diff
==============================================================================
--- ant/core/trunk/src/etc/testcases/taskdefs/touch.xml (original)
+++ ant/core/trunk/src/etc/testcases/taskdefs/touch.xml Mon Nov 28 20:42:55 2005
@@ -53,6 +53,12 @@
     </touch>
   </target>
 
+  <target name="testResourceCollection">
+    <touch millis="1662256000000">
+      <file file="touchtest"/>
+    </touch>
+  </target>
+
   <target name="testMappedFileset">
     <touch file="touchtest" millis="${mappermillis}" />
     <touch>

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Touch.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Touch.java?rev=349637&r1=349636&r2=349637&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Touch.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Touch.java Mon Nov 28 20:42:55 2005
@@ -22,6 +22,7 @@
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.Iterator;
 import java.util.Locale;
 import java.util.Vector;
 import org.apache.tools.ant.BuildException;
@@ -31,6 +32,11 @@
 import org.apache.tools.ant.types.Mapper;
 import org.apache.tools.ant.types.FileSet;
 import org.apache.tools.ant.types.FileList;
+import org.apache.tools.ant.types.Resource;
+import org.apache.tools.ant.types.ResourceCollection;
+import org.apache.tools.ant.types.resources.FileResource;
+import org.apache.tools.ant.types.resources.Touchable;
+import org.apache.tools.ant.types.resources.Union;
 import org.apache.tools.ant.util.FileUtils;
 import org.apache.tools.ant.util.FileNameMapper;
 
@@ -78,7 +84,7 @@
     private long millis = -1;
     private String dateTime;
     private Vector filesets = new Vector();
-    private Vector filelists = new Vector();
+    private Union resources = new Union();
     private boolean dateTimeConfigured;
     private boolean mkdirs;
     private boolean verbose = true;
@@ -188,7 +194,8 @@
      * @param set the <code>Fileset</code> to add.
      */
     public void addFileset(FileSet set) {
-        filesets.addElement(set);
+        filesets.add(set);
+        add(set);
     }
 
     /**
@@ -196,7 +203,16 @@
      * @param list the <code>Filelist</code> to add.
      */
     public void addFilelist(FileList list) {
-        filelists.addElement(list);
+        add(list);
+    }
+
+    /**
+     * Add a collection of resources to touch.
+     *
+     * @since Ant 1.7
+     */
+    public void add(ResourceCollection rc) {
+        resources.add(rc);
     }
 
     /**
@@ -205,12 +221,12 @@
      * @since Ant 1.6.3
      */
     protected synchronized void checkConfiguration() throws BuildException {
-        if (file == null && filesets.size() + filelists.size() == 0) {
+        if (file == null && resources.size() == 0) {
             throw new BuildException("Specify at least one source"
-                                   + "--a file, filelist or a fileset.");
+                                   + "--a file or resource collection.");
         }
         if (file != null && file.exists() && file.isDirectory()) {
-            throw new BuildException("Use a fileset to touch directories.");
+            throw new BuildException("Use a resource collection to touch directories.");
         }
         if (dateTime != null && !dateTimeConfigured) {
             long workmillis = millis;
@@ -266,33 +282,31 @@
         long defaultTimestamp = getTimestamp();
 
         if (file != null) {
-            touch(file.getParentFile(), file.getName(), defaultTimestamp);
+            touch(new FileResource(file.getParentFile(), file.getName()),
+                  defaultTimestamp);
         }
-        // deal with the filesets
+        // deal with the resource collections
+        Iterator iter = resources.iterator();
+        while (iter.hasNext()) {
+            Resource r = (Resource) iter.next();
+            if (!(r instanceof Touchable)) {
+                throw new BuildException("Can't touch " + r);
+            }
+            touch(r, defaultTimestamp);
+        }
+
+        // deal with filesets in a special way since the task
+        // originally also used the directories and Union won't return
+        // them.
         for (int i = 0; i < filesets.size(); i++) {
             FileSet fs = (FileSet) filesets.elementAt(i);
             DirectoryScanner ds = fs.getDirectoryScanner(getProject());
             File fromDir = fs.getDir(getProject());
 
-            String[] srcFiles = ds.getIncludedFiles();
             String[] srcDirs = ds.getIncludedDirectories();
 
-            for (int j = 0; j < srcFiles.length; j++) {
-                touch(fromDir, srcFiles[j], defaultTimestamp);
-            }
             for (int j = 0; j < srcDirs.length; j++) {
-                touch(fromDir, srcDirs[j], defaultTimestamp);
-            }
-        }
-        // deal with the filelists
-        for (int i = 0; i < filelists.size(); i++) {
-            FileList fl = (FileList) filelists.elementAt(i);
-            File fromDir = fl.getDir(getProject());
-
-            String[] srcFiles = fl.getFiles(getProject());
-
-            for (int j = 0; j < srcFiles.length; j++) {
-                touch(fromDir, srcFiles[j], defaultTimestamp);
+                touch(new FileResource(fromDir, srcDirs[j]), defaultTimestamp);
             }
         }
     }
@@ -313,14 +327,19 @@
         return (millis < 0) ? System.currentTimeMillis() : millis;
     }
 
-    private void touch(File fromDir, String filename, long defaultTimestamp) {
-        File f = FILE_UTILS.resolveFile(fromDir, filename);
+    private void touch(Resource r, long defaultTimestamp) {
         if (fileNameMapper == null) {
-            touch(f, defaultTimestamp);
+            if (r instanceof FileResource) {
+                // use this to create file and deal with non-writable files
+                touch(((FileResource) r).getFile(), defaultTimestamp);
+            } else {
+                ((Touchable) r).touch(defaultTimestamp);
+            }
         } else {
-            String[] mapped = fileNameMapper.mapFileName(filename);
+            String[] mapped = fileNameMapper.mapFileName(r.getName());
             if (mapped != null && mapped.length > 0) {
-                long modTime = (f.exists()) ? f.lastModified() : defaultTimestamp;
+                long modTime = (r.isExists()) ? r.getLastModified()
+                    : defaultTimestamp;
                 for (int i = 0; i < mapped.length; i++) {
                     touch(getProject().resolveFile(mapped[i]), modTime);
                 }

Modified: ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/TouchTest.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/TouchTest.java?rev=349637&r1=349636&r2=349637&view=diff
==============================================================================
--- ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/TouchTest.java (original)
+++ ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/TouchTest.java Mon Nov 28 20:42:55
2005
@@ -106,6 +106,13 @@
     }
 
     /**
+     * test the resource collection
+     */
+    public void testResourceCollection() {
+        touchFile("testResourceCollection", 1662256000000L);
+    }
+
+    /**
      * test the mapped file set
      */
     public void testMappedFileset() {



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


Mime
View raw message