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"/>.
Modifier and Type | Class and Description |
---|---|
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.
|
parameters
description, location, project
Constructor and Description |
---|
ModifiedSelector()
Bean-Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addClasspath(Path path)
Add the classpath.
|
void |
addParam(Parameter parameter)
Support for nested <param> tags.
|
void |
addParam(java.lang.String key,
java.lang.Object value)
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.
|
java.lang.ClassLoader |
getClassLoader()
Returns and initializes the classloader for this class.
|
java.util.Comparator |
getComparator()
Get the comparator type to use.
|
boolean |
getDelayUpdate()
Getter for the delay update
|
int |
getModified()
Getter for the modified count
|
boolean |
isSelected(java.io.File basedir,
java.lang.String filename,
java.io.File file)
Implementation of BaseExtendSelector.isSelected().
|
boolean |
isSelected(Resource resource)
Implementation of ResourceSelector.isSelected().
|
protected java.lang.Object |
loadClass(java.lang.String classname,
java.lang.String msg,
java.lang.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(java.lang.String classname)
Setter for algorithmClass.
|
void |
setCache(ModifiedSelector.CacheName name)
Set the cache type to use.
|
void |
setCacheClass(java.lang.String classname)
Setter for cacheClass.
|
void |
setClassLoader(java.lang.ClassLoader loader)
Set the used ClassLoader.
|
void |
setComparator(ModifiedSelector.ComparatorName name)
Set the comparator type to use.
|
void |
setComparatorClass(java.lang.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.
|
java.lang.String |
toString()
Override Object.toString().
|
protected void |
tryToSetAParameter(java.lang.Object obj,
java.lang.String name,
java.lang.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().
|
getParameters
getError, setError, validate
checkAttributesAllowed, checkChildrenAllowed, circularReference, clone, dieOnCircularReference, dieOnCircularReference, dieOnCircularReference, getCheckedRef, getCheckedRef, getCheckedRef, getCheckedRef, getDataTypeName, getRefid, invokeCircularReferenceCheck, isChecked, isReference, noChildrenAllowed, pushAndInvokeCircularReferenceCheck, setChecked, setRefid, tooManyAttributes
getDescription, getLocation, getProject, log, log, setDescription, setLocation, setProject
public void verifySettings()
verifySettings
in class BaseSelector
public void configure()
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.
protected java.lang.Object loadClass(java.lang.String classname, java.lang.String msg, java.lang.Class type)
classname
- the classnamemsg
- the message-part for the BuildExceptiontype
- the type to check againstpublic boolean isSelected(Resource resource)
isSelected
in interface ResourceSelector
resource
- The resource to checkResourceSelector.isSelected(Resource)
public boolean isSelected(java.io.File basedir, java.lang.String filename, java.io.File file)
isSelected
in interface FileSelector
isSelected
in class BaseExtendSelector
basedir
- as described in BaseExtendSelectorfilename
- as described in BaseExtendSelectorfile
- as described in BaseExtendSelectorprotected void saveCache()
public void setAlgorithmClass(java.lang.String classname)
classname
- new valuepublic void setComparatorClass(java.lang.String classname)
classname
- new valuepublic void setCacheClass(java.lang.String classname)
classname
- new valuepublic void setUpdate(boolean update)
update
- new valuepublic void setSeldirs(boolean seldirs)
seldirs
- new valuepublic void setSelres(boolean newValue)
newValue
- the new valuepublic int getModified()
public void setModified(int modified)
modified
- countpublic boolean getDelayUpdate()
public void setDelayUpdate(boolean delayUpdate)
delayUpdate
- true if we should delay for performancepublic void addClasspath(Path path)
path
- the classpathpublic java.lang.ClassLoader getClassLoader()
public void setClassLoader(java.lang.ClassLoader loader)
loader
- the ClassLoader to usepublic void addParam(java.lang.String key, java.lang.Object value)
key
- the key of the parametervalue
- the value of the parameterpublic void addParam(Parameter parameter)
parameter
- the parameter objectpublic void setParameters(Parameter[] parameters)
setParameters
in interface Parameterizable
setParameters
in class BaseExtendSelector
parameters
- the parameters to set.addParam(String,Object).
public void useParameter(Parameter parameter)
parameter
- Key and value as parameter objectprotected void tryToSetAParameter(java.lang.Object obj, java.lang.String name, java.lang.String value)
obj
- the object on which the attribute should be setname
- the attributenamevalue
- the new valuepublic java.lang.String toString()
public void buildFinished(BuildEvent event)
buildFinished
in interface BuildListener
event
- recieved BuildEventBuildEvent.getException()
public void targetFinished(BuildEvent event)
targetFinished
in interface BuildListener
event
- recieved BuildEventBuildEvent.getException()
public void taskFinished(BuildEvent event)
taskFinished
in interface BuildListener
event
- recieved BuildEventBuildEvent.getException()
public void buildStarted(BuildEvent event)
buildStarted
in interface BuildListener
event
- recieved BuildEventpublic void targetStarted(BuildEvent event)
targetStarted
in interface BuildListener
event
- received BuildEventBuildEvent.getTarget()
public void taskStarted(BuildEvent event)
taskStarted
in interface BuildListener
event
- recieved BuildEventBuildEvent.getTask()
public void messageLogged(BuildEvent event)
messageLogged
in interface BuildListener
event
- recieved BuildEventBuildEvent.getMessage()
,
BuildEvent.getException()
,
BuildEvent.getPriority()
public Cache getCache()
public void setCache(ModifiedSelector.CacheName name)
name
- an enumerated cache type.public Algorithm getAlgorithm()
public void setAlgorithm(ModifiedSelector.AlgorithmName name)
name
- an enumerated algorithm type.public java.util.Comparator getComparator()
public void setComparator(ModifiedSelector.ComparatorName name)
name
- an enumerated comparator type.