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, Extend Selectors.

  1. Extend Selectors

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

    To create a new Extend Selector, you have to create a class that implements org.apache.tools.ant.types.selectors.ExtendFileSelector. The easiest way to do that is through the convenience base class org.apache.tools.ant.types.selectors.BaseExtendSelector, 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 static selectors demonstrate how to do that because they can also be used as extend selectors.

  2. Static 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 itself.

  3. Selector Containers

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