How to check with Ant if files contain a string a OR a string b - ant

I'm looking for a way to make this code snippet work but with one of the three contains being true. So OR instead of AND.
<condition property="warningFilesFound">
<resourcecount when="greater" count="0">
<fileset id="warnings-fileset-id" dir="${target.dir}/xref" includes="**/*.warnings">
<contains text="requires "CHARACTER","RAW" or "COLUMN" for double-byte or multi-byte(UTF8) languages. (3619)"/>
<contains text="requires "CHARACTER" or "RAW" for double-byte languages. (2363)"/>
<contains text="requires "CHARACTER", "RAW", "COLUMN" or "FIXED" for double-byte or multi-byte(UTF8) languages. (3623)"/>
</fileset>
</resourcecount>
</condition>
Only one of the three contains should be true. In this code snippet all three contains must be true. Regular expression?

You should be able to wrap an <or> selector round the contain elements, something like this:
<fileset id="warnings-fileset-id" dir="${target.dir}/xref" includes="**/*.warnings">
<or>
<contains text="requires "CHARACTER","RAW" or "COLUMN" for double-byte or multi-byte(UTF8) languages. (3619)"/>
<contains text="requires "CHARACTER" or "RAW" for double-byte languages. (2363)"/>
<contains text="requires "CHARACTER", "RAW", "COLUMN" or "FIXED" for double-byte or multi-byte(UTF8) languages. (3623)"/>
</or>
</fileset>

Related

Read more than one text file for a foreach loop in Ant and store the line values as different properties

I have a requirement with respect to ant loops.
It says I have 3 different text files each with say 3 lines (each line is a one word string for all files).
Now I need a foreach loop in Ant that reads all 3 files at same time for the first line in each file and stores the values accordingly as 3 different properties. This way for every single iteration of loop I can refer to a target where I can pass these properties for target execution.
The loop will hence run 3 times and execute that target 3 times one for each iteration.
Say for example I have the following sample code:-
<target name="read">
<loadfile property="file" srcfile="./dist/DB_Critical_Stub_Data.txt"/>
<loadfile property="fileversion" srcfile="./dist/version.txt"/>
<loadfile property="filecomponent" srcfile="./dist/component.txt"/>
<foreach list="${file},${fileversion},${filecomponent}" param="line,line1,line2" delimiter="${line.separator}" target="start-stub"/>
</target>
<target name="start-stub">
<property name="stub-name" value="${line}"/>
<property name="stub-version" value="${line1}"/>
<property name="stub-component" value="${line2}"/>
<startStub name="${stub-name}" version="${stub-version}" component="${stub-component"}/>
</target>
Any suggestions/help here would be highly appreciated.

ant: replace double empty line with single

I am trying to set up an script that goes through each file and replace all consecutive empty lines with just one empty line. something like:
aaa
bbb
converted to
aaa
bbb
so far I have:
<replace file="web.xml" value="">
<replacefilter>
<replacetoken>\n\n</replacetoken>
<replacevalue>\n</replacevalue>
</replacefilter>
</replace>
but it isn't working at all
so far the only way is:
<target name="-remove-blank">
<replaceregexp file="${basedir}/temp/WEB-INF/web.xml"
match="(\r?\n)\s*\r?\n"
flags="g"
replace="\1"
/>
</target>
but this deletes all blank lines whereas I need it to only delete when there are 2 or more consecutive blank lines
<replaceregexp
file="some.file"
match="(${line.separator}){2}"
replace="${line.separator}"
flags="g"
/>
doesn't work.
-- EDIT --
given file
line1
line2
line3
line4
line5
line6
and using :
<replaceregexp
file="foo.txt"
match="^(${line.separator}){2,}"
replace="${line.separator}"
flags="mg"
/>
or when on windows (better use ${line.separator} and let ant do the work):
<replaceregexp
file="foo.txt"
match="^(\r\n){2,}"
replace="\r\n"
flags="mg"
/>
works :
line1
line2
line3
line4
line5
line6
If lines contain whitespaces you have to use :
match="^(\s*${line.separator}){2,}"
or
match="^(\s*\r\n){2,}"

Parsing hh:mm:ss[.xxx]

I would like to parse the time expression hh:mm:ss.xxx (hours, minutes, seconds, milliseconds) in a .XML file. It should look something like that:
<condition property="illegal-tc">
<matches pattern="the_pattern" string="${timeCode}"/>
</condition>
What I need is the negate of the pattern \d{2}:\d{2}:\d{2}.\d{3}.
I tried by doing ^[\d{2}:\d{2}:\d{2}.\d{3}]$ but it doesn't work properly.
The [...] construct matches the set of characters between those [ and ]. To get a negative match you need the (?! ... ) "negative lookahead" construct.
The pattern ^(?!\d{2}:\d{2}:\d{2}\.\d{3}).*$ matches anything that is not "hh:mm:ss.fff".
Note that a single digit hour, or a fraction of less than 3 digits will still match!
I found out another solution: do the "legal-tc" and negate it in the fail condition with the unless tag like this:
<condition property="legal-tc">
<matches pattern="^\d{2}:\d{2}:\d{2}.\d{3}$" string="${timeCode}"/>
</condition>
<fail message="Illegal Time Code" unless="legal-tc"/>

How to add the AM or PM to time date format in ANT task?

I have a date and time stamp that I would like to add the AM or PM value to. I haven't found the way to do this. Here is my code:
<target name="updateDate">
<propertyset id="tdate"></propertyset>
<tstamp>
<format property="tdate" pattern="MM-dd-yyyy HH:mm"/>
</tstamp>
<echo>Updating build date to: ${tdate}</echo>
<replaceregexp byline="true">
<regexp pattern="BUILD_DATE:String\s+=\s+(['|"])([a-zA-Z0-9-:\s]+)(['|"])"/>
<substitution expression="BUILD_DATE:String = \1${tdate}\3"/>
<fileset dir="project/src/model">
<include name="ProjectModel.as"/>
</fileset>
</replaceregexp>
</target>
Straight from the documentation:
a Am/pm marker Text PM
So
<format property="tdate" pattern="MM-dd-yyyy HH:mm a"/>
Note that this is redundant with HH, since HH prints the hour from 00 to 23. Use hh to get the hour from 01 to 12.

Ant: Check if two numbers are equal

I have an ant task which should compare two values for equality. If the two values are not equal, I'd like to fail:
<condition property="versionDoesNotMatch">
<not>
<equals arg1="applicationVersion" arg2="releaseNotesVersion"/>
</not>
</condition>
<fail if="versionDoesNotMatch" message="Version of Application and Release notes does not match."/>
According to the ant output, both values, releaseNotesVersion and applicationVersion have the same value 1.7 but the condition always evaluates to true - which because of the not would mean, that the numbers are not equal. Which makes me wonder, if ant would have troubles comparing those kind of values ?
You're matching two literal strings in your example; these will never be equal and so your condition always evaluates to true. Assuming that your args are Ant properties, you need to evaluate the property values like this:
<condition property="versionDoesNotMatch">
<not>
<equals arg1="${applicationVersion}" arg2="${releaseNotesVersion}"/>
</not>
</condition>
<fail if="versionDoesNotMatch" message="Version of Application and Release notes does not match."/>

Resources