ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Goktepe" <andrewgokt...@gmail.com>
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
macro.

Something like this (untested!):

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

<my-macro if="my.if.property" />

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 unset.property will hopefully never be set.

-Andrew

On 7/30/07, Keith Hatton <khatton@axiomsystems.com> 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
>
>
>

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