ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kamran Hameed <>
Subject A Question regarding conditionals
Date Sun, 03 Jan 2010 14:30:30 GMT
Folks i have two questions

1. I want to check whether an environment variable is defined or not. e-g i
want to check whether the variable JAVA_HOME is set or not. How can i do
that. Currently the way i am doing that is :

  <property environment="env"/>
    <property name="java_home" value="${env.JAVA_HOME}"/>

    <target name="all">
*        <contains string="${java_home}" substring="JAVA_HOME"/> // the line
doing it*
    <antcall target="do_if_java_is_true"/>
    <antcall target="do_if_java_is_false"/>

so in the highlighted line, i am checking the whether the variable
$java_home contains JAVA_HOME or not. If it does, then it means that
JAVA_HOME is not set else it is set.

Now i want to ask that is it the right way to check or is there any better

2. The second question is that based on the above condition, i want to
execute separate targets. i-e if JAVA_HOME is set, then execute a different
target, else execute a different task. The way i am doing it is i am calling
i am calling two antcall as

*    <antcall target="do_if_java_is_true"/>*
*    <antcall target="do_if_java_is_false"/>*

<target name="do_if_java_is_false"
   if=""  depends="compile,jars,clean>

<target name="do_if_java_is_true"
    unless=""  depends="javaspecific,compile,jars,clean>

Now, the problem is that though i am able to detect somehow that whether
java is defined or not. But it executes both the targets i-e the "depends"
attribute of both the targets gets executed whereas i dont want the depends
attribute of both the target to be executed....

Can any help how can i correct Or do it more elegantly??

Kamran Hameed

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message