ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Re: Using if/unless within a target
Date Wed, 09 Aug 2000 20:49:13 GMT

Don't use property substitution.  Do

<target name="test1" depends="check_for_depend" if="string.present">

The if attribute is simply expecting the name of the attribute.  The way
you have it coded, ant will replace string.present with ${string.present},
since it can't find it at parse time (unless they've changed things in the
week that I've been on vacation).  Just before the target is executed, it
looks for property ${string.present}, not string.present.

Glenn McAllister
TID - Software Developer - VisualAge for Java
IBM Toronto Lab, (416) 448-3805
"An approximate answer to the right question is better than the
right answer to the wrong question." - John W. Tukey

Please respond to

To:        "''" <>
Subject:        Using if/unless within a target

I am trying to use "if" within a target tag, and the documentation
that if the property is set, the target will be executed.  The small
buildfile below indicates that this is not the case.  When I execute this
buildfile, I would expect to see: "executing test1", instead I don't see
echo messages.  Likewise, if I replace the "if" with "unless", I see both
echo messages.

Have I set this up incorrectly?  When I turn on verbose, I see the message
that "string.present" is set to true.
This behavior seems buggy and contrary to the documentation.

I am using the release version 1.1, and have also tried it with last
build (08/09) with the same result.

Ralph Bohnet

<project name="testConditions" default="all" >
 <target name="check_for_depend" >
   <available property="string.present" classname="java.lang.String" />
   <available property="not.present" classname="foo" />

  <target name="test1" depends="check_for_depend" if="${string.present}">
   <echo message="executing test1"/>

  <target name="test2" depends="check_for_depend" if="${not.present}">
   <echo message="executing test2"/>

  <target name="all" depends="test1,test2" />


(See attached file: C.gif)
(See attached file: att1.htm)

View raw message