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.

  1. Custom 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 <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 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 core selectors demonstrate how to do that because they can also be used as custom selectors.

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

  3. Selector Containers

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