You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Mariusz Nowostawski <ma...@marni.otago.ac.nz> on 2000/05/17 23:11:30 UTC

Re: A question about "available" and doing conditionals in a build xml file.

Well, I am also pretty new to the issue with conditional tasks, but
if Ant allows to have targets with "if", there is really no big
difference to allow targets with "ifnot" or "unless". That would make the
example below given by Glenn much simpler and shorter (and it would mean
no need for ifdef and ifnotdef tasks).

I also like the idea of available + ifdef + ifnotdef `tasks (if we can
have
only if in targets).

Would it be possible for those three tasks to have the same way for
setting a property?  In proposed by Glenn solution attribute
"property" means two different things in "available" and "if*def" tasks,
which can be confusing. Maybe:
<available file="some_well_known_file" property="a.property"/>
...
<ifnotdef test="a.property" property="another.property"/>
<ifdef test="a.property" property="another.property"/>

Mariusz


-----------
Glenn wrote:

> There is a pretty easy way around your problem if you are willing to create
> more targets in your build, use a custom task, and use the "if" attribute
> of the target.
> 
> Try something like the following:
> 
> <target name="compile_src"
> depends="check_idl2java,do_idl2java,do_java_compile">
>   <!-- dummy target used to control the order of execution -->
> </target>
> 
> <target name="check_idl2java">
>   <available file="some_well_known_file" property="found.generated"/>
>   <ifnotdef property="found.generated" set="couldnt.find.generated"/>
> </target>
> 
> <target name="do_idl2java" if="couldnt.find.generated"
> depends="check_idl2java">
>   <!-- do your idl to java compilation --->
> </target>
> 
> <target name="do_java_compile" depends="do_idl2java">
>   <!-- yadda yadda yadda -->
> </target>
> 
> The ifnotdef task simply checks at execute and init time if the property
> specified by the "property" attribute exists.  If it does, it sets the
> property specified by the "set" attribute to "true", or to a specified
> value if there is an = in the text.  There is also an "unset" attribute you
> can use to remove a property.  I have a corresponding ifdef task that does
> the logical opposite.
> 
> Here's the code for the ifnotdef task.  I've moved it from our
> com.ibm.id.tools.ant.taskdefs package to the
> org.apache.tools.ant.taskdefs.optional to make incorporating it a little
> easier for you.  Sorry for the poor indenting, but VisualAge for Java
> doesn't do the best job of exporting code from its repository to a file.
> :-(

[....]

> 
> 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
>