The easiest way to have real "file tasks" in ANT

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

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

"With the file, you are referring to the actual files, not the task names. So" build / dev / rake.html "and" dev / rake.xml "are the actual files. The html file is the result of this task and the xml file is you can think of the task of the file, how to tell the build system how to make the output file - indeed, that's exactly the concept in make - you specify the output files you want and tell how to make them.

An important part of the file task is that it won't run unless you need to run it. The build system scans the files and runs the task only if the output file does not exist or the modification date is higher than the input file. Thus, file tasks work very well when you think about things in a file through a file base. "

So, let's say I want to run a custom binary, and I 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 just transfer part of a set of files (i.e., there is only one per set of files, and I don't want the tool to run at all).

A perfect solution wouldn't be unpretentious either, but could easily be applied to any goal - perhaps using some ANT JavaScript or custom tasks?

+2


source to share


1 answer


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

Here's an example on how to integrate it into your assembly:



<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>

      

+1


source







All Articles