Search code examples
variablesantpropertiesbuildant-contrib

Reuse property value for other property name


I've a question about ANT property.

I want to do this :

<var name="index" value="1"/>
<for param="XXX">
....
<loadproperties prefix="${index}">
    <zipentry zipfile="@{XXXX}" name="YYYY"/>
        <filterchain>
            <linecontains>
                <contains value="ZZZZZ"/>
            </linecontains>
        </filterchain>
</loadproperties>
<echo message="${${index}.ZZZZZ}"/>
....
<math result="index" operand1="${index}" operation="+" operand2="1" datatype="int" />

The problem is to reuse the "index" variable to display the desired property . Is it possible to do that in ANT ? Thank you :)


Solution

  • I found the solution ...

    //use this
    <appendProperty prop="implversion" data="${index}.ZZZZZ" />  
    //don't forget to set that
        <macrodef name="appendProperty">
                   <attribute name="prop" default="" />
                   <attribute name="data" default="" />
                   <sequential>
                           <var name="@{prop}" value="${@{data}}" />
                   </sequential>
        </macrodef>