Reputation: 289
I have a JAVA Ant task which is-
<target name="javatask">
<java classname="arq.sparql" fork="true" outputproperty="javaresult" errorproperty="javaerror1">
<arg value="--data=${tools.dir}/build-config/SPARQL/cpldm.ttl"/>
<arg value="--query=${queryFile}"/>
<jvmarg value="-Xmx1024M"/>
<classpath>
<path>
<fileset dir="${jena.dir}/lib">
<include name="*.jar"/>
</fileset>
</path>
</classpath>
</java>
<echo message="Error at: ${javaerror1} in ${queryFile}"/>
<echo message="Result for ${queryFile} is: ${javaresult}"/>
</target>
Now I want the error message to be echo-ed only if there is a 'javaerror' and the Result message to be echoed if there is no error. So basically its kind of if-else condition, i.e if there is error echo error message , else- Give result message. How can I achieve that
Upvotes: 1
Views: 1756
Reputation: 107040
The latest version of Ant includes a new If and Unless attributes that can be set in almost any task. I've had a few problems with getting it to work, and you do need to have Ant 1.9.1 or higher, but it does make if/else conditions much easier to handle.
For example, you could put this in your <echo/>
statement:
<echo unless:blank="javaerror1">Error at: ${javaerror1} in ${queryFile}</echo>
You might be able to use the set attribute instead:
<echo if:set"javaerror1">Error at: ${javaerror1} in ${queryFile}</echo>
Upvotes: 1
Reputation: 3353
<target name="javataskfailure" if="javaerror1" depends="javatask">
<echo message="Error at: ${javaerror1} in ${queryFile}"/>
<echo message="Result for ${queryFile} is: ${javaresult}"/>
</target>
The task will only execute if the "javaerror1" property exists.
Upvotes: 1