org.apache.tools.ant.types.selectors.modifiedselector
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 simpliest example is
<copy todir="dest"> <filelist dir="src"> <modified/> </filelist> </copy>
The same example rewritten as CoreSelector with setting the all values (same as defaults are) would be
<copy todir="dest"> <filelist 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> </filelist> </copy>
And the same rewritten as CustomSelector would be
<copy todir="dest"> <filelist 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> </filelist> </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/mycompony-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
Nested Class Summary | |
---|---|
static class | ModifiedSelector.AlgorithmName
The enumerated type for algorithm.
|
static class | ModifiedSelector.CacheName
The enumerated type for cache.
|
static class | ModifiedSelector.ComparatorName
The enumerated type for algorithm.
|
Constructor Summary | |
---|---|
ModifiedSelector() Bean-Constructor. |
Method Summary | |
---|---|
void | addClasspath(Path path)
Add the classpath. |
void | addParam(String key, Object value)
Support for nested <param> tags. |
void | addParam(Parameter parameter)
Support for nested <param> tags. |
void | buildFinished(BuildEvent event)
Signals that the last target has finished. |
void | buildStarted(BuildEvent event)
Signals that a build has started. |
void | configure()
Configures this Selector.
|
Algorithm | getAlgorithm()
Get the algorithm type to use. |
Cache | getCache()
Get the cache type to use. |
ClassLoader | getClassLoader()
Returns and initializes the classloader for this class. |
Comparator | getComparator()
Get the comparator type to use. |
boolean | getDelayUpdate()
Getter for the delay update |
int | getModified()
Getter for the modified count |
boolean | isSelected(Resource resource)
Implementation of ResourceSelector.isSelected().
|
boolean | isSelected(File basedir, String filename, File file)
Implementation of BaseExtendSelector.isSelected().
|
protected Object | loadClass(String classname, String msg, Class type)
Loads the specified class and initializes an object of that class.
|
void | messageLogged(BuildEvent event)
Signals a message logging event. |
protected void | saveCache()
save the cache file |
void | setAlgorithm(ModifiedSelector.AlgorithmName name)
Set the algorithm type to use. |
void | setAlgorithmClass(String classname)
Setter for algorithmClass. |
void | setCache(ModifiedSelector.CacheName name)
Set the cache type to use. |
void | setCacheClass(String classname)
Setter for cacheClass. |
void | setClassLoader(ClassLoader loader)
Set the used ClassLoader.
|
void | setComparator(ModifiedSelector.ComparatorName name)
Set the comparator type to use. |
void | setComparatorClass(String classname)
Setter for comparatorClass. |
void | setDelayUpdate(boolean delayUpdate)
Setter for the delay update |
void | setModified(int modified)
Setter for the modified count |
void | setParameters(Parameter[] parameters)
Defined in org.apache.tools.ant.types.Parameterizable.
|
void | setSeldirs(boolean seldirs)
Support for seldirs attribute. |
void | setSelres(boolean newValue)
Support for selres attribute. |
void | setUpdate(boolean update)
Support for update attribute. |
void | targetFinished(BuildEvent event)
Signals that a target has finished. |
void | targetStarted(BuildEvent event)
Signals that a target is starting. |
void | taskFinished(BuildEvent event)
Signals that a task has finished. |
void | taskStarted(BuildEvent event)
Signals that a task is starting. |
String | toString()
Override Object.toString(). |
protected void | tryToSetAParameter(Object obj, String name, String value)
Try to set a value on an object using reflection.
|
void | useParameter(Parameter parameter)
Support for nested tags.
|
void | verifySettings() Overrides BaseSelector.verifySettings(). |
Parameters: path the classpath
Parameters: key the key of the parameter value the value of the parameter
Parameters: parameter the parameter object
Parameters: event recieved BuildEvent
Parameters: event recieved BuildEvent
Because some problems while configuring from
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.
Returns: the enumerated algorithm type
Returns: the enumerated cache type
Returns: the classloader
Returns: the enumerated comparator type
Returns: true if we should delay for performance
Returns: modified count
Parameters: resource The resource to check
Returns: whether the resource is selected
See Also: isSelected
Parameters: basedir as described in BaseExtendSelector filename as described in BaseExtendSelector file as described in BaseExtendSelector
Returns: as described in BaseExtendSelector
Parameters: classname the classname msg the message-part for the BuildException type the type to check against
Returns: a castable object
Parameters: event recieved BuildEvent
Parameters: name an enumerated algorithm type.
Parameters: classname new value
Parameters: name an enumerated cache type.
Parameters: classname new value
Parameters: loader the ClassLoader to use
Parameters: name an enumerated comparator type.
Parameters: classname new value
Parameters: delayUpdate true if we should delay for performance
Parameters: modified count
Parameters: parameters the parameters to set.
See Also: .
Parameters: seldirs new value
Parameters: newValue the new value
Parameters: update new value
Parameters: event recieved BuildEvent
Parameters: event received BuildEvent
Parameters: event recieved BuildEvent
Parameters: event recieved BuildEvent
Returns: information about this selector
Parameters: obj the object on which the attribute should be set name the attributename value the new value
Parameters: parameter Key and value as parameter object