You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2003/09/23 15:16:05 UTC

cvs commit: ant/src/main/org/apache/tools/ant/util ResourceUtils.java SourceFileScanner.java

bodewig     2003/09/23 06:16:05

  Modified:    docs/manual/CoreTasks copy.html move.html sync.html
               src/main/org/apache/tools/ant/taskdefs Copy.java Sync.java
               src/main/org/apache/tools/ant/util ResourceUtils.java
                        SourceFileScanner.java
  Log:
  Add a granularity attribute to <copy>, <move> and <sync> that works
  the same way as the attribute of the <depend> selector.
  
  PR: 22150
  
  Revision  Changes    Path
  1.20      +10 -0     ant/docs/manual/CoreTasks/copy.html
  
  Index: copy.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/CoreTasks/copy.html,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- copy.html	24 Jul 2003 13:14:20 -0000	1.19
  +++ copy.html	23 Sep 2003 13:16:04 -0000	1.20
  @@ -135,6 +135,16 @@
         <em>since Ant 1.6</em>.</td>
       <td align="center">No - defaults to false.</td>
     </tr>
  +  <tr>
  +    <td valign="top">granularity</td>
  +    <td valign="top">The number of milliseconds leeway to give before
  +    deciding a file is out of date. This is needed because not every
  +    file system supports tracking the last modified time to the
  +    millisecond level. Default is 0 milliseconds, or 2 seconds on DOS
  +    systems.  This can also be useful if source and target files live
  +    on separate machines with clocks being out of sync.  <em>since Ant
  +    1.6</em>.</td>
  +  </tr>
   </table>
   <h3>Parameters specified as nested elements</h3>
   
  
  
  
  1.15      +10 -0     ant/docs/manual/CoreTasks/move.html
  
  Index: move.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/CoreTasks/move.html,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- move.html	24 Jul 2003 13:14:20 -0000	1.14
  +++ move.html	23 Sep 2003 13:16:04 -0000	1.15
  @@ -113,6 +113,16 @@
         <em>since Ant 1.6</em>.</td>
       <td align="center">No - defaults to false.</td>
     </tr>
  +  <tr>
  +    <td valign="top">granularity</td>
  +    <td valign="top">The number of milliseconds leeway to give before
  +    deciding a file is out of date. This is needed because not every
  +    file system supports tracking the last modified time to the
  +    millisecond level. Default is 0 milliseconds, or 2 seconds on DOS
  +    systems.  This can also be useful if source and target files live
  +    on separate machines with clocks being out of sync.  <em>since Ant
  +    1.6</em>.</td>
  +  </tr>
   </table>
   <h3>Parameters specified as nested elements</h3>
   <h4>mapper</h4>
  
  
  
  1.4       +10 -0     ant/docs/manual/CoreTasks/sync.html
  
  Index: sync.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/CoreTasks/sync.html,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- sync.html	14 May 2003 11:58:18 -0000	1.3
  +++ sync.html	23 Sep 2003 13:16:04 -0000	1.4
  @@ -51,6 +51,16 @@
        <td valign="top">Log the files that are being copied.</td>
        <td valign="top" align="center">No; defaults to false.</td>
     </tr>
  +  <tr>
  +    <td valign="top">granularity</td>
  +    <td valign="top">The number of milliseconds leeway to give before
  +    deciding a file is out of date. This is needed because not every
  +    file system supports tracking the last modified time to the
  +    millisecond level. Default is 0 milliseconds, or 2 seconds on DOS
  +    systems.  This can also be useful if source and target files live
  +    on separate machines with clocks being out of sync.  <em>since Ant
  +    1.6</em>.</td>
  +  </tr>
   </table>
   
   <h3>Parameters specified as nested elements</h3>
  
  
  
  1.67      +18 -3     ant/src/main/org/apache/tools/ant/taskdefs/Copy.java
  
  Index: Copy.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Copy.java,v
  retrieving revision 1.66
  retrieving revision 1.67
  diff -u -r1.66 -r1.67
  --- Copy.java	16 Sep 2003 09:08:55 -0000	1.66
  +++ Copy.java	23 Sep 2003 13:16:04 -0000	1.67
  @@ -121,12 +121,14 @@
       private FileUtils fileUtils;
       private String inputEncoding = null;
       private String outputEncoding = null;
  +    private long granularity = 0;
   
       /**
        * Copy task constructor.
        */
       public Copy() {
           fileUtils = FileUtils.newFileUtils();
  +        granularity = fileUtils.getFileTimestampGranularity();
       }
   
       /**
  @@ -371,6 +373,18 @@
       }
   
       /**
  +     * The number of milliseconds leeway to give before deciding a
  +     * target is out of date.
  +     *
  +     * <p>Default is 0 milliseconds, or 2 seconds on DOS systems.</p>
  +     *
  +     * @since Ant 1.6
  +     */
  +    public void setGranularity(long granularity) {
  +        this.granularity = granularity;
  +    }
  +
  +    /**
        * Performs the copy operation.
        * @exception BuildException if an error occurs
        */
  @@ -397,7 +411,8 @@
                       }
   
                       if (forceOverwrite || !destFile.exists()
  -                        || (file.lastModified() > destFile.lastModified())) {
  +                        || (file.lastModified() - granularity 
  +                                > destFile.lastModified())) {
                           fileCopyMap.put(file.getAbsolutePath(),
                                           new String[] {destFile.getAbsolutePath()});
                       } else {
  @@ -583,7 +598,7 @@
               v.copyInto(toCopy);
           } else {
               SourceFileScanner ds = new SourceFileScanner(this);
  -            toCopy = ds.restrict(names, fromDir, toDir, mapper);
  +            toCopy = ds.restrict(names, fromDir, toDir, mapper, granularity);
           }
   
           for (int i = 0; i < toCopy.length; i++) {
  
  
  
  1.8       +13 -1     ant/src/main/org/apache/tools/ant/taskdefs/Sync.java
  
  Index: Sync.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Sync.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Sync.java	16 Sep 2003 09:08:55 -0000	1.7
  +++ Sync.java	23 Sep 2003 13:16:04 -0000	1.8
  @@ -323,6 +323,18 @@
       }
   
       /**
  +     * The number of milliseconds leeway to give before deciding a
  +     * target is out of date.
  +     *
  +     * <p>Default is 0 milliseconds, or 2 seconds on DOS systems.</p>
  +     *
  +     * @since Ant 1.6
  +     */
  +    public void setGranularity(long granularity) {
  +        _copy.setGranularity(granularity);
  +    }
  +
  +    /**
        * Subclass Copy in order to access it's file/dir maps.
        */
       public static class MyCopy extends Copy {
  
  
  
  1.5       +33 -15    ant/src/main/org/apache/tools/ant/util/ResourceUtils.java
  
  Index: ResourceUtils.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/util/ResourceUtils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ResourceUtils.java	19 Jul 2003 08:11:08 -0000	1.4
  +++ ResourceUtils.java	23 Sep 2003 13:16:04 -0000	1.5
  @@ -58,6 +58,7 @@
   import org.apache.tools.ant.taskdefs.condition.Os;
   import org.apache.tools.ant.types.Resource;
   import org.apache.tools.ant.types.ResourceFactory;
  +import org.apache.tools.ant.types.selectors.SelectorUtils;
   
   import java.io.File;
   import java.util.Vector;
  @@ -70,7 +71,7 @@
    */
   public class ResourceUtils {
   
  -    /**                                                                      {
  +    /**
        * tells which source files should be reprocessed based on the
        * last modification date of target files
        * @param logTo where to send (more or less) interesting output
  @@ -88,19 +89,34 @@
                                                       Resource[] source,
                                                       FileNameMapper mapper,
                                                       ResourceFactory targets) {
  -        long now = (new java.util.Date()).getTime();
  +        return selectOutOfDateSources(logTo, source, mapper, targets,
  +                                      FileUtils.newFileUtils()
  +                                      .getFileTimestampGranularity());
  +    }
   
  -        /*
  -          If we're on Windows, we have to munge the time up to 2 secs to
  -          be able to check file modification times.
  -          (Windows has a max resolution of two secs for modification times)
  -          Actually this is a feature of the FAT file system, NTFS does
  -          not have it, so if we could reliably passively test for an NTFS
  -          file systems we could turn this off...
  -        */
  -        if (Os.isFamily("windows")) {
  -            now += 2000;
  -        }
  +    /**
  +     * tells which source files should be reprocessed based on the
  +     * last modification date of target files
  +     * @param logTo where to send (more or less) interesting output
  +     * @param source array of resources bearing relative path and last
  +     * modification date
  +     * @param mapper filename mapper indicating how to find the target
  +     * files
  +     * @param targets object able to map as a resource a relative path
  +     * at <b>destination</b>
  +     * @param granularity The number of milliseconds leeway to give
  +     * before deciding a target is out of date.
  +     * @return array containing the source files which need to be
  +     * copied or processed, because the targets are out of date or do
  +     * not exist
  +     * @since Ant 1.6
  +     */
  +    public static Resource[] selectOutOfDateSources(ProjectComponent logTo,
  +                                                    Resource[] source,
  +                                                    FileNameMapper mapper,
  +                                                    ResourceFactory targets,
  +                                                    long granularity) {
  +        long now = (new java.util.Date()).getTime() + granularity;
   
           Vector vresult = new Vector();
           for (int counter = 0; counter < source.length; counter++) {
  @@ -130,8 +146,10 @@
                                     + " doesn\'t exist.", Project.MSG_VERBOSE);
                           vresult.addElement(source[counter]);
                           added = true;
  -                    } else if (!atarget.isDirectory() && atarget.getLastModified()
  -                               < source[counter].getLastModified()) {
  +                    } else if (!atarget.isDirectory() && 
  +                               SelectorUtils.isOutOfDate(source[counter], 
  +                                                         atarget,
  +                                                         (int) granularity)) {
                           logTo.log(source[counter].getName() + " added as "
                                     + atarget.getName()
                                     + " is outdated.", Project.MSG_VERBOSE);
  
  
  
  1.22      +36 -2     ant/src/main/org/apache/tools/ant/util/SourceFileScanner.java
  
  Index: SourceFileScanner.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/util/SourceFileScanner.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- SourceFileScanner.java	19 Jul 2003 08:11:08 -0000	1.21
  +++ SourceFileScanner.java	23 Sep 2003 13:16:04 -0000	1.22
  @@ -99,6 +99,27 @@
        */
       public String[] restrict(String[] files, File srcDir, File destDir,
                                FileNameMapper mapper) {
  +        return restrict(files, srcDir, destDir, mapper,
  +                        fileUtils.getFileTimestampGranularity());
  +    }
  +
  +    /**
  +     * Restrict the given set of files to those that are newer than
  +     * their corresponding target files.
  +     *
  +     * @param files   the original set of files
  +     * @param srcDir  all files are relative to this directory
  +     * @param destDir target files live here. if null file names
  +     *                returned by the mapper are assumed to be absolute.
  +     * @param mapper  knows how to construct a target file names from
  +     *                source file names.
  +     * @param granularity The number of milliseconds leeway to give
  +     *                    before deciding a target is out of date.
  +     *
  +     * @since Ant 1.6
  +     */
  +    public String[] restrict(String[] files, File srcDir, File destDir,
  +                             FileNameMapper mapper, long granularity) {
           // record destdir for later use in getResource
           this.destDir = destDir;
           Vector v = new Vector();
  @@ -114,7 +135,7 @@
           // respect to the target
           Resource[] outofdate =
               ResourceUtils.selectOutOfDateSources(task, sourceresources,
  -                                                 mapper, this);
  +                                                 mapper, this, granularity);
           String[] result = new String[outofdate.length];
           for (int counter = 0; counter < outofdate.length; counter++) {
               result[counter] = outofdate[counter].getName();
  @@ -129,7 +150,20 @@
        */
       public File[] restrictAsFiles(String[] files, File srcDir, File destDir,
                                     FileNameMapper mapper) {
  -        String[] res = restrict(files, srcDir, destDir, mapper);
  +        return restrictAsFiles(files, srcDir, destDir, mapper,
  +                               fileUtils.getFileTimestampGranularity());
  +    }
  +
  +    /**
  +     * Convinience layer on top of restrict that returns the source
  +     * files as File objects (containing absolute paths if srcDir is
  +     * absolute).
  +     *
  +     * @since Ant 1.6
  +     */
  +    public File[] restrictAsFiles(String[] files, File srcDir, File destDir,
  +                                  FileNameMapper mapper, long granularity) {
  +        String[] res = restrict(files, srcDir, destDir, mapper, granularity);
           File[] result = new File[res.length];
           for (int i = 0; i < res.length; i++) {
               result[i] = new File(srcDir, res[i]);
  
  
  

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


Re: cvs commit: ant/src/main/org/apache/tools/ant/util ResourceUtils.java SourceFileScanner.java

Posted by Stefan Bodewig <bo...@apache.org>.
On 23 Sep 2003, <bo...@apache.org> wrote:

>   Add a granularity attribute to <copy>, <move> and <sync> that
>   works the same way as the attribute of the <depend> selector.

Has anybody found the time to try those changes on Windows?  I'd like
to see them in the 1.6 branch.

Stefan

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


Re: cvs commit: ant/src/main/org/apache/tools/ant/util ResourceUtils.java SourceFileScanner.java

Posted by Stefan Bodewig <bo...@apache.org>.
On 23 Sep 2003, <bo...@apache.org> wrote:

>   Add a granularity attribute to <copy>, <move> and <sync> that
>   works the same way as the attribute of the <depend> selector.

the original problem is that source and target directories live on
different machines with clocks being slightly (but for a well known
amount) out of sync.

You can deal with it in <copy> by explicitly using a <depend>
selector, but selectors are not available in <sync>.

I have not merged it into the 1.6 branch for two reasons:

(1) I'm not sure whether we should add it to <copy> and <move> at all
or rather require the explicit usage of <depend>.  This would of
course lead to a lot of duplication.  Compare

<copy todir="/target" granularity="5000">
  <fileset dir="/source1"/>
  <fileset dir="/source2"/>

  <mapper type="glob" from="*" to="*.bak"/>
</copy>

to

<copy todir="/target">
  <fileset dir="/source1">
    <depend granularity="5000" targetdir="/target">
      <mapper type="glob" from="*" to="*.bak"/>
    </depend>
  </fileset>
  <fileset dir="/source2">
    <depend granularity="5000" targetdir="/target">
      <mapper type="glob" from="*" to="*.bak"/>
    </depend>
  </fileset>

  <mapper type="glob" from="*" to="*.bak"/>
</copy>

the same mapper three times, definition of targetdir in three places.

(2) The changes to SourceFileScanner and ResourceUtils will have an
impact on Windows.  As I'm unable to test anything there, I'd rather
wait for failure reports before I go and merge things.

Stefan

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