Return-Path: Delivered-To: apmail-ant-dev-archive@www.apache.org Received: (qmail 87992 invoked from network); 29 Nov 2005 04:43:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 29 Nov 2005 04:43:27 -0000 Received: (qmail 16548 invoked by uid 500); 29 Nov 2005 04:43:25 -0000 Delivered-To: apmail-ant-dev-archive@ant.apache.org Received: (qmail 16505 invoked by uid 500); 29 Nov 2005 04:43:25 -0000 Mailing-List: contact dev-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list dev@ant.apache.org Received: (qmail 16487 invoked by uid 500); 29 Nov 2005 04:43:25 -0000 Received: (qmail 16482 invoked by uid 99); 29 Nov 2005 04:43:25 -0000 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 28 Nov 2005 20:43:24 -0800 Received: (qmail 87928 invoked by uid 65534); 29 Nov 2005 04:43:04 -0000 Message-ID: <20051129044304.87927.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: ant-cvs@apache.org From: bodewig@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 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 @@

Touch

Description

-

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 Fileset (which -also includes directories) -or a Filelist (since Ant 1.6).

+ +

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 resource and +resource collections (which also includes directories). Prior to Ant +1.7 only FileSet or Filelist +(since Ant 1.6) have been supported.

+

Parameters

@@ -25,8 +28,8 @@ - + @@ -60,15 +63,20 @@
file The name of the file.Unless a nested fileset element - or a nested filelist element has been specified.Unless a nested resource collection element + has been specified.
millis

Parameters specified as nested elements

-

fileset

-

You can use any number of nested <fileset> -elements to define the files for this task and refer to -<fileset>s defined elsewhere.

-

filelist

-

Since Ant 1.6

-

You can use any number of nested <filelist> -elements to define the files for this task and refer to -<filelist>s defined elsewhere.

+

any resource collection

+ +

You can use any number of nested resource collection elements to +define the resource for this task and refer to resources defined +elsewhere. Note: resource passed to this task must implement +the org.apache.tools.ant.types.resources.Touchable +interface, this is true for all filesystem-based resources like those +returned by path, fileset ot filelist.

+ +

For backwards compatibility directories matched by nested filesets +will be "touched" as well, use a <type> 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.

mapper

Since Ant 1.6.3, a nested 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 @@ + + + + + + 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 Fileset to add. */ public void addFileset(FileSet set) { - filesets.addElement(set); + filesets.add(set); + add(set); } /** @@ -196,7 +203,16 @@ * @param list the Filelist 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