ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@locus.apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs UpToDate.java
Date Wed, 29 Nov 2000 16:33:45 GMT
bodewig     00/11/29 08:33:44

  Modified:    src/main/org/apache/tools/ant/taskdefs UpToDate.java
  Log:
  Added a nested <mapper> element to <uptodate>
  
  Revision  Changes    Path
  1.3       +39 -14    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/UpToDate.java
  
  Index: UpToDate.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/UpToDate.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- UpToDate.java	2000/11/16 09:57:46	1.2
  +++ UpToDate.java	2000/11/29 16:33:42	1.3
  @@ -23,7 +23,7 @@
    *    Alternately, this acknowlegement may appear in the software itself,
    *    if and wherever such third-party acknowlegements normally appear.
    *
  - * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
  + * 4. The names "The Jakarta Project", "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.
  @@ -77,6 +77,8 @@
       private File _targetFile;
       private Vector sourceFileSets = new Vector();
   
  +    protected Mapper mapperElement = null;
  +
       /**
        * The property to set if the target file is more up to date than each of
        * the source files.
  @@ -98,49 +100,72 @@
       }
   
       /**
  -     * Nested <srcfiles> element.
  +     * Nested &lt;srcfiles&gt; element.
        */
       public void addSrcfiles(FileSet fs) {
           sourceFileSets.addElement(fs);
       }
   
       /**
  -     * Sets property to true if target file has a more recent timestamp than
  -     * each of the source files.
  +     * Defines the FileNameMapper to use (nested mapper element).
        */
  +    public Mapper createMapper() throws BuildException {
  +        if (mapperElement != null) {
  +            throw new BuildException("Cannot define more than one mapper",
  +                                     location);
  +        }
  +        mapperElement = new Mapper(project);
  +        return mapperElement;
  +    }
  +
  +    /**
  +     * Sets property to true if target files have a more recent timestamp than
  +     * each of the corresponding source files.
  +     */
       public void execute() throws BuildException {
   
           if (sourceFileSets.size() == 0) {
             throw new BuildException("At least one <srcfiles> element must be set");
           }
   
  -        if (_targetFile == null) {
  -          throw new BuildException("The targetfile attribute must be set");
  +        if (_targetFile == null && mapperElement == null) {
  +          throw new BuildException("The targetfile attribute or a nested mapper element
must be set");
           }
   
           // if not there then it can't be up to date
  -        if (!_targetFile.exists()) return; 
  +        if (_targetFile != null && !_targetFile.exists()) return; 
   
           Enumeration enum = sourceFileSets.elements();
           boolean upToDate = true;
           while (upToDate && enum.hasMoreElements()) {
               FileSet fs = (FileSet) enum.nextElement();
               DirectoryScanner ds = fs.getDirectoryScanner(project);
  -            upToDate = upToDate && scanDir(fs.getDir(project), _targetFile, 
  +            upToDate = upToDate && scanDir(fs.getDir(project), 
                                              ds.getIncludedFiles());
           }
   
           if (upToDate) {
               this.project.setProperty(_property, "true");
  -            log("File \"" + _targetFile.getAbsolutePath() + "\" is up to date.",
  -                Project.MSG_VERBOSE);
  +            if (mapperElement == null) {
  +                log("File \"" + _targetFile.getAbsolutePath() + "\" is up to date.",
  +                    Project.MSG_VERBOSE);
  +            } else {
  +                log("All target files have been up to date.",
  +                    Project.MSG_VERBOSE);
  +            }
           }
       }
   
  -    protected boolean scanDir(File srcDir, File destFile, String files[]) {
  +    protected boolean scanDir(File srcDir, String files[]) {
           SourceFileScanner sfs = new SourceFileScanner(this);
  -        MergingMapper mm = new MergingMapper();
  -        mm.setTo(destFile.getAbsolutePath());
  -        return sfs.restrict(files, srcDir, null, mm).length == 0;
  +        FileNameMapper mapper = null;
  +        if (mapperElement == null) {
  +            MergingMapper mm = new MergingMapper();
  +            mm.setTo(_targetFile.getAbsolutePath());
  +        } else {
  +            mapper = mapperElement.getImplementation();
  +        }
  +        
  +        return sfs.restrict(files, srcDir, null, mapper).length == 0;
       }
   }
  
  
  

Mime
View raw message