org.apache.tools.ant.types.selectors.modifiedselector

Class ModifiedSelector

public class ModifiedSelector extends BaseExtendSelector

Selector class that uses Algorithm, Cache and Comparator for its work. The Algorithm is used for computing a hashvalue for a file. The Comparator decides whether to select or not. The Cache stores the other value for comparison by the Comparator in a persistent manner.

The ModifiedSelector is implemented as a CoreSelector and uses default values for all its attributes therefore the simpliest example is

   
       
           
       
   
 

The same example rewritten as CoreSelector with setting the all values (same as defaults are) would be

   
       
           
               
               
           
       
   
 

And the same rewritten as CustomSelector would be

   
       
           
               
               
               
               
               
               
           
       
   
 

All these three examples copy the files from src to dest using the ModifiedSelector. The ModifiedSelector uses the PropertyfileCache , the DigestAlgorithm and the EqualComparator for its work. The PropertyfileCache stores key-value-pairs in a simple java properties file. The filename is cache.properties. The update flag lets the selector update the values in the cache (and on first call creates the cache). The DigestAlgorithm computes a hashvalue using the java.security.MessageDigest class with its MD5-Algorithm and its standard provider. The new computed hashvalue and the stored one are compared by the EqualComparator which returns 'true' (more correct a value not equals zero (1)) if the values are not the same using simple String comparison.

A useful scenario for this selector is inside a build environment for homepage generation (e.g. with Apache Forrest).

 
      generate the site using forrest 
     

      upload the changed files 
     
         
             
         
     
 
 
Here all changed files are uploaded to the server. The ModifiedSelector saves therefore much upload time.

This selector supports the following nested param's:

namevaluesdescriptionrequired
cache propertyfile which cache implementation should be used
  • propertyfile - using java.util.Properties
no, defaults to 'propertyfile'
algorithm hashvalue | digest which algorithm implementation should be used
  • hashvalue - loads the file content into a String and uses its hashValue() method
  • digest - uses java.security.MessageDigest class
  • no, defaults to digest
    comparator equal | role which comparator implementation should be used
  • equal - simple comparison using String.equals()
  • role - uses java.text.RuleBasedCollator class
  • no, defaults to equal
    update true | false If set to true, the cache will be stored, otherwise the values will be lost. no, defaults to true
    seldirs true | false If set to true, directories will be selected otherwise not no, defaults to true
    cache.* depends on used cache value is stored and given to the Cache-Object for initialisation depends on used cache
    algorithm.* depends on used algorithm value is stored and given to the Algorithm-Object for initialisation depends on used algorithm
    comparator.* depends on used comparator value is stored and given to the Comparator-Object for initialisation depends on used comparator
    If another name is used a BuildException "Invalid parameter" is thrown.

    This selector uses reflection for setting the values of its three interfaces (using org.apache.tools.ant.IntrospectionHelper) therefore no special 'configuration interfaces' has to be implemented by new caches, algorithms or comparators. All present setXX methods can be used. E.g. the DigestAlgorithm can use a specified provider for computing its value. For selecting this there is a setProvider(String providername) method. So you can use a nested .

    Since: Ant 1.6

    Version: 2003-09-13

    Nested Class Summary
    static classModifiedSelector.AlgorithmName
    static classModifiedSelector.CacheName
    static classModifiedSelector.ComparatorName
    Constructor Summary
    ModifiedSelector()
    Bean-Constructor.
    Method Summary
    voidaddParam(String key, Object value)
    Support for nested <param> tags.
    voidaddParam(Parameter parameter)
    Support for nested <param> tags.
    voidconfigure()
    Configures this Selector.
    AlgorithmgetAlgorithm()
    CachegetCache()
    ComparatorgetComparator()
    booleanisSelected(File basedir, String filename, File file)
    Implementation of BaseExtendSelector.isSelected().
    voidsetAlgorithm(ModifiedSelector.AlgorithmName name)
    voidsetCache(ModifiedSelector.CacheName name)
    voidsetComparator(ModifiedSelector.ComparatorName name)
    voidsetParameters(Parameter[] parameters)
    Defined in org.apache.tools.ant.types.Parameterizable.
    voidsetSeldirs(boolean seldirs)
    Support for seldirs attribute.
    voidsetUpdate(boolean update)
    Support for update attribute.
    StringtoString()
    Override Object.toString().
    protected voidtryToSetAParameter(Object obj, String name, String value)
    Try to set a value on an object using reflection.
    voiduseParameter(Parameter parameter)
    Support for nested tags.
    voidverifySettings()
    Overrides BaseSelector.verifySettings().

    Constructor Detail

    ModifiedSelector

    public ModifiedSelector()
    Bean-Constructor.

    Method Detail

    addParam

    public void addParam(String key, Object value)
    Support for nested <param> tags.

    Parameters: key the key of the parameter value the value of the parameter

    addParam

    public void addParam(Parameter parameter)
    Support for nested <param> tags.

    Parameters: parameter the parameter object

    configure

    public void configure()
    Configures this Selector. Does this work only once per Selector object.

    Because some problems while configuring from Selector the configuration is done in the following order:

    1. collect the configuration data
    2. wait for the first isSelected() call
    3. set the default values
    4. set values for name pattern '*': update, cache, algorithm, comparator
    5. set values for name pattern '*.*: cache.cachefile, ...

    This configuration algorithm is needed because you don't know the order of arriving config-data. E.g. if you first set the cache.cachefilename and after that the cache itself, the default value for cachefilename is used, because setting the cache implies creating a new Cache instance - with its defaults.

    getAlgorithm

    public Algorithm getAlgorithm()

    getCache

    public Cache getCache()

    getComparator

    public Comparator getComparator()

    isSelected

    public boolean isSelected(File basedir, String filename, File file)
    Implementation of BaseExtendSelector.isSelected().

    Parameters: basedir as described in BaseExtendSelector filename as described in BaseExtendSelector file as described in BaseExtendSelector

    Returns: as described in BaseExtendSelector

    setAlgorithm

    public void setAlgorithm(ModifiedSelector.AlgorithmName name)

    setCache

    public void setCache(ModifiedSelector.CacheName name)

    setComparator

    public void setComparator(ModifiedSelector.ComparatorName name)

    setParameters

    public void setParameters(Parameter[] parameters)
    Defined in org.apache.tools.ant.types.Parameterizable. Overwrite implementation in superclass because only special parameters are valid.

    See Also: .

    setSeldirs

    public void setSeldirs(boolean seldirs)
    Support for seldirs attribute.

    Parameters: seldirs new value

    setUpdate

    public void setUpdate(boolean update)
    Support for update attribute.

    Parameters: update new value

    toString

    public String toString()
    Override Object.toString().

    Returns: information about this selector

    tryToSetAParameter

    protected void tryToSetAParameter(Object obj, String name, String value)
    Try to set a value on an object using reflection. Helper method for easier access to IntrospectionHelper.setAttribute().

    Parameters: obj the object on which the attribute should be set name the attributename value the new value

    useParameter

    public void useParameter(Parameter parameter)
    Support for nested tags. Parameter named cache, algorithm, comparator or update are mapped to the respective set-Method. Parameter which names starts with cache. or algorithm. or comparator. are tried to set on the appropriate object via its set-methods. Other parameters are invalid and an BuildException will be thrown.

    Parameters: parameter Key and value as parameter object

    verifySettings

    public void verifySettings()
    Overrides BaseSelector.verifySettings().
    Copyright B) 2000-2007 Apache Software Foundation. All Rights Reserved.