FileDocCategorySizeDatePackage
SourceFileScanner.javaAPI DocApache Ant 1.706899Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.util

SourceFileScanner

public class SourceFileScanner extends Object implements org.apache.tools.ant.types.ResourceFactory
Utility class that collects the functionality of the various scanDir methods that have been scattered in several tasks before.

The only method returns an array of source files. The array is a subset of the files given as a parameter and holds only those that are newer than their corresponding target files.

Fields Summary
protected org.apache.tools.ant.Task
task
private static final FileUtils
FILE_UTILS
private File
destDir
Constructors Summary
public SourceFileScanner(org.apache.tools.ant.Task task)
Construct a new SourceFileScanner.

param
task The task we should log messages through.

     // base directory of the fileset

                      
       
        this.task = task;
    
Methods Summary
public org.apache.tools.ant.types.ResourcegetResource(java.lang.String name)
Returns resource information for a file at destination.

param
name relative path of file at destination.
return
data concerning a file whose relative path to destDir is name.
since
Ant 1.5.2

        return new FileResource(destDir, name);
    
public java.lang.String[]restrict(java.lang.String[] files, java.io.File srcDir, java.io.File destDir, FileNameMapper mapper)
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.
return
an array of filenames.

        return restrict(files, srcDir, destDir, mapper,
                        FILE_UTILS.getFileTimestampGranularity());
    
public java.lang.String[]restrict(java.lang.String[] files, java.io.File srcDir, java.io.File destDir, FileNameMapper mapper, long granularity)
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.
return
an array of filenames.
since
Ant 1.6.2

        // record destdir for later use in getResource
        this.destDir = destDir;
        Vector v = new Vector();
        for (int i = 0; i < files.length; i++) {
            File src = FILE_UTILS.resolveFile(srcDir, files[i]);
            v.addElement(new Resource(files[i], src.exists(),
                                      src.lastModified(), src.isDirectory()));
        }
        Resource[] sourceresources = new Resource[v.size()];
        v.copyInto(sourceresources);

        // build the list of sources which are out of date with
        // respect to the target
        Resource[] outofdate =
            ResourceUtils.selectOutOfDateSources(task, sourceresources,
                                                 mapper, this, granularity);
        String[] result = new String[outofdate.length];
        for (int counter = 0; counter < outofdate.length; counter++) {
            result[counter] = outofdate[counter].getName();
        }
        return result;
    
public java.io.File[]restrictAsFiles(java.lang.String[] files, java.io.File srcDir, java.io.File destDir, FileNameMapper mapper)
Convenience layer on top of restrict that returns the source files as File objects (containing absolute paths if srcDir is absolute).

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.
return
an array of files.

        return restrictAsFiles(files, srcDir, destDir, mapper,
                               FILE_UTILS.getFileTimestampGranularity());
    
public java.io.File[]restrictAsFiles(java.lang.String[] files, java.io.File srcDir, java.io.File destDir, FileNameMapper mapper, long granularity)
Convenience layer on top of restrict that returns the source files as File objects (containing absolute paths if srcDir is absolute).

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.
return
an array of files.
since
Ant 1.6.2

        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]);
        }
        return result;