从性能变量的Ant文件 [英] Variables from properties file in Ant
问题描述
我有一个Android应用程序,需要针对不同的环境(如UAT,分期,生产等),待建。每个环境都需要不同的属性(例如,网址,包装等)。
我希望把所有的不同的参数到一个单一的属性文件和preFIX与它相匹配的环境中每个参数。
例如,属性文件将包含 dev.home-URL = http://home_dev.com
的开发环境和刺。家庭URL = http://home.com
的生产环境。
我用下面创建一个指向物业,一个preFIX文件属性 PARAMS
:
<属性文件=parameters.propertiespreFIX =PARAMS/>
和使用属性,我用:
$ {params.home-URL}
问题来了,当我需要添加环境的preFIX的参数。 它最终会这样看,这显然无法做到的:
$ {PARAMS。$ {ENV-preFIX}。家里-URL}
一个关于蚂蚁经常被问到的问题是:
我怎么可以这样做<属性名= 托值=$ {$ {anotherprop}}/>
(双扩展属性)
下面的Ant构建文件是来自一些常见问题。
parameters.properties
dev.home-URL = http://home_dev.com
prod.home-URL = http://home.com
的build.xml
<项目默认=榜样>
<属性名=ENV-preFIX值=开发/>
<属性文件=parameters.propertiespreFIX =PARAMS/>
< macrodef名=propertycopy>
<属性名=姓名/>
<属性名=从/>
<连续>
<属性名=@ {名}值=$ {@ {从}}/>
< /顺序>
< / macrodef>
<目标名称=榜样>
<从= propertycopy名=local.property。PARAMS $ {ENV-preFIX}。家里-URL/>
<回声> $ {local.property}< /回声>
< /目标和GT;
< /项目>
执行例如
任务输出:
构建文件:/workspace/build.xml
例:
[回应] http://home_dev.com
BUILD SUCCESSFUL
总时间:405毫秒
I have an Android app that needs to be built for different environments (e.g., UAT, staging, production, etc.). Each environment needs different properties (e.g., URLs, packages, etc.).
I would like to put all the different parameters into a single properties file and prefix each parameter with the environment it matches to.
For example, the properties file will contain dev.home-url = http://home_dev.com
for the development environment and prod.home-url = http://home.com
for the production environment.
I use the below to create a property that points to the properties file with a prefix of params
:
<property file="parameters.properties" prefix="params" />
And to use a property, I use:
${params.home-url}
The problem comes when I need to add the prefix of the environment to the parameter. It would end up looking like this, which obviously can't be done:
${params.${env-prefix}.home-url}
A frequently asked question about Ant is:
The following Ant build file was inspired by that FAQ.
parameters.properties
dev.home-url = http://home_dev.com
prod.home-url = http://home.com
build.xml
<project default="example">
<property name="env-prefix" value="dev" />
<property file="parameters.properties" prefix="params" />
<macrodef name="propertycopy">
<attribute name="name" />
<attribute name="from" />
<sequential>
<property name="@{name}" value="${@{from}}" />
</sequential>
</macrodef>
<target name="example">
<propertycopy name="local.property" from="params.${env-prefix}.home-url" />
<echo>${local.property}</echo>
</target>
</project>
Executing the example
task outputs:
Buildfile: /workspace/build.xml
example:
[echo] http://home_dev.com
BUILD SUCCESSFUL
Total time: 405 milliseconds
这篇关于从性能变量的Ant文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!