ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Goktepe" <andrewgokt...@gmail.com>
Subject Re: Replace Question
Date Fri, 15 Dec 2006 15:09:19 GMT
If you are running Ant 1.6.3 or later, you can use the <isfileselected>
condition:

    <condition property="skip.replacement">
        <isfileselected file="bin/start.bat">
            <contains text="set bar=foostart" />
        </isfileselected>
    </condition>

The skip.replacement property will be set if the file already contains the
replacement text. You can then run <replace> conditionally on this property.

You could also use ant-contrib with <if> to combine the check with the
execution:

    <if>
         <isfileselected file="bin/start.bat">
            <contains text="set bar=foostart" />
        </isfileselected>
        <then/>
         <else>
             <replace dir="bin" file="bin/start.bat">
                <replacetoken><![CDATA[start]]></replacetoken>
                <replacevalue><![CDATA[set bar=foostart]]></replacevalue>
            </replace>
         </else>
    </if>

-Andrew


On 12/14/06, Fenlason, Josh <jfenlason@ptc.com> wrote:
>
> I want to add a line to a file, but only if the file doesn't already
> contain that line.  I can add the line fine, but I can't figure out how
> to do it conditionally.  Is this possible?   Here's what I have so far.
> Any suggestions would be greatly appreciated.  Thanks in advance.
> <target name="test">
>     <!-- this replace works, but it adds the line every time -->
>     <replace dir="bin" file="bin/start.bat">
>         <replacetoken><![CDATA[start]]></replacetoken>
>         <replacevalue><![CDATA[set bar=foo
> start]]></replacevalue>
>      </replace>
>
>      <!-- this doesn't replace anything no matter if start.bat contains
> set bar=foo or not -->
>      <replace dir="bin" includes="bin/start.bat">
>         <not><contains text="set bar=foo" casesensitive="yes"/></not>
>         <replacetoken><![CDATA[start]]></replacetoken>
>         <replacevalue><![CDATA[set bar=foo
> start]]></replacevalue>
>      </replace>
>
>   </target>
> ,
> Josh.
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message