anttargetmacrodef

Generate Ant tasks with macro


I've been searching for a possibility to generate ANT targets from top-level macro.

Details:

We have heterogenic build system. ANT+IVY is used as top-level (inherited solutin, can't be changed). Some projects are built via MSBuild, called from ANT via exec task. For each of these projects, there's at least two distinct calls to msbuild (wrapped with macro for brevity), one in "build" target, and one in "clean". Two of them are different only by "target" parameter. So I was guessing, if there's possibility for something like this:

Extension nodes:

<extensionpoint name="build-ext-point" />
<extensionpoint name="clean-ext-point" />
<target name="build" depends="build-ext-point" />
<target name="clean" depends="clean-ext-point" />

My magic macro:

<macrodef name="msbuild-proj" />
    <attribute name="project" />
    <sequential>
        <target name="@{project}-build" >
            <msbuild project="@{project}" target="Build" />
        </target>
        <target name="@{project}-clean" >
            <msbuild project="@{project}" target="Clean" />
        </target>
    </sequential>
</macrodef>

How it would be used:

<msbuild-proj project="CPP-proj" />

Thanks!

P.S: Yeah I know that I can define those build and clean overridden, or via ext point, or whatever. The question is actually whether I can remove some code duplication.

UPD: I'd answer this by myself. At the point, there's no such possibility. Mainly, because Target class is a task container, but not a task. So, it cannot be placed into container. So I guess I'll write some kind of extensible task.


Solution

  • Actually done this. Does its job, although some caveats are present. For those interested: https://bitbucket.org/targetsan/ant-events