ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter reilly <peter.rei...@corvil.com>
Subject Re: Newbie ant question
Date Thu, 20 Mar 2003 15:16:58 GMT
Included is a simple stringreplace... (it only takes one param)
(Cut and paste police may cringe at the code....)
<copy file="dm-example.xml" tofile="dm-example.xml.cdata">
   <filterchain>
       <filterreader classname="my.custom.ant.StringReplace"
                         classpath="my.custom.path">
           <param name="&amp;" value="&amp;amp;"/>
       <filterreader>
       <filterreader classname="my.custom.ant.StringReplace"
                         classpath="my.custom.path">
           <param name="&lt;" value="&amp;lt;"/>
       <filterreader>
   </filterchain>
</copy>

one may also use <if/> from ant-contrib.
<if>
    <uptodate
             srcfile="dm-example.xml"
              targetfile="dm-example.xml.cdata"/>
    <else>
    <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;"/>
</if>

included On Thursday 20 March 2003 14:02, Stefan Bodewig wrote:
> On Thu, 20 Mar 2003, Norman Walsh <ndw@nwalsh.com> wrote:
> > Yes, I understand that, I'm just wondering if there's some simpler
> > ant idiom for expressing the conditionality of a target.
>
> In general tasks are supposed to do the dependency checking.  <copy>
> does so and it works for it.  <replace> will not touch your file if
> there was nothing to replace - unfortunately there will always be
> something to replace in your case.
>
> The "simpler idiom" in this case probably would be a filterreader that
> performed the replacements you need while copying the files.  This
> would give you several benefits as you'd get the dependency tracking
> working and the files wouldn't have to be openend, read, written and
> closed three times.
>
> Unfortunately there isn't such a replace-filter built-in into Ant
> (yet), but several people have asked for it, both a simple and a
> regular expression version.
>
> Stefan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org

Mime
View raw message