ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject RE: Zvi_Q: know the number of token in a file
Date Tue, 22 Jul 2003 11:40:54 GMT
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/"/>

    <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}"
        <fail message="token '${token}' not found" unless="nofail"/>


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:
this file
no token

this file
contains the
token ant.


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

ant -Dfile=2.txt

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 ...


> -----Original Message-----
> From: Rahamim, Zvi (Zvi) ** CTR ** []
> 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:
> For additional commands, e-mail:

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