Author: jkf Date: Sun Sep 2 05:53:16 2007 New Revision: 571970 URL: http://svn.apache.org/viewvc?rev=571970&view=rev Log: Improvement of handling mappers in the touch task. datetime and millis now take precedence over the timestamp on the original file. Bugzilla report 43235.
Modified: ant/core/trunk/WHATSNEW ant/core/trunk/docs/manual/CoreTasks/touch.html ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Touch.java Modified: ant/core/trunk/WHATSNEW URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=571970&r1=571969&r2=571970&view=diff ============================================================================== --- ant/core/trunk/WHATSNEW (original) +++ ant/core/trunk/WHATSNEW Sun Sep 2 05:53:16 2007 @@ -21,6 +21,10 @@ in Ant 1.7.0 has been removed. Bugzilla report 40511. +* In the <touch> task when a <mapper> is used, the millis and datetime + attributes now override the time of the source resource if provisioned. + Bugzilla report 43235. + Fixed bugs: ----------- Modified: ant/core/trunk/docs/manual/CoreTasks/touch.html URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/touch.html?rev=571970&r1=571969&r2=571970&view=diff ============================================================================== --- ant/core/trunk/docs/manual/CoreTasks/touch.html (original) +++ ant/core/trunk/docs/manual/CoreTasks/touch.html Sun Sep 2 05:53:16 2007 @@ -56,7 +56,9 @@ </tr> <tr> <td valign="top">datetime</td> - <td valign="top">Specifies the new modification time of the file.</td> + <td valign="top">Specifies the new modification time of the file. The + special value "now" indicates the current time + (now supported since Ant 1.8).</td> </tr> <tr> <td valign="top">pattern</td> @@ -99,9 +101,12 @@ mapper</a> can be specified. Files specified via nested <code>fileset</code>s, <code>filelist</code>s, or the <code>file</code> attribute are mapped using the specified mapper. For each file mapped, - the resulting files are touched. If the original file exists its - timestamp will be used. Otherwise the task settings (<code>millis</code>, - <code>datetime</code>) take effect.</p> + the resulting files are touched. If no time has been specified and + the original file exists its timestamp will be used. + If no time has been specified and the original file does not exist the + current time is used. Since Ant 1.8 the task settings (<code>millis</code>, + and <code>datetime</code>) have priority over the timestamp of the original + file.</p> <h3>Examples</h3> <pre> <touch file="myfile"/></pre> <p>creates <code>myfile</code> if it doesn't exist and changes the @@ -126,6 +131,14 @@ </pre> <p>creates <code>bar</code> if it doesn't exist and changes the modification time to that of <code>foo</code>.</p> + +<pre> <touch file="foo" datetime="now"> + <mapper type="regexp" from="^src(.*)\.java" to="shadow\1.empty" /> + </touch> +</pre> +<p>creates files in the <code>shadow</code> directory for every java file in the + <code>src</code> directory if it doesn't exist and changes the modification + time of those files to the current time.</p> </body> Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Touch.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Touch.java?rev=571970&r1=571969&r2=571970&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 Sun Sep 2 05:53:16 2007 @@ -231,44 +231,48 @@ } if (dateTime != null && !dateTimeConfigured) { long workmillis = millis; - DateFormat df = dfFactory.getPrimaryFormat(); - ParseException pe = null; - try { - workmillis = df.parse(dateTime).getTime(); - } catch (ParseException peOne) { - df = dfFactory.getFallbackFormat(); - if (df == null) { - pe = peOne; - } else { - try { - workmillis = df.parse(dateTime).getTime(); - } catch (ParseException peTwo) { - pe = peTwo; + if ("now".equalsIgnoreCase(dateTime)) { + workmillis = System.currentTimeMillis(); + } else { + DateFormat df = dfFactory.getPrimaryFormat(); + ParseException pe = null; + try { + workmillis = df.parse(dateTime).getTime(); + } catch (ParseException peOne) { + df = dfFactory.getFallbackFormat(); + if (df == null) { + pe = peOne; + } else { + try { + workmillis = df.parse(dateTime).getTime(); + } catch (ParseException peTwo) { + pe = peTwo; + } } } - } - if (pe != null) { - throw new BuildException(pe.getMessage(), pe, getLocation()); - } - if (workmillis < 0) { - throw new BuildException("Date of " + dateTime - + " results in negative " - + "milliseconds value " - + "relative to epoch " - + "(January 1, 1970, " - + "00:00:00 GMT)."); + if (pe != null) { + throw new BuildException(pe.getMessage(), pe, getLocation()); + } + if (workmillis < 0) { + throw new BuildException("Date of " + dateTime + + " results in negative " + "milliseconds value " + + "relative to epoch " + "(January 1, 1970, " + + "00:00:00 GMT)."); + } } log("Setting millis to " + workmillis + " from datetime attribute", - ((millis < 0) ? Project.MSG_DEBUG : Project.MSG_VERBOSE)); + ((millis < 0) ? Project.MSG_DEBUG : Project.MSG_VERBOSE)); setMillis(workmillis); - //only set if successful to this point: + // only set if successful to this point: dateTimeConfigured = true; } } /** * Execute the touch operation. - * @throws BuildException if an error occurs. + * + * @throws BuildException + * if an error occurs. */ public void execute() throws BuildException { checkConfiguration(); @@ -339,8 +343,10 @@ } else { String[] mapped = fileNameMapper.mapFileName(r.getName()); if (mapped != null && mapped.length > 0) { - long modTime = (r.isExists()) ? r.getLastModified() - : defaultTimestamp; + long modTime = defaultTimestamp; + if (millis < 0 && r.isExists()){ + modTime = r.getLastModified(); + } for (int i = 0; i < mapped.length; i++) { touch(getProject().resolveFile(mapped[i]), modTime); } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]