FileDocCategorySizeDatePackage
DependSet.javaAPI DocApache Ant 1.709178Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.taskdefs

DependSet

public class DependSet extends MatchingTask
Examines and removes out of date target files. If any of the target files are out of date with respect to any of the source files, all target files are removed. This is useful where dependencies cannot be computed (for example, dynamically interpreted parameters or files that need to stay in synch but are not directly linked) or where the ant task in question could compute them but does not (for example, the linked DTD for an XML file using the XSLT task). nested arguments:
  • sources (resource union describing the source resources to examine)
  • srcfileset (fileset describing the source files to examine)
  • srcfilelist (filelist describing the source files to examine)
  • targets (path describing the target files to examine)
  • targetfileset (fileset describing the target files to examine)
  • targetfilelist (filelist describing the target files to examine)
At least one of both source and target entities is required.

This task will examine each of the sources against each of the target files. If any target files are out of date with respect to any of the sources, all targets are removed. If any sources or targets do not exist, all targets are removed. Hint: If missing files should be ignored, specify them as include patterns in filesets, rather than using filelists.

This task attempts to optimize speed of dependency checking by comparing only the dates of the oldest target file and the newest source.

Example uses:

  • Record the fact that an XML file must be up to date with respect to its XSD (Schema file), even though the XML file itself includes no reference to its XSD.
  • Record the fact that an XSL stylesheet includes other sub-stylesheets
  • Record the fact that java files must be recompiled if the ant build file changes
ant.task
category="filesystem"
since
Ant 1.4

Fields Summary
private static final org.apache.tools.ant.types.resources.selectors.ResourceSelector
NOT_EXISTS
private static final org.apache.tools.ant.types.resources.comparators.ResourceComparator
DATE_ASC
private static final org.apache.tools.ant.types.resources.comparators.ResourceComparator
DATE_DESC
private org.apache.tools.ant.types.resources.Union
sources
private org.apache.tools.ant.types.Path
targets
Constructors Summary
Methods Summary
public voidaddSrcfilelist(org.apache.tools.ant.types.FileList fl)
Add a list of source files.

param
fl the FileList to add.

        createSources().add(fl);
    
public voidaddSrcfileset(org.apache.tools.ant.types.FileSet fs)
Add a set of source files.

param
fs the FileSet to add.

        createSources().add(fs);
    
public voidaddTargetfilelist(org.apache.tools.ant.types.FileList fl)
Add a list of target files.

param
fl the FileList to add.

        createTargets().add(fl);
    
public voidaddTargetfileset(org.apache.tools.ant.types.FileSet fs)
Add a set of target files.

param
fs the FileSet to add.

        createTargets().add(new HideMissingBasedir(fs));
    
public synchronized org.apache.tools.ant.types.resources.UnioncreateSources()
Create a nested sources element.

return
a Union instance.


                  
        
        sources = (sources == null) ? new Union() : sources;
        return sources;
    
public synchronized org.apache.tools.ant.types.PathcreateTargets()
Create a nested targets element.

return
a Union instance.

        targets = (targets == null) ? new Path(getProject()) : targets;
        return targets;
    
public voidexecute()
Execute the task.

throws
BuildException if errors occur.

        if (sources == null) {
          throw new BuildException(
              "At least one set of source resources must be specified");
        }
        if (targets == null) {
          throw new BuildException(
              "At least one set of target files must be specified");
        }
        //no sources = nothing to compare; no targets = nothing to delete:
        if (sources.size() > 0 && targets.size() > 0 && !uptodate(sources, targets)) {
           log("Deleting all target files.", Project.MSG_VERBOSE);
           Delete delete = new Delete();
           delete.bindToOwner(this);
           delete.add(targets);
           delete.perform();
        }
    
private voidlogFuture(org.apache.tools.ant.types.ResourceCollection rc, org.apache.tools.ant.types.resources.selectors.ResourceSelector rsel)

        Restrict r = new Restrict();
        r.add(rsel);
        r.add(rc);
        for (Iterator i = r.iterator(); i.hasNext();) {
            log("Warning: " + i.next() + " modified in the future.", Project.MSG_WARN);
        }
    
private booleanuptodate(org.apache.tools.ant.types.ResourceCollection src, org.apache.tools.ant.types.ResourceCollection target)

        org.apache.tools.ant.types.resources.selectors.Date datesel
            = new org.apache.tools.ant.types.resources.selectors.Date();
        datesel.setMillis(System.currentTimeMillis());
        datesel.setWhen(TimeComparison.AFTER);
        logFuture(targets, datesel);

        int neTargets = new NonExistent(targets).size();
        if (neTargets > 0) {
            log(neTargets + " nonexistent targets", Project.MSG_VERBOSE);
            return false;
        }
        FileResource oldestTarget = (FileResource) (new Oldest(targets).iterator().next());
        log(oldestTarget + " is oldest target file", Project.MSG_VERBOSE);

        logFuture(sources, datesel);

        int neSources = new NonExistent(sources).size();
        if (neSources > 0) {
            log(neSources + " nonexistent sources", Project.MSG_VERBOSE);
            return false;
        }
        Resource newestSource = (Resource) (new Newest(sources).iterator().next());
        log(newestSource.toLongString() + " is newest source", Project.MSG_VERBOSE);
        return oldestTarget.getLastModified() >= newestSource.getLastModified();