| “Strategies in (*)ability” | [iDareMedia] [JWare] [PET] [CI-Dashboard] |
The $default: value uri lets you query the current setting of a build iteration property. Because AntX-based tools can subclass the Iteration class and change the names of these properties, it is important that your scripts do not hard-code their names. Also, some default properties do not have corresponding Ant project properties but are attributes on the current build iteration object; for example, the configid property is an immutable Iteration object attribute not a project property you can set from Ant. You must explicitly install this value uri’s handler; read the Examples section to see how this is done.
In addition to the AntX iteration defaults, this uri will also return values of defaults you have set within the Ant fixture using regular Ant properties. Specifically, any property that begins with an application-defined prefix (like “myproj.defaults.”) can be queried. The advantage of using the $default: mechanism with your own default properties is the same as for iteration properties: your scripts can be used in different runtime contexts that use different namespaces for global properties.
The general form of the uri is: $default:default-name[?fallback] where default-name is the is the symbolic name of the default property you want read and fallback is your default value for the property if it has not been set explicitly (the default can be the empty string). The symbolic name is usually much shorter that the name of the associated property and more importantly, it is fixed so you can use it in your scripts. The standard (AntX only) set of names are listed below; see each AntX-based tool’s documentation for additional default names.
1) The following snippet declares the default scheme name for the default value uri handler: $default:. This is usually done by an “init” target or at the project’s top level.
<manageuris action="install">
<parameter name="default"
value="com.idaremedia.antx.valueuri.info.DefaultsValueURIHandler"/>
</manageuris>
2) The following snippet shows three different (and independent) projects that use completely different naming schemes for default properties. They all use a shared macrodef mkbuildreport that is unaffected by these differences because it uses the default value handler to get its information. Note that only the short symbolic property name (email) is normalized and if the default has not been set the macrodef attribute is set to the empty string.
[Project 1]
<property name="${$defaultsproperty:prefix}" value="myproj.defaults."/>
<property name="myproj.defaults.email" value="buildadmins@mycompany.com"/>
...
[Project 2]
<property name="${$defaultsproperty:prefix}" value="proj2."/>
<property name="proj2.email" value="john@yahoo.com"/>
...
[Project 3]
<property name="${$defaultsproperty:prefix}" value="com.longlongname.uk."/>
<property name="com.longlongname.uk.email" value="seekrits@longlongname.de"/>
...
Shared antlib macrodef
<macrodef name="mkbuildreport">
<attribute name="email" default="${$default:email?}"/>
...
3) The following snippet dumps to a file defaults.properties both the AntX-related global properties and the custom defaults properties that have been defined explicitly.
<newfile path="${logs}/defaults.properties" overwrite="yes">
<propertyset>
<propertyref prefix="${$default:configid}"/>
<propertyref prefix="${$default:defaults.prefix}"/>
</propertyset>
</newfile>