bodewig     2004/05/25 05:12:57

  Modified:    docs/manual/CoreTasks Tag: ANT_16_BRANCH copy.html
               src/main/org/apache/tools/ant/taskdefs Tag: ANT_16_BRANCH
                        Copy.java
               src/main/org/apache/tools/ant/util Tag: ANT_16_BRANCH
                        ResourceUtils.java SourceFileScanner.java
  Log:
  Merge fix for PR#22150
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.19.2.6  +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.2.5
  retrieving revision 1.19.2.6
  diff -u -r1.19.2.5 -r1.19.2.6
  --- copy.html 9 Feb 2004 22:12:07 -0000       1.19.2.5
  +++ copy.html 25 May 2004 12:12:56 -0000      1.19.2.6
  @@ -129,6 +129,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.2</em>.</td>
  +  </tr>
   </table>
   <h3>Parameters specified as nested elements</h3>
   
  
  
  
  No                   revision
  No                   revision
  1.66.2.5  +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.2.4
  retrieving revision 1.66.2.5
  diff -u -r1.66.2.4 -r1.66.2.5
  --- Copy.java 9 Mar 2004 17:01:33 -0000       1.66.2.4
  +++ Copy.java 25 May 2004 12:12:56 -0000      1.66.2.5
  @@ -78,12 +78,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();
       }
   
       /**
  @@ -328,6 +330,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.2
  +     */
  +    public void setGranularity(long granularity) {
  +        this.granularity = granularity;
  +    }
  +
  +    /**
        * Performs the copy operation.
        * @exception BuildException if an error occurs
        */
  @@ -354,7 +368,8 @@
                       }
   
                       if (forceOverwrite || !destFile.exists()
  -                        || (file.lastModified() > destFile.lastModified())) {
  +                        || (file.lastModified() - granularity
  +                                > destFile.lastModified())) {
                           fileCopyMap.put(file.getAbsolutePath(),
                                           new String[] 
{destFile.getAbsolutePath()});
                       } else {
  @@ -540,7 +555,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++) {
  
  
  
  No                   revision
  No                   revision
  1.4.2.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.2.4
  retrieving revision 1.4.2.5
  diff -u -r1.4.2.4 -r1.4.2.5
  --- ResourceUtils.java        9 Mar 2004 17:01:57 -0000       1.4.2.4
  +++ ResourceUtils.java        25 May 2004 12:12:57 -0000      1.4.2.5
  @@ -21,6 +21,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;
  @@ -32,7 +33,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
  @@ -50,19 +51,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.2
  +     */
  +    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++) {
  @@ -92,8 +108,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.21.2.5  +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.2.4
  retrieving revision 1.21.2.5
  diff -u -r1.21.2.4 -r1.21.2.5
  --- SourceFileScanner.java    9 Mar 2004 17:01:57 -0000       1.21.2.4
  +++ SourceFileScanner.java    25 May 2004 12:12:57 -0000      1.21.2.5
  @@ -60,6 +60,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.2
  +     */
  +    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();
  @@ -75,7 +96,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();
  @@ -90,7 +111,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.2
  +     */
  +    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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to