Q:

ANT Build: Can the token itself be parsed from other values from within the property file?

Can the token itself be parsed from other values from within the property file?
Is it possible to evaluate the token key, without hardcoding the token? Can the token itself be parsed from other values from within the property file?
For example, if the properties file has the following tokens (test.properties):
module_no       =   01
module_code     =   bb

title_01_aa =   ABC
title_02_aa =   DEF
title_03_aa =   GHI
title_01_bb =   JKL
title_02_bb =   MNO
title_03_bb =   PQR

Contents of build.xml
<?xml version="1.0" encoding="utf-8"?>
<project default="repl">
    <property file="test.properties" />
    <target name="repl">
        <replace file="test.txt" token="module_title" value="title_${module_no}_${module_code}" />
    </target>
</project>

Sample content with text:
Welcome to module_title.

The replace task will result in:
Welcome to title_01_bb.

How to achieve this instead?
Welcome to JKL.

This might be very basic, but please do guide me in the right direction. Thank you.

A:

Nested property expansion does not work by default in Ant as described in the documentation:

Nesting of Braces
In its default configuration Ant will not try to balance braces in property expansions, it will only consume the text up to the first closing brace when creating a property name. I.e. when expanding something like ${a${b}} it will be translated into two parts:

the expansion of property a${b - likely nothing useful.
the literal text } resulting from the second closing brace

This means you can't use easily expand properties whose names are given by properties, but there are some workarounds for older versions of Ant. With Ant 1.8.0 and the the props Antlib you can configure Ant to use the NestedPropertyExpander defined there if you need such a feature.

If you check the workarounds link, one solution is to use a macrodef to copy the property:
<property file="test.properties" />
<target name="repl">
    <gettitleprop name="titleprop" moduleno="${module_no}" modulecode="${module_code}" />
    <replace file="test.txt" token="module_title" value="${titleprop}" />
</target>

<macrodef name="gettitleprop">
    <attribute name="name"/>
    <attribute name="moduleno"/>
    <attribute name="modulecode"/>
    <sequential>
        <property name="@{name}" value="${title_@{moduleno}_@{modulecode}}"/>
    </sequential>
</macrodef>

