# RelaxNGCC Ant Task

$Revision: 1.1 $ by Kohsuke Kawaguchi

Ant is a popular open-source build tool. RelaxNGCC comes with an Ant task implementation, which makes it easier to invoke RelaxNGCC from your Ant build script.

This document describes how you can use it.

## Simple example

    <project .... >
      ...

      <taskdef name="relaxngcc" classname="relaxngcc.ant.RelaxNGCCTask">
        <classpath path="lib/relaxngcc.jar"/>
      </taskdef>

      <target ... >
        ...
        <mkdir dir="src/parser/state"/>
        <relaxngcc source="mygrammar.rng" targetdir="src/parser/state">
          <!-- up-to-date check parameters -->
          <depends  dir="." includes="*.rng"/>
          <produces dir="src/relaxngcc/state" includes="*.java"/>
          <produces dir="src/relaxngcc/state" includes="*.class"/>
        </relaxngcc>
      </target>
    </project>

It is usually a good idea to have a `<mkdir>` task before RelaxNGCC, since RelaxNGCC doesn't create a directory. The `source` attribute specifies the source RELAX NG grammar, and the `targetdir` attribute specifies the directory where the generated files will be placed.

The nested `<depends>` and `<produces>` are used to perform up-to-date check. If all the files specified by `<depends>` is older than all the files specified by `<produces>`, then RelaxNGCC won't run. If not, all the files specified by `<produces>` will be deleted (to avoid leaving stale files behind) and RelaxNGCC generates a fresh set of files. One can specify multiple `<depends>` and `<produces>` if necessary. If either one of them is not present, then RelaxNGCC will always re-generate files.

## Synoposis

The RelaxNGCC task supports the following parameter attributes.

Attribute | Description | Required
source | Specifies the RELAX NG grammar file to be compiled. | Yes
targetdir | Specifies a directory to place files produced by RelaxNGCC. This directory needs to exist before you run RelaxNGCC. | Yes
automata | Specifies a directory to place gif files which contains automata produced by RelaxNGCC. You need to have GraphViz in your path. This is a debug option. | No

Following nested element parameters are supported as well. These two type of elements must be used in pair.

### depends

File set that specifies the source files used for up-to-date check. Optional. Technically, this information can be derived by RelaxNGCC itself from the source grammar, but it's not smart enough to do that for now.

### produces

File set that specifies files generated by RelaxNGCC. Optional. Technically this information can be derived by RelaxNGCC itself, but for now it's not that smart.

When both are present, RelaxNGCC will check if any source file is updated. If so, it deletes all the files specified by the `produces` elements before it runs.

RelaxNGCC home