Apache Ant Custom Components
Ant allows us to create custom components according to our requirement. The custom components can be condition, filter, selector etc, and are defined outside the ant core api.
The custom components behave like Ant core components.
The custom components are the normal Java classes which can implement classes and interface. It looks like writing a custom task which defines attributes by setter and getter methods.
The <typedef> element is used to implement the custom components into the Ant core.
Creating Custom Component
It is a three phase process. First create a Java class then define <typedef> element and after that use it within build file.
Example
Create a Java class for condition.
Now define <typedef> by specifying Java class.
By doing this, we have successfully created a custom element <alluppercase> which further can be used in our project. See the build.xml file.
// build.xml
Custom Selector
In the above example, we created a custom condition element.Now we will create a custom selector.Selectors are datatypes and to create custom selector, it must implement
org.apache.tools.ant.types.selectors.FileSelector interface. This interface has a single method isSeletected(File basedir, String filename, File file) which must be overridden. An example of custom selector is given below.
// Java Class
// Type Defining
// build.xml
Same like, we can create custom filters as well.