You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by DanVegas <da...@hotmail.com> on 2010/02/06 10:46:30 UTC

Conditional help

Hi all,

I'm new to using Ant and need a little help with an Task I am working on?

In one part of it I need to check if a string does notexist in a certain
file and if it doesn't then I want to add it.
I looked through the manual/web and couldn't find any way of doing it.

Pseudo code:
...
<if>
   <isfalse>
      <contained in file file="${somefile}" value="${somestring}" />
          <then>
             <replace file="${src}/index.html">
                 <replacefilter token="@mytoken@"
value="@mytoken@${somestring}"/>
             </replace>
         </then>
   </isfalse>
</if>
...

Any help greatly appreciated
-- 
View this message in context: http://old.nabble.com/Conditional-help-tp27477844p27477844.html
Sent from the Ant - Users mailing list archive at Nabble.com.


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


AW: Conditional help

Posted by Ja...@rzf.fin-nrw.de.
Instead of first selecting a file and then checking its content I would do the other order:
1. Select all files which contains the searchstring
2. replace the the tokens

1. is done with a selector: <contains>
2. your <replace> task, but with nested <fileset> from #1


<replace>
    <!-- use dir,includes,excludes for narrowing all files to a smaller amount -->
    <fileset dir="..." includes="...">
        <!-- checking the content is more expensive than checking names -->
        <contains text="${searchstring}"/>
    </fileset>
    <!-- if no file remains, 'replace' will do nothing -->
    <replacefilter token="@mytoken@" value="@mytoken@${somestring}"/>
</replace>


Jan    

>-----Ursprüngliche Nachricht-----
>Von: DanVegas [mailto:dan_vegas@hotmail.com] 
>Gesendet: Samstag, 6. Februar 2010 10:47
>An: user@ant.apache.org
>Betreff: Conditional help
>
>
>Hi all,
>
>I'm new to using Ant and need a little help with an Task I am 
>working on?
>
>In one part of it I need to check if a string does notexist in 
>a certain
>file and if it doesn't then I want to add it.
>I looked through the manual/web and couldn't find any way of doing it.
>
>Pseudo code:
>...
><if>
>   <isfalse>
>      <contained in file file="${somefile}" value="${somestring}" />
>          <then>
>             <replace file="${src}/index.html">
>                 <replacefilter token="@mytoken@"
>value="@mytoken@${somestring}"/>
>             </replace>
>         </then>
>   </isfalse>
></if>
>...
>
>Any help greatly appreciated
>-- 
>View this message in context: 
>http://old.nabble.com/Conditional-help-tp27477844p27477844.html
>Sent from the Ant - Users mailing list archive at Nabble.com.
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org
>
>

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