diff --git a/WHATSNEW b/WHATSNEW index d73797024..135e355e7 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -440,6 +440,9 @@ Other changes: * Added task allowing tasks to be defined using any BSF-supported scripting language. +* '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 =================================== diff --git a/docs/manual/CoreTasks/touch.html b/docs/manual/CoreTasks/touch.html index e3044a0ba..eb3922b87 100644 --- a/docs/manual/CoreTasks/touch.html +++ b/docs/manual/CoreTasks/touch.html @@ -37,7 +37,7 @@ of now works, all other cases will emit a warning.

datetime specifies the new modification time of the file - in the format MM/DD/YYYY HH:MM AM_or_PM. + in the format MM/DD/YYYY HH:MM AM_or_PM or MM/DD/YYYY HH:MM:SS AM_or_PM. No @@ -56,8 +56,13 @@ hour times).

</touch>

changes the modification time to Oct, 09 1974 4:30 pm of all files and directories found in src_dir.

+
  <touch file="myfile" datetime="06/28/2000 2:02:17 pm"/>
+

creates myfile 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.


-

Copyright © 2000-2001 Apache Software Foundation. All rights +

Copyright © 2000-2001,2003 Apache Software Foundation. All rights Reserved.

diff --git a/src/etc/testcases/taskdefs/touch.xml b/src/etc/testcases/taskdefs/touch.xml new file mode 100644 index 000000000..010aff651 --- /dev/null +++ b/src/etc/testcases/taskdefs/touch.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/org/apache/tools/ant/taskdefs/Touch.java b/src/main/org/apache/tools/ant/taskdefs/Touch.java index ea2ebf331..c5e47a3bd 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Touch.java +++ b/src/main/org/apache/tools/ant/taskdefs/Touch.java @@ -1,7 +1,7 @@ /* * 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. * * 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 - * in the format MM/DD/YYYY HH:MM AM or PM; + * in the format "MM/DD/YYYY HH:MM AM or PM" + * or "MM/DD/YYYY HH:MM:SS AM or PM". * Optional, default=now */ public void setDatetime(String dateTime) { @@ -148,22 +149,42 @@ public class Touch extends Task { try { 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.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.US); try { 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) { - 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)."); } } diff --git a/src/testcases/org/apache/tools/ant/taskdefs/TouchTest.java b/src/testcases/org/apache/tools/ant/taskdefs/TouchTest.java new file mode 100644 index 000000000..4668221fe --- /dev/null +++ b/src/testcases/org/apache/tools/ant/taskdefs/TouchTest.java @@ -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 + * . + */ + +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"); + } +}