tags:

views:

43

answers:

1

I am still learning how to use ANT well, and I wanted to understand if there is some reasonable way to do file tasks in it, similar to Rake and Make:

http://martinfowler.com/articles/rake.html#FileTasks

"With a file you are referring to actual files rather than task names. So 'build/dev/rake.html' and 'dev/rake.xml' are actual files. The html file is the output of this task and the xml file is the input. You can think of a file task as telling the build system how to make the output file - indeed this is exactly the notion in make - you list the output files you want and tell make how to make them.

An important part of the file task is that it's not run unless you need to run it. The build system looks at the files and only runs the task if the output file does not exist or it's modification date is earlier than the input file. File tasks therefore work extremely well when you're thinking of things at a file by file basis."

So in other words, let's say I want to run a custom binary and I only want that binary to run if any of the files have changed. This is related to this question, but I don't want to run the binary at all, not only pass a part of the fileset (i.e. there is only one in the fileset and I don't want the tool to run at all).

The ideal solution would also not be a loooong thing, but rather could be easily applied to any target -- perhaps using some ANT JavaScript or custom task?

+1  A: 

Use ant-contrib outofdate task. It has exactly the properties you are asking for. Here is ant-contrib website.

Here is a template on how to integrate it into your build:

<taskdef
  resource="net/sf/antcontrib/antlib.xml"
>
  <classpath>
    <pathelement location="${ant-contrib.jar}"/>
</taskdef>

<outofdate>
 <sourcefiles path="dev/rake.xml"/>
 <targetfiles path="build/dev/rake.html"/>
 <sequential>
   ... do your work here ...
   ... will only run if rake.html is older than rake.xml ...
 </sequential>
</outofdate>
Alexander Pogrebnyak