ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vimil Saju <>
Subject Re: "scoping" for macro definitions?
Date Thu, 26 Sep 2013 22:43:24 GMT
I am not sure if this feature is available in ant 1.7 but can't you use namespaces to scope
the macrodefs like follows

<project name="testBuild" default="all" basedir="." xmlns:c="common" >
<typedef file="../build-common/buildCommon.xml"uri="common"/>

Now all the macrodefs in buildCommon.xml has to be accessed as follows

 <c:theirmacro ...

Any macrodef you define in your build.xml can be accessed without using the namespace syntax.

 From: Cyril Sagan <>
To: Ant Users List <> 
Sent: Thursday, September 26, 2013 3:15 PM
Subject: "scoping" for macro definitions?

Is there a way to override a macro defined from a library I cannot
control, my goal is to provide a local implementation, but not have to
change all the callers.

I'm stuck on Ant 1.7.0, and cannot update.

How could I "fake out" a scoping mechanism to accomplish something like:
<super.macroImplementation/> or <project[@name].macroImplemenation/>

I tried using <presetdef/> to "override" the macro, but I can't figure
out how to invoke the original macro of the same name.  I could
redefine the macro from the library in my local ant script, but I
don't want to open a possibility that my local implementation could
get out of sync with the one from the provided library.

Another way to express what I need is the macro equivalent of target
overriding, which is accomplished with the code snip below, but I need
it for <macrodef/>!

    <project name="common_library">
        <target name="stuff">
            <!-- run stuff from common library -->

    <project name="myBuild">
        <import file="common.xml" />
        <target name="stuff" depends="mystuff_first, common_library.stuff"

        <!-- henceforth target="stuff" is *my* implementation -->

But what if its a macro (or scriptdef)?  In principle here's what I was
hoping could
work, but it doesn't, so that's why I'm asking:

    <project name="common_library">
        <macrodef name="routine">
            <attribute name="arg1" />
            <attribute name="arg2" />
                <!-- macro definition from common library -->

    <project name="myBuild">
        <import file="common.xml" />
        <presetdef name="routine">

        <macrodef name="local_routine">
            <attribute name="arg1" />
            <attribute name="arg2" />
                <!-- add some logic here... -->
                <common_library.routine arg1="@{arg1} arg2="@{arg2}" />

        <!-- henceforth <routine/> is *my* implementation -->

Any ideas would be much appreciated.  Thanks.

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