views:

161

answers:

1

I have a set of input files, each of which is processed to generate an output file. In one case it's hibernate xml files as input, and java files as output, but that isn't the only case I have to deal with.

In make, I would have set up a rule to tell it how to generate a .java file from an .hbm.xml file (modulo the .hbm.xml specifying a different class name to generate), and modifying a single .hbm.xml files would trigger the build of a single .java file.

How do I express the dependencies in ant so it will only build the out of date .java files and not all of them just because one .hbm.xml changed?

I'm looking at apply and up-to-date, but not seeing a solution yet...

+1  A: 

Have you looked at ant-contrib outofdate task?

The example at the end of the doc looks like something you could use:

  <outofdate property="manual.outofdate"
             outputsources="grammer.sources">
    <sourcefiles>
      <fileset dir="${src.grammer}" includes="**/*.y"/>
    </sourcefiles>
    <mapper type="glob" dir="${src.grammer}" from="*.y" to="${gen.grammer}/*.c"/>
    <mapper type="glob" dir="${src.grammer}" from="*.y" to="${gen.grammer}/*.h"/>
    <sequential>
      <shellscript shell="bash">
        cd ${gen.grammer}
        for g in ${grammer.sources}
        do
            gengrammer $g
        done
      </shellscript>
    </sequential>
  </outofdate>

Also note that you might use ant-contrib "for" task in the body of the outofdate task.

To initialize ant-contrib do this:

<property name="ant-contrib.jar" location="..."/>
<taskdef
  resource="net/sf/antcontrib/antlib.xml"
  uri="http://ant-contrib.sourceforge.net"
>
  <classpath>
    <pathelement location="${ant-contrib.jar}"/>
  </classpath>
</taskdef>
Alexander Pogrebnyak
Just to clarify, if a sub-set of the sources are out of date, then the property named by `outputsources` is set to a list of _just those sources_ and not all of the sources, correct?
retracile
Correct, `outputsources` lists only sources newer than respective targets.
Alexander Pogrebnyak