| “Strategies in (*)ability” | [iDareMedia] [JWare] [PET] [CI-Dashboard] |
[guide] $variable: |
The $variable: uri (also $var:) lets you read the current value of a mutable AntX property and optionally provide a default value if that property does not exist. An important feature of this uri is its ability to chain to $property: uris; for example, you can chain property and variable uris together to get double or triple property deferencing. This uri’s handler is builtin into AntX; it is always available whenever you enable value URIs.
The general form of the uri is: $var[iable]:variable-name[?[default]] where variable-name is the variable property to be read and default is the default value to use if the property is undefined (this value can be the empty string). You can use the AntX value uri property reference syntax $(…) to get double property deferencing but you must chain to get more levels of dereferencing.
1) The following snippet sets a variable conf based on the name of the target property. The value of that variable is read repeatedly without using an Ant property to store it.
<assign variable="conf" value="${config}/${$property:target?dev|$lowercase:}.conf"/>
<assert filenotempty="${$var:conf}" msg="File '${$var:conf}' exists."/>
<property file="${$var:conf}"/>
2) The following snippet applies a set of configuration files to the current project. The files are organized by name; for example, setting the layout parameter to “webapp-builder” will cause the files named webapp.conf and webapp-builder.conf to be applied in that order. The script use a variable filename to track the changing file name and the $var: uri to extract its information.
<macrodef name="startup">
<attribute name="layout"/>
...
<property file="${templates}/all.conf"/>
<foreach i="layoutname" list="@{layout}" delim="-" mode="local">
<assign var="filename" op="+s" value="-${layoutname}"/>
<property file="${templates}/${$var:filename}.conf"/>
</foreach>
...
</macrodef>