bodewig     2003/06/24 05:46:57

  Modified:    .        WHATSNEW
               docs/manual/CoreTasks touch.html
               src/main/org/apache/tools/ant/taskdefs Touch.java
  Added:       src/etc/testcases/taskdefs touch.xml
               src/testcases/org/apache/tools/ant/taskdefs TouchTest.java
  Log:
  Allow <touch>'s datetime attribute to accept seconds as well.
  
  PR: 21014
  
  Revision  Changes    Path
  1.445     +3 -0      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.444
  retrieving revision 1.445
  diff -u -r1.444 -r1.445
  --- WHATSNEW  24 Jun 2003 11:29:19 -0000      1.444
  +++ WHATSNEW  24 Jun 2003 12:46:56 -0000      1.445
  @@ -440,6 +440,9 @@
   * Added <scriptdef> task allowing tasks to be defined using any BSF-supported
     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
   ===================================
   
  
  
  
  1.8       +7 -2      ant/docs/manual/CoreTasks/touch.html
  
  Index: touch.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/CoreTasks/touch.html,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- touch.html        1 Jun 2002 12:26:33 -0000       1.7
  +++ touch.html        24 Jun 2003 12:46:56 -0000      1.8
  @@ -37,7 +37,7 @@
     <tr>
       <td valign="top">datetime</td>
       <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>
     </tr>
   </table>
  @@ -56,8 +56,13 @@
     &lt;/touch&gt;</pre>
   <p>changes the modification time to Oct, 09 1974 4:30 pm of all files and 
directories 
     found in <code>src_dir</code>. </p>
  +<pre>  &lt;touch file=&quot;myfile&quot; datetime=&quot;06/28/2000 2:02:17 
pm&quot;/&gt;</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>
  -<p align="center">Copyright &copy; 2000-2001 Apache Software Foundation. All 
rights
  +<p align="center">Copyright &copy; 2000-2001,2003 Apache Software 
Foundation. All rights
   Reserved.</p>
   
   </body>
  
  
  
  1.1                  ant/src/etc/testcases/taskdefs/touch.xml
  
  Index: touch.xml
  ===================================================================
  <?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.31      +32 -11    ant/src/main/org/apache/tools/ant/taskdefs/Touch.java
  
  Index: Touch.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Touch.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- Touch.java        7 Mar 2003 11:23:02 -0000       1.30
  +++ Touch.java        24 Jun 2003 12:46:56 -0000      1.31
  @@ -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 @@
   
       /**
        * the new modification time of the file
  -     * in the format MM/DD/YYYY HH:MM AM <i>or</i> PM;
  +     * in the format &quot;MM/DD/YYYY HH:MM AM <i>or</i> PM&quot; 
  +     * or &quot;MM/DD/YYYY HH:MM:SS AM <i>or</i> PM&quot;.
        * Optional, default=now
        */
       public void setDatetime(String dateTime) {
  @@ -148,22 +149,42 @@
   
           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).");
                   }
               }
   
  
  
  
  1.1                  
ant/src/testcases/org/apache/tools/ant/taskdefs/TouchTest.java
  
  Index: TouchTest.java
  ===================================================================
  /*
   * 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 [EMAIL PROTECTED]
   *
   * 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");
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to