Apt Task

## Apt

### Description

Runs the annotation processor tool (apt), and then optionally compiles the original code, and any generated source code. This task requires Java 1.5. It may work on later versions, but this cannot be confirmed until those versions ship. Be advised that the Apt tool does appear to be an unstable part of the JDK framework, so may change radically in future versions. In particular it is likely to be obsolete in JDK 6, which can run annotation processors as part of javac. If the <apt> task does break when upgrading JVM, please check to see if there is a more recent version of Ant that tracks any changes.

This task inherits from the Javac Task, and thus supports nearly all of the same attributes, and subelements. There is one special case, the `fork` attribute, which is present but which can only be set to `true`. That is, apt only works as a forked process.

In addition, it supports the following addition items:

### Parameters

Attribute | Description | Required
compile | After running the Apt, should the code be compiled. (see the `-nocompile` flag on the Apt executable) | No, defaults to false.
factory | The fully qualified classname of the AnnotationProcessFactory to be used to construct annotation processors. This represents the `-factory` command line flag of the Apt executable. | No
factorypathref | The reference id of the path used to find the classes needed by the AnnotationProcessorFactory (and the location of the factory itself). This represents the `-factorypath` flag on the Apt executable. | No
preprocessdir | The directory used for preprocessing. This is the directory where the generated source code will be place. This represents the `-s` flag on the Apt executable. | No

### Parameters specified as nested elements

#### factorypath

You can specify the path used to find the classes needed by the AnnotationProcessorFactory at runtime, using this element. It is represents as a generic path like structure. This represents the `-factorypath` flag on the Apt executable.

#### option

Used to represent a generic option to pass to Apt. This represents the `-A` flag on the Apt executable. You can specify zero or more `<option>` elements.

Attribute | Description | Required
name | The name of the option | Yes.
value | The value to set the option to | Yes.

### Examples

>     <apt srcdir="${src}"
>          destdir="${build}"
>          classpath="xyz.jar"
>          debug="on"
>          compile="true"
>          factory="com.mycom.MyAnnotationProcessorFactory"
>          factorypathref="my.factorypath.id"
>          preprocessdir="${preprocess.dir}">
>     </apt>

compiles all `.java` files under the `${src}` directory, and stores the `.class` files in the `${build}` directory. The classpath used includes `xyz.jar`, and compiling with debug information is on. It also forces the generated source code to be compiled. The generated source code will be placed in `${preprocess.dir}` directory, using the class `com.mycom.MyAnnotationProcessorFactory` to supply AnnotationProcessor instances.

### Notes

The inherited "fork" attribute is set to true by default; please do not change it.

The inherited "compiler" attribute is ignored, as it is forced to use the Apt compiler

Using the Apt compiler with the "compile" option set to "true" forces you to use Sun's Apt compiler, which will use the JDK's Javac compiler. If you wish to use another compiler, you will first need run the Apt processor with the "compile" flag set to "false", and then use a `<javac>` task to compile first your original source code, and then the generated source code:

>     <apt srcdir="${src}"
>          destdir="${build}"
>          classpath="xyz.jar"
>          debug="true"
>          compile="false"
>          factory="com.mycom.MyAnnotationProcessorFactory"
>          factorypathref="my.factorypath.id"
>          preprocessdir="${preprocess.dir}">
>     </apt>

>     <javac srcdir="${src}"
>            destdir="${build}"
>            classpath="xyz.jar"
>            debug="on"/>

>     <javac srcdir="${preprocess.dir}"
>            destdir="${build}"
>            classpath="xyz.jar"
>            debug="true"/>

This may involve more build file coding, but the speedup gained from switching to jikes may justify the effort.