Rarar
Rarar

Reputation: 449

Macrodef in Ant : passing a value outside the definition

I have the following macro definition in Ant and I would like to pass the "cmdStatus" value outside this macro def:

<macrodef name="execEtlBinScript">
    <attribute name="script" />
    <sequential>
        <exec executable="@{script}" resultproperty="cmdStatus"/>
    </sequential>
</macrodef>

Do you have any idea if it is possible or not ?

Thank you for any help. Kind regards, foxrafi

Upvotes: 2

Views: 2316

Answers (1)

Nicolas Lalev&#233;e
Nicolas Lalev&#233;e

Reputation: 2013

In your exemple, the property cmdStatus is set and is then available outside the macrodef. But I guess that your issue is that if your call several times your macro, you don't get the next status values as properties in Ant are immutable.

The way to handle it properly is to make the result property an attribute of the macro:

<macrodef name="execEtlBinScript">
    <attribute name="script" />
    <attribute name="resultproperty" />
    <sequential>
        <exec executable="@{script}" resultproperty="@{resultproperty}"/>
    </sequential>
</macrodef>

Then each call to the macrodef will get its value via a different property:

<execEtlBinScript script="somescript" resultproperty="status1" />
<echo message="Result of the first call: ${status1}" />
<execEtlBinScript script="somescript" resultproperty="status2" />
<echo message="Result of the second call: ${status2}" />

Upvotes: 3

Related Questions