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."/>
Related
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>
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.
I am trying to concat multiple files (say 15 txt files) to a single file at the same time by separate ant calls.
Say there are 15 concat() run at the same time.
However, the output file was not expected.
The data in the output file is corrupted.
Does anyone have idea to solve this problem?
Example:
Input 1:
a=1
b=2
c=3
Input 2:
d=4
e=5
f=6
Output:
a=1
b=2
d=4
e
c=3=5
f=6
You can do this with the concat task, which take a resource collection such as `filesets' as nested elements, allowing you to concatenate all the files in a single task call. Example:
<concat destfile="${build.dir}/output.txt">
<fileset file="${src.dir}/input1.txt" />
<fileset file="${src.dir}/input2.txt" />
</concat>
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"/>
I'm trying to make an Ant target that runs if ONE of two other targets completes. Basically, assuming I have three targets A1, A2, and B, I want B to run only if A1 OR A2 run. A1 and A2 depend on a condition, so either A1 or A2 will run (but never both).
For example:
<target name="A1" if="${conditionalVar}">
<target name="A2" unless="${conditionalVar}">
<target name="B" depends="????????">
What should the 'depends' for target B be? Is there anyway to do this?
Yes, such a configuration is possible and not very complicated:
The trick is to set a property that will be tested if set (e.g. call it "taskA1.use").
<target name="A1" if="taskA1.use" />
<target name="A2" unless="taskA1.use" />
<target name="B" depends="A1,A2" />
Therefore even if B depends on both tasks A1 and A2 only one will be executed depending of the property "taskA1.use" has been set or not.