Retrieving a value from a file using ant

The file contains the following lines. I would like to extract some data from this file.

Number of current user assembly lists: 23

  • 'RevisionBuild' Execution time (in minutes) = 8.40

[Build] RC = 0

I used the following regex to extract the value 23 from this file

<ac:for param="line" list="${logFileContent}" delimiter="${line.separator}"> <sequential> <propertyregex property="noOfBuildlists" input="@{line}" regexp="(.*)Number of current user build lists: (.*)$" select="\2"/> </sequential> </ac:for> 

But the same regex gets no value when I try to extract other lines, such as regexp = "(.) [RevBuild] RC = (.) $" Or regexp = "(.) 'RevisionBuild' Runtime ( in minutes) = (.) $ ", where the extracted values ​​should be 0 and 8.40 respectively.

Can anybody help? Thanks, Aarthi

+6
source share
2 answers

I think this is what interests you. On the input file as shown below

 Number of current user build lists: 23 'RevisionBuild' Run time (in minutes) = 8.40 [Build] RC = 0 

when i execute below target

 <project name="BuildModule" basedir="." default="extract.nums"> <taskdef resource="net/sf/antcontrib/antlib.xml" /> <property environment="env" /> <loadfile property="file" srcfile="${basedir}/inputLog.log"/> <target name="extract.nums"> <for param="line" delimiter="${line.separator}" list="${file}"> <sequential> <propertyregex property="noOfBuildlists" input="@{line}" regexp="Number of current user build lists:\s*([0-9]+)$" select="\1" /> <propertyregex property="revisionBuild" input="@{line}" regexp="'RevisionBuild' Run time\s*\(in minutes\)\s*=\s*([0-9\.]+)$" select="\1" /> <propertyregex property="rcBuild" input="@{line}" regexp="\[Build\] RC\s*\=\s*([0-9]+)$" select="\1" /> </sequential> </for> <echo message="Current user build : ${noOfBuildlists}" /> <echo message="Revision Build : ${revisionBuild}" /> <echo message="RC Build : ${rcBuild}" /> </target> </project> 

I get below output.

 [echo] Current user build : 23 [echo] Revision Build : 8.40 [echo] RC Build : 0 
+9
source

When I use propertyregex , it causes an error if doesn't support the nested "condition" element . In my {android.sdk.air}/tools/ant/build.xml there are many nested "condition" elements. So I tried to find a solution that the Ant standard can provide. I have done it.

Try the following:

 <loadfile encoding="UTF-8" property="property.for.your.string" srcFile="your/file/path" > <filterchain> <tokenfilter> <containsregex pattern="Number of current user build lists:\s*([0-9]+)$" replace="\1" /> </tokenfilter> </filterchain> </loadfile> <echo message="DEBUG LOG: property.for.your.string = ${property.for.your.string}" /> 

I am wondering why Ant calls the attribute “replacement”, which leads to my misunderstanding.

+1
source

Source: https://habr.com/ru/post/921651/


All Articles