diff --git a/docs/manual/CoreTasks/propertyhelper.html b/docs/manual/CoreTasks/propertyhelper.html index 47f1a5046..f6c1800fa 100644 --- a/docs/manual/CoreTasks/propertyhelper.html +++ b/docs/manual/CoreTasks/propertyhelper.html @@ -31,7 +31,7 @@ (b) (hopefully more often) install one or more PropertyHelper Delegates into the PropertyHelper active on the current Project. This is somewhat advanced Ant usage and assumes a working familiarity with the modern Ant APIs. See the description of Ant's -Property Helper for more information. +Property Helper for more information. Since Ant 1.8

Parameters specified as nested elements

diff --git a/docs/manual/using.html b/docs/manual/using.html index df2c444f8..de8ae3c2e 100644 --- a/docs/manual/using.html +++ b/docs/manual/using.html @@ -345,6 +345,62 @@ parsing, etc. This makes Ant's property handling highly extensible; also of inte new propertyhelper task used to manipulate the PropertyHelper and its delegates from the context of the Ant buildfile. +

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;
+    }
+}
+
+

Example Buildfile

 <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