Home » Apache Ant Argument Processor

Apache Ant Argument Processor

by Online Tutorials Library

Apache Ant Argument Processor

Ant Argument Processor is a command line processor plugging. It is used to call third party plug-in before or after the build file is parsed.

Third party arguments also may have custom command line argument which modify Ant behavior.

It calls each time whenever Ant process an argument. Ant?s arguments always takes precedence over to ArgumentProcessor arguments.

We can call it at any moment of process and at different-different phases as well to perform various behavior at each phase.

It can be called just after every argument is passed, just before the project is configured and just after as well.

Ant provides an interface ArgumentProcessor which is located inside org.apache.tools.ant package. It contains various methods which are given below.

Ant ArgumentProcessor Methods

Method Description
boolean handleArg(java.util.List<java.lang.String> args) It executes only if after all arguments were parsed.
int readArguments(java.lang.String[] args, int pos) It read the arguments from the command line at the specified position.
void prepareConfigure(Project project,java.util.List<java.lang.String> args) This method is called just before the project being configured.
boolean handleArg(Project project, java.util.List<java.lang.String> arg) It handles the arguments with readArguments(String[], int), just after the project being configured.
void printUsage(java.io.PrintStream writer) It prints the usage of the supported arguments.

How to register it’s own ArgumentProcessor

To register own ArgumentProcessor, it requires couple of steps which are given below.

Implement ArgumentProcessor

First, it must implement ArgumentProcessor interface located into org.apache.ant.ArgumentProcessor.

Declaration

To declare ArgumentProcessor, create a file META-INF/services/org.apache.tools.ant.ArgumentProcessor which contains only one line the fully qualified name of the class of the implementation.

Class Path

This file which implements ArgumentProcessor and the file in which it is declared both together should be found in Ant’s classpath.

Next TopicApache Ant API

You may also like