Programming your own Selectors

Selector Programming API

Want to define your own selectors? It's easy!

First, pick the type of selector that you want to define. There are three types, and a recipe for each one follows. Chances are you'll want to work with the first one, Custom Selectors.

Custom Selectors

This is the category that Ant provides specifically for youto define your own Selectors. Anywhere you want to use your selector you use the <custom> element and specify the class name of your selector within it. See the Custom Selectors section of the Selector page for details. The <custom> element can be used anywhere the core selectors can be used. It can be contained within Selector Containers, for example.

To create a new Custom Selector, you have to create a class that implements The easiest way to do that is through the convenience base class, which provides all of the methods for supporting <param> tags. First, override the isSelected() method, and optionally the verifySettings() method. If your custom selector requires parameters to be set, you can also override the setParameters() method and interpret the parameters that are passed in any way you like. Several of the core selectors demonstrate how to do that because they can also be used as custom selectors.

Note: If you don't need to set variables on your selector with the the embedded <param> elements, your custom selector could just implement the interface rather than the full interface. Using the latter will give you the most flexibility, though.

Note: If you inherit from or, any selector container will perform a validation pass before calling the isSelected() method. Make sure that all initialization is performed before the validation is done.

Core Selectors

These are the selectors used by Ant itself. To implement one of these, you will have to alter some of the classes contained within Ant.

Selector Containers

Got an idea for a new Selector Container? Creating a new one is no problem:

Copyright © 2002 Apache Software Foundation. All rights Reserved.