Class ModifiedSelector

java.lang.Object
All Implemented Interfaces:
Cloneable, EventListener, BuildListener, Parameterizable, ResourceSelector, ExtendFileSelector, FileSelector

public class ModifiedSelector extends BaseExtendSelector implements BuildListener, ResourceSelector

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 simplest example is

   <copy todir="dest">
       <fileset dir="src">
           <modified/>
       </fileset>
   </copy>
 

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

   <copy todir="dest">
       <fileset dir="src">
           <modified update="true"
                     cache="propertyfile"
                     algorithm="digest"
                     comparator="equal">
               <param name="cache.cachefile"     value="cache.properties"/>
               <param name="algorithm.algorithm" value="MD5"/>
           </modified>
       </fileset>
   </copy>
 

And the same rewritten as CustomSelector would be

   <copy todir="dest">
       <fileset dir="src">
           <custom class="org.apache.tools.ant.type.selectors.ModifiedSelector">
               <param name="update"     value="true"/>
               <param name="cache"      value="propertyfile"/>
               <param name="algorithm"  value="digest"/>
               <param name="comparator" value="equal"/>
               <param name="cache.cachefile"     value="cache.properties"/>
               <param name="algorithm.algorithm" value="MD5"/>
           </custom>
       </fileset>
   </copy>
 

If you want to provide your own interface implementation you can do that via the *classname attributes. If the classes are not on Ant's core classpath, you will have to provide the path via nested <classpath> element, so that the selector can find the classes.

   <modified cacheclassname="com.mycompany.MyCache">
       <classpath>
           <pathelement location="lib/mycompany-antutil.jar"/>
       </classpath>
   </modified>
 

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).

 <target name="generate-and-upload-site">
     <echo> generate the site using forrest </echo>
     <antcall target="site"/>

     <echo> upload the changed files </echo>
     <ftp server="${ftp.server}" userid="${ftp.user}" password="${ftp.pwd}">
         <fileset dir="htdocs/manual">
             <modified/>
         </fileset>
     </ftp>
 </target>
 

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

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 <param name="algorithm.provider" value="MyProvider"/>.

Since:
Ant 1.6