PR: 21014 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274700 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -440,6 +440,9 @@ Other changes: | |||||
| * Added <scriptdef> task allowing tasks to be defined using any BSF-supported | * Added <scriptdef> task allowing tasks to be defined using any BSF-supported | ||||
| scripting language. | scripting language. | ||||
| * <touch>'s datetime attribute can now accept time with a granularity | |||||
| of seconds as well. Bugzilla Report 21014. | |||||
| Changes from Ant 1.5.2 to Ant 1.5.3 | Changes from Ant 1.5.2 to Ant 1.5.3 | ||||
| =================================== | =================================== | ||||
| @@ -37,7 +37,7 @@ of now works, all other cases will emit a warning.</p> | |||||
| <tr> | <tr> | ||||
| <td valign="top">datetime</td> | <td valign="top">datetime</td> | ||||
| <td valign="top">specifies the new modification time of the file | <td valign="top">specifies the new modification time of the file | ||||
| in the format MM/DD/YYYY HH:MM AM_or_PM.</td> | |||||
| in the format MM/DD/YYYY HH:MM AM_or_PM or MM/DD/YYYY HH:MM:SS AM_or_PM.</td> | |||||
| <td valign="top" align="center">No</td> | <td valign="top" align="center">No</td> | ||||
| </tr> | </tr> | ||||
| </table> | </table> | ||||
| @@ -56,8 +56,13 @@ hour times).</p> | |||||
| </touch></pre> | </touch></pre> | ||||
| <p>changes the modification time to Oct, 09 1974 4:30 pm of all files and directories | <p>changes the modification time to Oct, 09 1974 4:30 pm of all files and directories | ||||
| found in <code>src_dir</code>. </p> | found in <code>src_dir</code>. </p> | ||||
| <pre> <touch file="myfile" datetime="06/28/2000 2:02:17 pm"/></pre> | |||||
| <p>creates <code>myfile</code> if it doesn't exist and changes the | |||||
| modification time to Jun, 28 2000 2:02:17 pm (14:02:17 for those used to 24 | |||||
| hour times), if the filesystem allows a precision of one second - a | |||||
| time close to it otherwise.</p> | |||||
| <hr> | <hr> | ||||
| <p align="center">Copyright © 2000-2001 Apache Software Foundation. All rights | |||||
| <p align="center">Copyright © 2000-2001,2003 Apache Software Foundation. All rights | |||||
| Reserved.</p> | Reserved.</p> | ||||
| </body> | </body> | ||||
| @@ -0,0 +1,15 @@ | |||||
| <?xml version="1.0"?> | |||||
| <project default="cleanup" basedir="."> | |||||
| <target name="cleanup"> | |||||
| <delete file="touchtest" /> | |||||
| </target> | |||||
| <target name="noSeconds"> | |||||
| <touch file="touchtest" datetime="2003/06/24 2:20 pm"/> | |||||
| </target> | |||||
| <target name="seconds"> | |||||
| <touch file="touchtest" datetime="2003/06/24 2:20:12 pm"/> | |||||
| </target> | |||||
| </project> | |||||
| @@ -1,7 +1,7 @@ | |||||
| /* | /* | ||||
| * The Apache Software License, Version 1.1 | * The Apache Software License, Version 1.1 | ||||
| * | * | ||||
| * Copyright (c) 2000-2002 The Apache Software Foundation. All rights | |||||
| * Copyright (c) 2000-2003 The Apache Software Foundation. All rights | |||||
| * reserved. | * reserved. | ||||
| * | * | ||||
| * Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
| @@ -116,7 +116,8 @@ public class Touch extends Task { | |||||
| /** | /** | ||||
| * the new modification time of the file | * the new modification time of the file | ||||
| * in the format MM/DD/YYYY HH:MM AM <i>or</i> PM; | |||||
| * in the format "MM/DD/YYYY HH:MM AM <i>or</i> PM" | |||||
| * or "MM/DD/YYYY HH:MM:SS AM <i>or</i> PM". | |||||
| * Optional, default=now | * Optional, default=now | ||||
| */ | */ | ||||
| public void setDatetime(String dateTime) { | public void setDatetime(String dateTime) { | ||||
| @@ -148,22 +149,42 @@ public class Touch extends Task { | |||||
| try { | try { | ||||
| if (dateTime != null) { | if (dateTime != null) { | ||||
| /* | |||||
| * The initial version used DateFormat.SHORT for the | |||||
| * time format, which ignores seconds. If we want | |||||
| * seconds as well, we need DateFormat.MEDIUM, which | |||||
| * in turn would break all old build files. | |||||
| * | |||||
| * First try to parse with DateFormat.SHORT and if | |||||
| * that fails with MEDIUM - throw an exception if both | |||||
| * fail. | |||||
| */ | |||||
| DateFormat df = | DateFormat df = | ||||
| DateFormat.getDateTimeInstance(DateFormat.SHORT, | DateFormat.getDateTimeInstance(DateFormat.SHORT, | ||||
| DateFormat.SHORT, | DateFormat.SHORT, | ||||
| Locale.US); | Locale.US); | ||||
| try { | try { | ||||
| setMillis(df.parse(dateTime).getTime()); | setMillis(df.parse(dateTime).getTime()); | ||||
| if (millis < 0) { | |||||
| throw new BuildException("Date of " + dateTime | |||||
| + " results in negative " | |||||
| + "milliseconds value " | |||||
| + "relative to epoch " | |||||
| + "(January 1, 1970, " | |||||
| + "00:00:00 GMT)."); | |||||
| } | |||||
| } catch (ParseException pe) { | } catch (ParseException pe) { | ||||
| throw new BuildException(pe.getMessage(), pe, getLocation()); | |||||
| df = | |||||
| DateFormat.getDateTimeInstance(DateFormat.SHORT, | |||||
| DateFormat.MEDIUM, | |||||
| Locale.US); | |||||
| try { | |||||
| setMillis(df.parse(dateTime).getTime()); | |||||
| } catch (ParseException pe2) { | |||||
| throw new BuildException(pe2.getMessage(), pe, | |||||
| getLocation()); | |||||
| } | |||||
| } | |||||
| if (millis < 0) { | |||||
| throw new BuildException("Date of " + dateTime | |||||
| + " results in negative " | |||||
| + "milliseconds value " | |||||
| + "relative to epoch " | |||||
| + "(January 1, 1970, " | |||||
| + "00:00:00 GMT)."); | |||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,88 @@ | |||||
| /* | |||||
| * The Apache Software License, Version 1.1 | |||||
| * | |||||
| * Copyright (c) 2003 The Apache Software Foundation. All rights | |||||
| * reserved. | |||||
| * | |||||
| * Redistribution and use in source and binary forms, with or without | |||||
| * modification, are permitted provided that the following conditions | |||||
| * are met: | |||||
| * | |||||
| * 1. Redistributions of source code must retain the above copyright | |||||
| * notice, this list of conditions and the following disclaimer. | |||||
| * | |||||
| * 2. Redistributions in binary form must reproduce the above copyright | |||||
| * notice, this list of conditions and the following disclaimer in | |||||
| * the documentation and/or other materials provided with the | |||||
| * distribution. | |||||
| * | |||||
| * 3. The end-user documentation included with the redistribution, if | |||||
| * any, must include the following acknowlegement: | |||||
| * "This product includes software developed by the | |||||
| * Apache Software Foundation (http://www.apache.org/)." | |||||
| * Alternately, this acknowlegement may appear in the software itself, | |||||
| * if and wherever such third-party acknowlegements normally appear. | |||||
| * | |||||
| * 4. The names "Ant" and "Apache Software | |||||
| * Foundation" must not be used to endorse or promote products derived | |||||
| * from this software without prior written permission. For written | |||||
| * permission, please contact apache@apache.org. | |||||
| * | |||||
| * 5. Products derived from this software may not be called "Apache" | |||||
| * nor may "Apache" appear in their names without prior written | |||||
| * permission of the Apache Group. | |||||
| * | |||||
| * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
| * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
| * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
| * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
| * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
| * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
| * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
| * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
| * SUCH DAMAGE. | |||||
| * ==================================================================== | |||||
| * | |||||
| * This software consists of voluntary contributions made by many | |||||
| * individuals on behalf of the Apache Software Foundation. For more | |||||
| * information on the Apache Software Foundation, please see | |||||
| * <http://www.apache.org/>. | |||||
| */ | |||||
| package org.apache.tools.ant.taskdefs; | |||||
| import org.apache.tools.ant.BuildFileTest; | |||||
| public class TouchTest extends BuildFileTest { | |||||
| public TouchTest(String name) { | |||||
| super(name); | |||||
| } | |||||
| public void setUp() { | |||||
| configureProject("src/etc/testcases/taskdefs/touch.xml"); | |||||
| } | |||||
| public void tearDown() { | |||||
| executeTarget("cleanup"); | |||||
| } | |||||
| /** | |||||
| * No real test, simply checks whether the dateformat without | |||||
| * seconds is accepted - by erroring out otherwise. | |||||
| */ | |||||
| public void testNoSeconds() { | |||||
| executeTarget("noSeconds"); | |||||
| } | |||||
| /** | |||||
| * No real test, simply checks whether the dateformat with | |||||
| * seconds is accepted - by erroring out otherwise. | |||||
| */ | |||||
| public void testSeconds() { | |||||
| executeTarget("seconds"); | |||||
| } | |||||
| } | |||||