Browse Source

Improvement of handling mappers in the touch task. datetime and millis now take precedence over the timestamp on the original file. Bugzilla report 43235.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@571970 13f79535-47bb-0310-9956-ffa450edef68
master
Jacobus Martinus Kruithof 18 years ago
parent
commit
f14a2ef8c3
3 changed files with 56 additions and 33 deletions
  1. +4
    -0
      WHATSNEW
  2. +17
    -4
      docs/manual/CoreTasks/touch.html
  3. +35
    -29
      src/main/org/apache/tools/ant/taskdefs/Touch.java

+ 4
- 0
WHATSNEW View File

@@ -21,6 +21,10 @@ Changes that could break older environments:
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:
-----------



+ 17
- 4
docs/manual/CoreTasks/touch.html View File

@@ -56,7 +56,9 @@ resource collections (which also includes directories). Prior to Ant
</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 &quot;now&quot; indicates the current time
(now supported since Ant 1.8).</td>
</tr>
<tr>
<td valign="top">pattern</td>
@@ -99,9 +101,12 @@ collection.</p>
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> &lt;touch file=&quot;myfile&quot;/&gt;</pre>
<p>creates <code>myfile</code> if it doesn't exist and changes the
@@ -127,6 +132,14 @@ time close to it otherwise.</p>
<p>creates <code>bar</code> if it doesn't exist and changes the
modification time to that of <code>foo</code>.</p>

<pre> &lt;touch file=&quot;foo&quot; datetime=&quot;now&quot;&gt;
&lt;mapper type=&quot;regexp&quot; from=&quot;^src(.*)\.java&quot; to=&quot;shadow\1.empty&quot; /&gt;
&lt;/touch&gt;
</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>
</html>

+ 35
- 29
src/main/org/apache/tools/ant/taskdefs/Touch.java View File

@@ -231,44 +231,48 @@ public class Touch extends Task {
}
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 @@ public class Touch extends Task {
} 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);
}


Loading…
Cancel
Save