|
|||||
Recent ArticlesClojure is a relatively new language to appear on the Java Virtual Machine (JVM), although it draws on very mature roots in the form of the LISP langu ... Should You Care About Requirements Engineering? Recently, I (Adil) was invited to participate in a one day seminar on the subject of Requirements Engineering. Whilst I have no direct experience of t ... Tips for Setting Up Your First Business Website To attract all potential customers to your business you need a presence on the web. The problem is that if you haven't set up a website before, you p ... LISP is a general-purpose programming language and is the second-oldest programming language still in use, but how much do you know about it? Did you ... Open Source Tools for Developers: Why They Matter From a developer's point of view use of open-source tools has advantages beyond the obvious economic ones. With the open-source database MySQL in mind ... |
Example of Ant's uptodate TaskExample of Ant's uptodate taskI've had some difficulty getting ant's uptodate task working for me, so decided to come up with a "bare bones" example to demonstrate how it works.'Uptodate' ExampleFirst of all, here's the example:<project default="runtest"> <target name="init"> <touch file="old.txt"/> <sleep seconds="2"/> <touch file="new.txt"/> </target> <target name="check.new.newer"> <uptodate targetfile="new.txt" srcfile="old.txt" property="new.newer"/> </target> <target name="check.old.newer"> <uptodate targetfile="old.txt" srcfile="new.txt" property="old.newer"/> </target> <target name="is.old.newer" if="old.newer"> <echo message="old is newer than new"/> </target> <target name="is.new.newer" if="new.newer"> <echo message="new is newer than old"/> </target> <target name="runtest" depends="init, check.old.newer, check.new.newer, is.old.newer, is.new.newer"> <echo message="done"/> </target> </project> Description of TargetsThe ant script contains the following six targets:
How It WorksI hope it is clear to you what is intended - the files are first created, then checked against each other using the uptodate task to see which is newer, and finally a message (or messages) is printed out according to the conditional targetsis.old.newer and is.new.newer . If the script works as expected, then only one
of the conditional targets will be run, as only one of the files can be newer than the other, and therefore only
one of the two properties tested will actually be set.
Sample OutputWhen the script is run (by typing ant) the following output is produced:C:\uptodate-test>ant Buildfile: build.xml init: check.old.newer: check.new.newer: is.old.newer: is.new.newer: [echo] new is newer than old runtest: [echo] done BUILD SUCCESSFUL Total time: 2 secondsThis is exactly what we would hope to see - the file new.txt has been shown to be newer than the file
old.txt !
SummaryThis is a good example because it demonstrates the setting, and not setting, of properties by the uptodate task, as well as the conditional execution of tasks based on whether properties have been set. The structure shown can form a basis for more complex scripts that use uptodate in conjunction with other tasks to perform conditional compilation or conditional distribution of code.Simon White |