ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stirling, Scott" <scott.stirl...@workscape.com>
Subject uptodate vs. outofdate and if/unless gotchas
Date Thu, 04 Mar 2004 15:43:58 GMT
Hi,

I was confused about the use and interpretation of these tasks.  Thought I'd share my experience
in case it helps others.

These tasks seem like they do the same thing on the surface, but they actually set a property
based on opposite conditions.

- <outofdate> sets a property if target is older than source.
- <uptodate> sets a property if target is newer than source.

The Ant <uptodate> task docs state: "the value of the property is set to true if the
timestamp of the target file(s) is more recent than the timestamp of the corresponding source
file(s)."

The antcontrib <outofdate> task docs state: "This is an extension of uptodate . . .
If any of the target file's dates are earlier than any of the source file's dates . . . [it
does its thing]"

What's the difference?  You really have to think about what the authors mean by "more recent"
and "earlier."  They are opposite.  And I think the statement that <outofdate> is an
extension of <uptodate> is misleading because it's behavior is not only extended, but,
in a sense, inverted.

Q: Was Caesar's birth more recent than yours?
A: No.

Q: Was Caesar's birth earlier than yours?
A: Yes.

Think about the task names and how we use the same words in English:
uptodate:
Q: Is your resume up to date?
A: Yes, I updated it yesterday.

outofdate:
Q: Is your resume out of date?
A: No, I updated it yesterday.

Now think about how you use a property that these tasks would set in an if/unless target attribute,
e.g.:

This target depends on is-webdoclet-needed, which executes an <outofdate> to check timestamps
on web.xml and struts-config.xml:
<target name="webdoclet" 
        description="=> generate struts-config.xml and web.xml"
        depends="is-webdoclet-needed"
        if="webdoclet.generated.outofdate">

This target depends on is-ejbdoclet-needed, which executes an <uptodate> to check timestamps
on an EJB jar and some source files:
<target name="ejbdoclet" 
        description="=> run ejbdoclet over all ejb code"
        depends="is-ejbdoclet-needed"
        unless="ejb.generated.uptodate">

Hope this helps someone,
Scott Stirling
Workscape, Inc.

P.S. Note, the <uptodate> doc claims that multiple target files can be specified using
a <mapper>, but this can be extremely difficult or impossible, depending on whether
there's any naming relationship between sources and targets.  For general use, if you need
to check the status of more than one target file and the names differ by more than just file
extension, you should go right ahead and use <outofdate> because it works like you'd
want it to.

***********************************************************************
This message is intended only for the use of the intended recipient and
may contain information that is PRIVILEGED and/or CONFIDENTIAL.  If you
are not the intended recipient, you are hereby notified that any use,
dissemination, disclosure or copying of this communication is strictly
prohibited.  If you have received this communication in error, please
destroy all copies of this message and its attachments and notify us
immediately.
***********************************************************************


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message