Chau Chee Yang
Chau Chee Yang

Reputation: 19650

How to run a custom task few times with different parameters?

I am trying to execute target "MyTarget" and get an error: "Unsupported element echo". Perhaps Macrodef is not the way to do the job. Is there any other way to pass a task to another target/macrodef with different parameters?

<macrodef name="dotask">
    <attribute name="platform" description="" />
    <attribute name="config" description="" />
    <element name="task2" optional="true" />
    <sequential>
        <task2 />
    </sequential>
</macrodef>

<macrodef name="buildsuite2">
    <element name="task" optional="true" />
    <sequential>
        <dotask platform="win32" config="debug">
            <task />
        </dotask>   
        <dotask platform="win32" config="release">
            <task />
        </dotask>
    </sequential>
</macrodef>

    <target name="MyTarget">
        <buildsuite2>
            <task>
                <echo>${platform} ${config}</echo>
            </task>
        </buildsuite2>
    </target>

Upvotes: 1

Views: 200

Answers (1)

Alex K
Alex K

Reputation: 22867

How to run a custom task few times with different parameters?

Yes you can do it with help of antcall task.

The sample:

<target name="method_impl">
    <echo message="${firstParam}"/>
    <echo message="${secondParam}"/>
</target>

<target name="test_calling_twice">
    <echo message="First time call"/>
    <antcall target="method_impl">
        <param name="firstParam" value="fP1"/>
        <param name="secondParam" value="sP1"/>
    </antcall>

    <echo message="Second time call"/>
    <antcall target="method_impl">
        <param name="firstParam" value="fP2"/>
        <param name="secondParam" value="sP2"/>
    </antcall>
</target>

The output will be:

First time call
fP1
sP1
Second time call
fP2
sP2

Upvotes: 1

Related Questions