ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Norman Walsh <...@nwalsh.com>
Subject Newbie ant question
Date Thu, 20 Mar 2003 13:42:37 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I've dug through the online docs, but perhaps I missed the salient points.
I'm converting some Makefiles into ant. I used to have the rule:

dm-example.xml.cdata: dm-example.xml
	cat $< | sed "s/&/\\&amp;/g" | sed "s/</\\&lt;/g" > $@

My first attempt to convert this to ant was simply:

  <target name="dm-example.xml.cdata">
    <echo message="Building CDATA version of dm-example.xml ..." />
    <copy file="dm-example.xml" tofile="dm-example.xml.cdata" overwrite="yes"/>
    <replace file="dm-example.xml.cdata" token="&amp;" value="&amp;amp;"/>
    <replace file="dm-example.xml.cdata" token="&lt;" value="&amp;lt;"/>
  </target>

But I discovered that this target always rebuilt the file, regardless
of whether or not the dm-example.xml file was actually newer than
dm-example.xml.cdata. I tried to use 'depends', but of course that
requires a target not a filename.

Eventually, I wound up with the following code:

  <target name="chk.dm-example.xml.cdata">
    <uptodate property="dm-example.xml.cdata.exists"
              srcfile="dm-example.xml"
              targetfile="dm-example.xml.cdata"/>
  </target>

  <target name="dm-example.xml.cdata"
          depends="chk.dm-example.xml.cdata"
          unless="dm-example.xml.cdata.exists">
    <echo message="Building CDATA version of dm-example.xml ..." />
    <copy file="dm-example.xml" tofile="dm-example.xml.cdata" overwrite="yes"/>
    <replace file="dm-example.xml.cdata" token="&amp;" value="&amp;amp;"/>
    <replace file="dm-example.xml.cdata" token="&lt;" value="&amp;lt;"/>
  </target>

Is this really the simplest idiom for this expression? By the time I
have a half-dozen or so of these, keeping track of them all is going
to be really tedious.

It seems like there should be a simpler idiom for "build this target if this
file (these files?) are newer than this file". 

                                        Be seeing you,
                                          norm

- -- 
Norman.Walsh@Sun.COM    | Kinship is healing; we are physicians to each
XML Standards Architect | other.--Oliver Sacks
Web Tech. and Standards |
Sun Microsystems, Inc.  | 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.7 <http://mailcrypt.sourceforge.net/>

iD8DBQE+ecVNOyltUcwYWjsRArVyAKCGBewgvt0qiKnmFkeujk0qpK8ONQCfQmqp
bNyImJQGse9gtoXYR40et24=
=mQgY
-----END PGP SIGNATURE-----

Mime
View raw message