我正在使用输入任务来收集特定的属性值,我想将它们连接成一个引用我的属性文件的属性值.
我可以生成属性的格式,但在运行时它被视为字符串而不是属性引用.
示例属性文件:
# build.properties
# Some Server Credentials
west.1.server = TaPwxOsa
west.2.server = DQmCIizF
east.1.server = ZCTgqq9A
Run Code Online (Sandbox Code Playgroud)
示例构建文件:
<property file="build.properties"/>
<target name="login">
<input message="Enter Location:" addproperty="loc" />
<input message="Enter Sandbox:" addproperty="box" />
<property name="token" value="\$\{${loc}.${box}.server}" />
<echo message="${token}"/>
</target>
Run Code Online (Sandbox Code Playgroud)
当我调用login并为输入值提供"west"和"1"时,echo将打印$ {west.1.server},但它不会从属性文件中检索属性值.
如果我在消息中硬编码属性值:
<echo message="${west.1.server}"/>
Run Code Online (Sandbox Code Playgroud)
然后Ant将尽职地从属性文件中检索字符串.
如何让Ant接受动态生成的属性值并将其视为要从属性文件中检索的属性?
该的antlib道具提供支持这一点,但据我知道有没有可用的二进制版本,因此还必须从源代码编译它.
另一种方法是使用macrodef:
<macrodef name="setToken">
<attribute name="loc"/>
<attribute name="box"/>
<sequential>
<property name="token" value="${@{loc}.@{box}.server}" />
</sequential>
</macrodef>
<setToken loc="${loc}" box="${box}"/>
Run Code Online (Sandbox Code Playgroud)