The use of a propertyFile allows great flexibility in the Replace task. But
when the propertyFile attribute is used, it requires that replacefilters are
created which specify which token will be replaced by the value associated
with
a given property key. Complex files may have very large numbers of tokens
to
be replaced. They may also be in a state of flux, where the number and name
of
tokens to replace changes frequently. This starts to become a maintenance
issue.
One option, presented here, is to allow the following alternative. If a
propertyFile is used and there are no task attribute nor nested
replacefilte(s)
tasks, use the propertyFile key(s) as the token to replace and replace it
with
the associated propertyFile value(s). This allows the ant build file to
remain
unchanged even as the source file and the propertyFile continue to evolve.
The change specified above was made on our version of Ant1.4. It is very
convenient. A diff of the original Replace.java file and the modified
version
is included below.
190a191,204
> if (token == null && replacefilters.size() == 0) {
> Enumeration props = properties.propertyNames();
> String prop;
> String value;
> Replacefilter filter;
> while (props.hasMoreElements()) {
> prop = (String)props.nextElement();
> value = (String)properties.getProperty(prop);
> filter = new Replacefilter();
> filter.setToken(prop);
> filter.setValue(value);
> replacefilters.add(filter);
> }
> }
231c245
< if (token == null && replacefilters.size() == 0) {
---
> if (token == null && replacefilters.size() == 0 && propertyFile ==
null) {
233c247
< + "must be specified";
---
> + "must be specified when no property file is specified";
This change has been submitted to the Ant Enhancemnet/Bug list with the
following information.
Summary: Enhancement to "Replace" task when useing "propertyFile"
attribute.
Product: Ant
Version: 1.4
Platform: All
OS/Version: Other
Status: NEW
Severity: Enhancement
Priority: Other
Component: Core tasks
AssignedTo: [EMAIL PROTECTED]
ReportedBy: [EMAIL PROTECTED]
Bruce Elliott
Test Engineer
Knowledgenet
e-mail: [EMAIL PROTECTED]
tel: 480 315-4659
fax: 480 315-4007