ANT Build:令牌本身是否可以从属性文件中的其他值中解析出来?

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

令牌本身是否可以从属性文件中的其他值中解析出来?

是否可以在不对令牌进行硬编码的情况下评估令牌密钥?令牌本身是否可以从属性文件中的其他值中解析出来?

例如,如果属性文件具有以下标记 (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

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>

带有文本的示例内容:

Welcome to module_title.

替换任务将导致:

Welcome to title_01_bb.

如何实现这一点?

Welcome to JKL.

这可能是非常基础的,但请指导我正确的方向。谢谢。

嵌套 属性 扩展在 Ant 中默认不起作用,如 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:

  1. the expansion of property a${b - likely nothing useful.
  2. 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.

如果您查看解决方法 link,一种解决方案是使用宏定义来复制 属性:

<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>