ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Goktepe" <>
Subject Re: How to achieve "if" and "unless"-style behaviour with macrodefs?
Date Mon, 30 Jul 2007 14:10:49 GMT
You could probably define "if" and "unless" custom attributes in your macro
and then use <isset> with ant-contrib's <if> to check them inside of your

Something like this (untested!):

<macrodef name="my-macro">
    <attribute name="if" default="basedir" />
    <attribute name="unless" default=""/>
    ... other attributes...
        <if> <and><isset property="@{if}" /><not><isset
               ... do stuff
            <else />

<my-macro if="" />

I purposely gave the if and unless attributes default values that cause the
macro to proceed when neither are set in the call. basedir should always be
set and will hopefully never be set.


On 7/30/07, Keith Hatton <> wrote:
> Hi,
> I have cases where it would be useful to call a macrodef if a property
> was set, but to skip it otherwise. If these were targets I could use the
> standard Ant if/unless attributes to achieve this behaviour, but
> macrodefs are called explicitly at certain points in the build file,
> rather than using the Ant dependency model for target execution. I don't
> see any corresponding options for a macrodef or (equivalently in my
> case) for the sequential task. What's the best way to achieve this?
> Thanks,
> Keith
> Axiom Systems Limited is a limited company registered in England and
> Wales. Registered number: 2358771. Registered office: One Forbury
> Square, The Forbury, Reading, Berks RG1 3EB

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