ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Phil Hanna <Phil.Ha...@sas.com>
Subject RE: Time-based dependencies
Date Wed, 12 Jul 2000 19:12:48 GMT
Thanks, Glenn.  You're right, this is closer to a solution.

The example I gave needed to test foo.bat to see if it was *older* than foo.zip, not newer.
 In other words, if I have foo.bat from Monday and there is a foo.zip dated Tuesday, my foo.bat
is out of date, and I need to do the unzip.

This is analogous to compile - link - create DLL for .c files.  In make, you set up targets
(well, actually there are built-in rules, but let's pretend there aren't) that declare the
.dll file to be dependent on the .obj, and the .obj on the .c.  make figures out which if
any are out of date and starts the build at the appropriate point.

Now that I think of it, perhaps this could be accomplished by a custom task "older" similar
to "available":

<target name="init">
   <older first="foo.bat" second="foo.zip" property="bat.is.older"/>
</target>

<target name="unzip" if="bat.is.older" depends="init">
  ... unzip foo.zip
</target>

The implementation should set the property to true if the first object does not exist or if
its timestamp is less than the timestamp of the second object.

-----Original Message-----
From: glennm@ca.ibm.com [mailto:glennm@ca.ibm.com]
Sent: Wednesday, July 12, 2000 2:54 PM
To: ant-dev@jakarta.apache.org
Subject: Re: Time-based dependencies






You need the latest CVS version of Ant my friend. :-) Stefan just commited
an "unless" attribute to Target, which executes the target _unless_ the
named property exists.  It doesn't solve your timestamp problem, but it
does get you a step closer.

So something like the following should work:

<target name="init">
  <available file="foo.zip" property="found.foo.zip" />
</target>

<target name="download_foo" unless="found.foo.zip" depends="init">
  ... do your download stuff
</target>

As for the time dependancy problem, why would you have a foo.bat newer than
foo.zip?  Are you making local modifications to the file, but expecting
them to be updated in the zip at a later date?

Glenn McAllister
TID - Software Developer - VisualAge for Java
IBM Toronto Lab, (416) 448-3805
"An approximate answer to the right question is better than the
right answer to the wrong question." - John W. Tukey


Please respond to ant-dev@jakarta.apache.org

To:        "'ant-dev@jakarta.apache.org'" <ant-dev@jakarta.apache.org>
cc:
Subject:        Time-based dependencies

I have an application that

1. downloads foo.zip file from the web
2. unzips foo.zip
3. runs foo.bat that came from foo.zip

If foo.bat already exists and is newer than foo.zip, I don't need to do
step 2.
If foo.zip is already downloaded, I don't need to run step 1.

How can I set up my build.xml to only do the minimum required, based on the
existence and file time comparisons that a makefile would do?

The solution doesn't seem to relate to the target "depends" attribute,
because that only refers to whether the other target has been executed in
the current Ant project.  The "available" task can be used to set a
property if a file *exists*, but not if it does *not* exist or if it is out
of date.  Similarly, the target "if" attribute causes a target to be run if
a property exists, but not if it does not exist.

What I think I need is something like

<target name="run" depends="unzip">...</target>
<target name="unzip" depends="download"
if="foo.bat_is_older_than_foo.zip">...</target>
<target name="download" if="foo.zip_does_not_exist">...</target>

Am I missing something obvious?  make handles this easily.

Phil Hanna
E-Commerce Solutions
SAS Institute, Inc.
Phil.Hanna@sas.com
(919) 677-8000 x4284





Mime
View raw message