ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rahamim, Zvi (Zvi) ** CTR **" <raha...@avaya.com>
Subject RE: Zvi_Q: know the number of token in a file
Date Tue, 22 Jul 2003 12:07:49 GMT
Thanks,
where can I find the propertyregex task?

-----Original Message-----
From: Jan.Materne@rzf.fin-nrw.de [mailto:Jan.Materne@rzf.fin-nrw.de]
Sent: Tuesday, July 22, 2003 2:41 PM
To: user@ant.apache.org
Subject: RE: Zvi_Q: know the number of token in a file


I did a quick hack using AntContrib:


<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="test" basedir="." default="main">
    <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>

    <target name="main">
        <property name="token" value="ant"/>
        <property name="file" value="1.txt"/>
        <loadfile property="tmp" srcfile="src/${file}"/>
        <propertyregex property="nofail" input="${tmp}" regexp="${token}"
select="\1"/>
        <fail message="token '${token}' not found" unless="nofail"/>
    </target>

</project>



First I read the whole content of the file into a property (prerequisite for
the next step).
The I use the same regexp which you use for your <regexp> in
<propertyregex>. <propertyregex>
copies the result of the regexp matching into the property or doesn´t create
that property
if nothing matches.
So I can use <fail> with 'unless' attribute.

Short test with:
1.txt
-----
this file
contains
no token

2.txt
-----
this file
contains the
token ant.


gave: 


ant -Dfile=1.txt
BUILD FAILED
C:\temp\x\build.xml:10: token 'ant' not found

ant -Dfile=2.txt
BUILD SUCCESSFUL



Maybe you can start here ...
If you want to fail if no files contains that regexp and sucess if one or
more contains
that, you can create a temporary file with <concat> and all files. Then read
that file.
BUT: this could eat much memory ...


Jan



> -----Original Message-----
> From: Rahamim, Zvi (Zvi) ** CTR ** [mailto:rahamim@avaya.com]
> Sent: Tuesday, July 22, 2003 1:22 PM
> To: Ant Users List
> Subject: Zvi_Q: know the number of token in a file
> 
> 
> Hi!
> I want to use the replace task to replace tokens.
> But... I also want that if no token is found, the build fails.
> Can you help me?
> Thanks!!!
> 
> ---------------------------------------------------------------------
> 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


Mime
View raw message