The Command Line Processor Plugin: ArgumentProcessor

What is an ArgumentProcessor?

An ArgumentProcessor is a parser of command line argument which is then call before and after the build file is being parsed. Third party libraries may then be able to have custom argument line argument which modify Ant behaviour.

An ArgumentProcessor is called each time Ant parse an unknown argument, an ArgumentProcessor doesn't take precedence over Ant to parse already supported options. It is then recommended to third party ArgumentProcessor implementation to chose specific 'enough' argument name, avoiding for instance one letter arguments.

It is also called at the different phases so different behaviour can be implemented. It is called just after every arguments are parsed, just before the project is being configured (the build file being parsed), and just after. Some of the methods to be implemented return a boolean: if true is returned, Ant will terminate immediately, without error.

Being called during all these phases, an ArgumentProcessor can just print some specific system properties and quit (like -diagnose), or print some specific properties of a project after being parsed and quit (like -projectHelp), or just set some custom properties on the project and let it run.

How to register it's own ArgumentProcessor

First, the ArgumentProcessor must be an implementation of

Then to declare it: create a file META-INF/services/ which contains only one line the fully qualified name of the class of the implementation. This file together with the implementation class need then to be found in Ant's classpath.