ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject cvs commit: ant WHATSNEW
Date Tue, 20 Apr 2004 21:37:59 GMT
mbenson     2004/04/20 14:37:59

  Modified:    src/etc/testcases/taskdefs Tag: ANT_16_BRANCH touch.xml
               src/main/org/apache/tools/ant/taskdefs Tag: ANT_16_BRANCH
                        Touch.java
               src/testcases/org/apache/tools/ant/taskdefs Tag:
                        ANT_16_BRANCH TouchTest.java
               .        Tag: ANT_16_BRANCH WHATSNEW
  Log:
  Add <touch> <filelist> support to 1.6 branch.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.1   +34 -0     ant/src/etc/testcases/taskdefs/touch.xml
  
  Index: touch.xml
  ===================================================================
  RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/touch.xml,v
  retrieving revision 1.1
  retrieving revision 1.1.2.1
  diff -u -r1.1 -r1.1.2.1
  --- touch.xml	24 Jun 2003 12:46:56 -0000	1.1
  +++ touch.xml	20 Apr 2004 21:37:59 -0000	1.1.2.1
  @@ -12,4 +12,38 @@
     <target name="seconds">
       <touch file="touchtest" datetime="2003/06/24 2:20:12 pm"/>
     </target>
  +
  +  <target name="testNow">
  +    <touch file="touchtest" />
  +  </target>
  +  
  +  <target name="testMillis">
  +    <!-- this one is about 21 years after the epoch -->
  +    <!-- less than 20 years after the epoch, test does not pass on my Win2K/FAT -->
  +    <!-- Antoine February 8, 2004 -->
  +    <!-- see http://developer.java.sun.com/developer/bugParade/bugs/4177432.html -->
  +    <!-- and http://developer.java.sun.com/developer/bugParade/bugs/4697792.html -->
  +    <!-- not sure why -->
  +    <touch file="touchtest" millis="662256000000" />
  +  </target>
  +  
  +  <target name="test2000">
  +    <!-- this number of milliseconds is 30 * 365 * 24 * 3600 * 1000 -->
  +    <!-- so the corresponding time is at the end of 1999 -->
  +    <touch file="touchtest" millis="946080000000" />
  +  </target>
  +  
  +  <target name="testFilelist">
  +    <touch millis="662256000000" >
  +      <filelist dir="." files="touchtest"/>
  +    </touch>
  +  </target>
  +
  +  <target name="testFileset" depends="testNow">
  +    <touch millis="946080000000" >
  +      <fileset dir="." includes="touchtest"/>
  +    </touch>
  +  </target>
  +
  +  
   </project>
  
  
  
  No                   revision
  No                   revision
  1.34.2.5  +41 -27    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.34.2.4
  retrieving revision 1.34.2.5
  diff -u -r1.34.2.4 -r1.34.2.5
  --- Touch.java	9 Mar 2004 17:01:34 -0000	1.34.2.4
  +++ Touch.java	20 Apr 2004 21:37:59 -0000	1.34.2.5
  @@ -28,11 +28,13 @@
   import org.apache.tools.ant.Project;
   import org.apache.tools.ant.Task;
   import org.apache.tools.ant.types.FileSet;
  +import org.apache.tools.ant.types.FileList;
   import org.apache.tools.ant.util.FileUtils;
   import org.apache.tools.ant.util.JavaEnvUtils;
   
   /**
  - * Touch a file and/or fileset(s); corresponds to the Unix touch command.
  + * Touch a file and/or fileset(s) and/or filelist(s);
  + * corresponds to the Unix touch command.
    *
    * <p>If the file to touch doesn't exist, an empty one is
    * created. </p>
  @@ -40,7 +42,6 @@
    * <p>Note: Setting the modification time of files is not supported in
    * JDK 1.1.</p>
    *
  - *
    * @since Ant 1.1
    *
    * @ant.task category="filesystem"
  @@ -51,6 +52,7 @@
       private long millis = -1;
       private String dateTime;
       private Vector filesets = new Vector();
  +    private Vector filelists = new Vector();
       private FileUtils fileUtils;
   
       public Touch() {
  @@ -92,14 +94,21 @@
       }
   
       /**
  +     * Add a filelist to touch
  +     */
  +    public void addFilelist(FileList list) {
  +        filelists.addElement(list);
  +    }
  +
  +    /**
        * Execute the touch operation.
        */
       public void execute() throws BuildException {
           long savedMillis = millis;
   
  -        if (file == null && filesets.size() == 0) {
  +        if (file == null && filesets.size() == 0 && filelists.size() ==
0) {
               throw
  -                new BuildException("Specify at least one source - a file or "
  +                new BuildException("Specify at least one source - a file, filelist or "
                                      + "a fileset.");
           }
   
  @@ -155,26 +164,9 @@
       }
   
       /**
  -     * Does the actual work. Entry point for Untar and Expand as well.
  +     * Does the actual work; assumes everything has been checked by now.
        */
       protected void touch() throws BuildException {
  -        if (file != null) {
  -            if (!file.exists()) {
  -                log("Creating " + file, Project.MSG_INFO);
  -                try {
  -                    fileUtils.createNewFile(file);
  -                } catch (IOException ioe) {
  -                    throw new BuildException("Could not create " + file, ioe,
  -                                             getLocation());
  -                }
  -            }
  -        }
  -
  -        if (millis >= 0 && JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1))
{
  -            log("modification time of files cannot be set in JDK 1.1",
  -                Project.MSG_WARN);
  -            return;
  -        }
   
           boolean resetMillis = false;
           if (millis < 0) {
  @@ -204,21 +196,43 @@
               }
           }
   
  +        // deal with the filelists
  +        for (int i = 0; i < filelists.size(); i++) {
  +            FileList fl = (FileList) filelists.elementAt(i);
  +            File fromDir = fl.getDir(getProject());
  +
  +            String[] srcFiles = fl.getFiles(getProject());
  +
  +            for (int j = 0; j < srcFiles.length; j++) {
  +                touch(new File(fromDir, srcFiles[j]));
  +            }
  +        }
  +
           if (resetMillis) {
               millis = -1;
           }
       }
   
  +    /**
  +     * touch a single file with the current timestamp (this.millis)
  +     * @param file file to touch
  +     * @throws BuildException
  +     */
       protected void touch(File file) throws BuildException {
  +        if (!file.exists()) {
  +            log("Creating " + file, Project.MSG_INFO);
  +            try {
  +                fileUtils.createNewFile(file);
  +            } catch (IOException ioe) {
  +                throw new BuildException("Could not create " + file, ioe,
  +                                         getLocation());
  +            }
  +        }
  +
           if (!file.canWrite()) {
               throw new BuildException("Can not change modification date of "
                                        + "read-only file " + file);
           }
  -
  -        if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)) {
  -            return;
  -        }
  -
           fileUtils.setFileLastModified(file, millis);
       }
   
  
  
  
  No                   revision
  No                   revision
  1.1.2.4   +85 -0     ant/src/testcases/org/apache/tools/ant/taskdefs/TouchTest.java
  
  Index: TouchTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/TouchTest.java,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- TouchTest.java	9 Feb 2004 22:12:47 -0000	1.1.2.3
  +++ TouchTest.java	20 Apr 2004 21:37:59 -0000	1.1.2.4
  @@ -18,9 +18,15 @@
   package org.apache.tools.ant.taskdefs;
   
   import org.apache.tools.ant.BuildFileTest;
  +import org.apache.tools.ant.BuildException;
  +import org.apache.tools.ant.util.FileUtils;
  +
  +import java.io.File;
   
   public class TouchTest extends BuildFileTest {
   
  +    private static String touchfile="src/etc/testcases/taskdefs/touchtest";
  +
       public TouchTest(String name) {
           super(name);
       }
  @@ -33,12 +39,22 @@
           executeTarget("cleanup");
       }
   
  +    public long getTargetTime() {
  +
  +        File file = new File(touchfile);
  +        if(!file.exists()) {
  +            throw new BuildException("failed to touch file "+touchfile);
  +        }
  +        return file.lastModified();
  +    }
  +
       /**
        * No real test, simply checks whether the dateformat without
        * seconds is accepted - by erroring out otherwise.
        */
       public void testNoSeconds() {
           executeTarget("noSeconds");
  +        long time = getTargetTime();
       }
   
       /**
  @@ -47,5 +63,74 @@
        */
       public void testSeconds() {
           executeTarget("seconds");
  +        long time=getTargetTime();
  +    }
  +    /**
  +     * verify that the millis test sets things up
  +     */
  +    public void testMillis() {
  +        touchFile("testMillis", 662256000000L);
  +    }
  +
  +    /**
  +     * verify that the default value defaults to now
  +     */
  +    public void testNow() {
  +        long now=System.currentTimeMillis();
  +        executeTarget("testNow");
  +        long time = getTargetTime();
  +        assertTimesNearlyMatch(time,now,5000);
  +    }
  +    /**
  +     * verify that the millis test sets things up
  +     */
  +    public void test2000() {
  +        touchFile("test2000", 946080000000L);
  +    }
  +
  +    /**
  +     * test the file list
  +     */
  +    public void testFilelist() {
  +        touchFile("testFilelist", 662256000000L);
  +    }
  +
  +    /**
  +     * test the file set
  +     */
  +    public void testFileset() {
  +        touchFile("testFileset", 946080000000L);
  +    }
  +
  +    /**
  +     * run a target to touch the test file; verify the timestamp is as expected
  +     * @param targetName
  +     * @param timestamp
  +     */
  +    private void touchFile(String targetName, long timestamp) {
  +        executeTarget(targetName);
  +        long time = getTargetTime();
  +        assertTimesNearlyMatch(timestamp,time);
  +    }
  +
  +    /**
  +     * assert that two times are within the current FS granularity;
  +     * @param timestamp
  +     * @param time
  +     */
  +    public void assertTimesNearlyMatch(long timestamp,long time) {
  +        long granularity= FileUtils.newFileUtils().getFileTimestampGranularity();
  +        assertTimesNearlyMatch(timestamp, time, granularity);
  +    }
  +
  +    /**
  +     * assert that two times are within a specified range
  +     * @param timestamp
  +     * @param time
  +     * @param range
  +     */
  +    private void assertTimesNearlyMatch(long timestamp, long time, long range) {
  +        assertTrue("Time "+timestamp+" is not within "+range+" ms of "+time,
  +                Math.abs(time-timestamp)<=range);
       }
   }
  
  
  
  No                   revision
  No                   revision
  1.503.2.74 +2 -0      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.503.2.73
  retrieving revision 1.503.2.74
  diff -u -r1.503.2.73 -r1.503.2.74
  --- WHATSNEW	20 Apr 2004 13:25:15 -0000	1.503.2.73
  +++ WHATSNEW	20 Apr 2004 21:37:59 -0000	1.503.2.74
  @@ -81,6 +81,8 @@
   
   * <xslt> now supports a nested <mapper>.  Bugzilla Report 11249.
   
  +* <touch> has filelist support.
  +
   Changes from Ant 1.6.0 to Ant 1.6.1
   ===================================
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message