|
Writing a Subversion SubTask
To write a subversion subtask, you must extend either SubversionSubTask or SubversionListenerTask.
SubversionSubTask extends AbstractSubversionTask, which in turn extends org.apache.tools.ant.Task. SubversionSubTask defines the abstract method
getCommandName() which should return a String with the name of one of subversion's subcommands (ie. add, commit, etc. - see subversion documentation if you
don't know what this means).
SubversionListenerTask extends SubversionSubTask and implements the java.beans.PropertyChangeListener interface. This means you must also implement the
propertyChange() method. For more information on how to do this, consult the java API. It also provides the convenience method setProperties and enforces
the implementation of the abstract getProperties() call. getProperties() should return an array of Strings, corresponding to local variables you want set when there is
a PropertyChangeEvent generated for them in the main SubversionTask. The list of bound properties is defined in SubversionTask as
public static enum BoundProperties { ... }. The setProperties call takes a PropertyChangeEvent as it's argument, and looks to see if the property to change is
one of the Strings returned by getProperties(). If it is, and if the current property is null (ie. it was not set), it overwrites it with the new property.
Here's an example:
public class LogTask extends SubversionListenerClass implements Serializable {
...
public Boolean xml;
public String[] listeners = {"xml", "quiet"};
...
public String[] getProperties() {
return listeners;
}
public void propertyChange(PropertyChangeEvent pce) {
setProperties(pce);
}
public Boolean getXml() {
return xml;
}
public void setXml(Boolean xml) {
this.xml = xml;
}
public Boolean getQuiet() {
return quiet;
}
public void setQuiet(Boolean quiet) {
this.quiet = quiet;
}
}
NOTE: You *must* define both getters and setters for any properties which you want to use this way
The preceding code would act like this in implementation:
<subversion quiet="true" xml="false"">
<log xml="true"/">
</subversion>
Log would inherit quiet as true from it's parent, and xml would be overriden to be true.
|