From d8f18f1b903f8f7344a3c679504098d185c75ea7 Mon Sep 17 00:00:00 2001
From: Stefan Bodewig
There are three sub-interfaces of Delegate
that may be
+ useful to
+ implement. org.apache.tools.ant.PropertyHelper$PropertyEvaluator
+ is used to expand ${some-string}
into
+ an Object
+ while org.apache.tools.ant.PropertyHelper$PropertySetter
+ is responsible for setting properties.
+ Finally org.apache.tools.ant.property.PropertyExpander
+ is responsible for finding the property name inside a string in the
+ first place (the default extracts foo
+ from ${foo}
).
The logic that replaces ${toString:some-id}
with the
+ stringified representation of the object with
+ id some-id
inside the current build is contained in a
+ PropertyEvaluator similar to the following code:
+public class ToStringEvaluator implements PropertyHelper.PropertyEvaluator { + private static final String prefix = "toString:"; + public Object evaluate(String property, PropertyHelper propertyHelper) { + Object o = null; + if (property.startsWith(prefix) && propertyHelper.getProject() != null) { + o = propertyHelper.getProject().getReference(property.substring(prefix.length())); + } + return o == null ? null : o.toString(); + } +} ++ +
An example of a PropertySetter
can be found
+ in org.apache.tools.ant.property.LocalProperties
which
+ implements storage for local
+ properties.
The default PropertyExpander
looks similar to:
+public class DefaultExpander implements PropertyExpander { + public String parsePropertyName(String s, ParsePosition pos, + ParseNextProperty notUsed) { + int index = pos.getIndex(); + if (s.indexOf("${", index) == index) { + int end = s.indexOf('}', index); + if (end < 0) { + throw new BuildException("Syntax error in property: " + s); + } + int start = index + 2; + pos.setIndex(end + 1); + return s.substring(start, end); + } + return null; + } +} ++
<project name="MyProject" default="dist" basedir="."> diff --git a/docs/manual/usinglist.html b/docs/manual/usinglist.html index 014c0b34d..8a1cbf4c8 100644 --- a/docs/manual/usinglist.html +++ b/docs/manual/usinglist.html @@ -35,7 +35,7 @@ Tasks
Properties
Built-in Properties
- Property Helpers
+ Property Helpers
Example Buildfile
Token Filters
Path-like Structures