FileDocCategorySizeDatePackage
MappingSelector.javaAPI DocApache Ant 1.705067Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.types.selectors

MappingSelector

public abstract class MappingSelector extends BaseSelector
A mapping selector is an abstract class adding mapping support to the base selector

Fields Summary
private static final org.apache.tools.ant.util.FileUtils
FILE_UTILS
Utilities used for file operations
protected File
targetdir
protected org.apache.tools.ant.types.Mapper
mapperElement
protected org.apache.tools.ant.util.FileNameMapper
map
protected int
granularity
Constructors Summary
public MappingSelector()
Creates a new MappingSelector instance.


    // CheckStyle:VisibilityModifier ON

              
      
        granularity = (int) FILE_UTILS.getFileTimestampGranularity();
    
Methods Summary
public org.apache.tools.ant.types.MappercreateMapper()
Defines the FileNameMapper to use (nested mapper element).

return
a mapper to be configured
throws
BuildException if more that one mapper defined

        if (mapperElement != null) {
            throw new BuildException("Cannot define more than one mapper");
        }
        mapperElement = new Mapper(getProject());
        return mapperElement;
    
public booleanisSelected(java.io.File basedir, java.lang.String filename, java.io.File file)
The heart of the matter. This is where the selector gets to decide on the inclusion of a file in a particular fileset.

param
basedir the base directory the scan is being done from
param
filename is the name of the file to check
param
file is a java.io.File object the selector can use
return
whether the file should be selected or not


        // throw BuildException on error
        validate();

        // Determine file whose out-of-dateness is to be checked
        String[] destfiles = map.mapFileName(filename);
        // If filename does not match the To attribute of the mapper
        // then filter it out of the files we are considering
        if (destfiles == null) {
            return false;
        }
        // Sanity check
        if (destfiles.length != 1 || destfiles[0] == null) {
            throw new BuildException("Invalid destination file results for "
                    + targetdir.getName() + " with filename " + filename);
        }
        String destname = destfiles[0];
        File destfile = new File(targetdir, destname);

        boolean selected = selectionTest(file, destfile);
        return selected;
    
protected abstract booleanselectionTest(java.io.File srcfile, java.io.File destfile)
this test is our selection test that compared the file with the destfile

param
srcfile file to test; may be null
param
destfile destination file
return
true if source file compares with destination file

public voidsetGranularity(int granularity)
Sets the number of milliseconds leeway we will give before we consider a file out of date. Defaults to 2000 on MS-DOS derivatives and 1000 on others.

param
granularity the leeway in milliseconds

        this.granularity = granularity;
    
public voidsetTargetdir(java.io.File targetdir)
The name of the file or directory which is checked for out-of-date files.

param
targetdir the directory to scan looking for files.

        this.targetdir = targetdir;
    
public voidverifySettings()
Checks to make sure all settings are kosher. In this case, it means that the dest attribute has been set and we have a mapper.

        if (targetdir == null) {
            setError("The targetdir attribute is required.");
        }
        if (mapperElement == null) {
            map = new IdentityMapper();
        } else {
            map = mapperElement.getImplementation();
        }
        if (map == null) {
            setError("Could not set <mapper> element.");
        }