ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rebhan, Gilbert" <Gilbert.Reb...@huk-coburg.de>
Subject RE: [help] Search a string in a file
Date Tue, 28 Nov 2006 06:41:29 GMT

Hi,

i'm still a newbie to ruby, maybe there's a more
elegant solution, you need jruby available for ant

http://dist.codehaus.org/jruby/jruby-bin-0.9.1.tar.gz


given test.txt =

abcd
xyz
what
why
Rebuild All: 1 failed, 0 skipped
new world
Rebuild All: 0 failed, 0 skipped
techno
Rebuild All: 1 failed, 0 skipped
Rebuild All: 10 failed, 0 Skipped


quick hack =

<target name="depends">
        <script language="ruby">
        <![CDATA[
            counterfailed=0;
            counterskipped=0;
            File.open("Y:/test.txt", "r").each do |line|
                if line =~ /(\d{1,2}).+(\d{1,2})/
                    counterfailed += $1.to_i
                    counterskipped += $2.to_i
                end
            end
            puts 'Summary :' 
            puts 'Failed == ' +counterfailed.to_s
            puts 'Skipped == ' +counterskipped.to_s
            
            $project.setNewProperty "failed", counterfailed.to_s
            $project.setNewProperty "skipped", counterskipped.to_s
            

          ]]>
          </script>
	</target>
 
	<target name="main" depends="depends">     
     <echo>$${failed} == ${failed}</echo>   
     <echo>$${skipped} == ${skipped}</echo>   
	</target>

depends:
   [script] Summary :
   [script] Failed == 12
   [script] Skipped == 0
main:
     [echo] ${failed} == 12
     [echo] ${skipped} == 0
BUILD SUCCESSFUL
Total time: 1 second

The regular expression \d{1,2} matches one or max 2 occurences of 
a digit, hope you don't get such a lot of failed rebuilds ;-)

If needed you can match 1 or 2 or 3 digits with \d{1,3} and so on ...

 
Regards, Gilbert 

-----Original Message-----
From: Rebhan, Gilbert [mailto:Gilbert.Rebhan@huk-coburg.de] 
Sent: Monday, November 27, 2006 4:46 PM
To: Ant Users List
Subject: RE: [help] Search a string in a file


Hi,

use a <loadfile> combined with a filterchain, f.e. =

test.txt

abcd
xyz
what
why
Rebuild All: 1 failed, 0 skipped
new world
Rebuild All: 0 failed, 0 skipped
techno

	<target name="depends">
        <loadfile property="failure.nos" srcfile="Y:/test.txt">
                    <filterchain>
                        <linecontainsregexp>
                            <regexp pattern='Rebuild.*'/>
                        </linecontainsregexp>
                    </filterchain>
                </loadfile>   
	</target>
 
	<target name="main" depends="depends">     
     <echo>$${failure.nos} == ${line.separator}${failure.nos}</echo>   
	</target>

depends:
main:
     [echo] ${failure.nos} ==
     [echo] Rebuild All: 1 failed, 0 skipped
     [echo] Rebuild All: 0 failed, 0 skipped
BUILD SUCCESSFUL
Total time: 359 milliseconds


Regards, Gilbert

 

-----Original Message-----
From: Dharmesh Vyas [mailto:dharmesh.mail@gmail.com] 
Sent: Monday, November 27, 2006 4:31 PM
To: user@ant.apache.org
Subject: [help] Search a string in a file

 Hello all,

Here is what I am trying to implement to identify if my build process
has
failed.

For e.g this are the contents of the input file:
abcd
xyz
what
why
Rebuild All: 1 failed, 0 skipped
new world
Rebuild All: 0 failed, 0 skipped
techno

- Read this file to search for string "Rebuild All: 1 failed, 0 skipped"
and
see how many failures were there.

*The problem I am finding is*
- I am using regex to perform the pattern matching to check if there
were
any failures. Since the line could appear any no of times in the file, i
don't know how shall I implement that.
- Regex takes a string as an input, how can I pass a file to it or there
is
any other task that I shall use.

Here is how I am using regex for an input string.
<target name="searchstring>
<regex property="failure.nos"
                input="Rebuild All: 0 succeeded, 1 failed, 0 skipped"
                regexp="Rebuild All: ([0-9]) failed, ([0-9])"
                select="\1"
                casesensitive="false" />
                <echo>${failure.nos}</echo>
</target>

Thanks a lot in advance,
- Dharmesh.

note: I am sorry if it's a stupid question but I am a novie user/memeber
of
this group.

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