From 8ff0a1229189912701348624b729d25328c338c2 Mon Sep 17 00:00:00 2001
From: Stefan Bodewig
-Loads property values from a valid xml file.
+Loads property values from a valid xml file. This XML property file:
+
+By default, this load
+does no processing of the input. In particular, unlike the
+Property task, property references
+(i.e., ${foo}) are not resolved.
+
+
+
+For example, with semantic attribute processing enabled, this XML property
+file:
+XmlProperty
Description
+ <root>
+ <properties>
+ <foo>bar</foo>
+ </properties>
+ </root>
+
+is roughly equivalent to this java property file:
+
+ root.properties.foo = bar
+
+
+Semantic Attributes
+
+Input processing can be enabled by using the semanticAttributes
+attribute. If this attribute is set to true (its default is
+false), the following processing occurs as the input XML file
+is loaded:
+
+
+
+
+
+
+
+ <root>
+ <properties>
+ <foo location="bar"/>
+ <quux>${root.properties.foo}</quux>
+ </properties>
+ </root>
+
+is roughly equivalent to the following fragments in a build.xml file:
+
+ <property name="root.properties.foo" location="bar"/>
+ <property name="root.properties.quux" value="${root.properties.foo}"/>
+
+
<xmlproperty file="somefile.xml" />+ + +
Load contents of somefile.xml as Ant properties, -generating the property names from the -file's element and attribute names.
+Here is an example xml file that does not have any semantic attributes.
<root-tag myattr="true"> @@ -62,28 +145,110 @@ file's element and attribute names. </root-tag>-
This is an example xml file.
- -root-tag(myattr)=true +default loading
+This entry in a build file: +
<xmlproperty file="somefile.xml" />+is equivalent to the following properties: ++ root-tag(myattr)=true root-tag.inner-tag=Text root-tag.inner-tag(someattr)=val root-tag.a2.a3.a4=false-These are the properties loaded by this task from the previous example file.
- +collapseAttributes=false
+This entry in a build file:
<xmlproperty file="somefile.xml" collapseAttributes="true"/>- -Load contents of somefile.xml as Ant properties collapsing attributes as nodes.
- -root-tag.myattr=true +is equivalent to the following properties: ++ root-tag.myattr=true root-tag.inner-tag=Text root-tag.inner-tag.someatt=val root-tag.a2.a3.a4=false-These are the properties loaded by this task from the previous example file, with - attribute collapsing true.
+keepRoot=false
+This entry in a build file: +
<xmlproperty file="somefile.xml" keepRoot="false"/>+is equivalent to the following properties: ++ inner-tag=Text + inner-tag(someattr)=val + a2.a3.a4=false ++ +Semantic Attributes
+ +Here is an example xml file that has semantic attributes.
++ <root-tag> + <version value="0.0.1"/> + <build folder="build"> + <classes id="build.classes" location="${build.folder}/classes"/> + <reference refid="build.classes"/> + </build> + <compile> + <classpath pathid="compile.classpath"> + <pathelement location="${build.classes}"/> + </classpath> + </compile> + <run-time> + <jars>*.jar</jars> + <classpath pathid="run-time.classpath"> + <path refid="compile.classpath"/> + <pathelement path="${run-time.jars}"/> + </classpath> + </run-time> + </root-tag> ++ +default loading (semanticAttributes=true)
+This entry in a build file: +
<xmlproperty file="somefile.xml" + semanticAttributes="true"/>+is equivalent to the following entries in a build file: ++ <property name="version" value="0.0.1"/> + <property name="build.folder" value="build"/> + <property name="build.classes" location="${build.folder}/classes" id="build.classes"/> + <property name="build.reference" refid="build.classes"/> + + <property name="run-time.jars" value="*.jar/> + + <classpath id="compile.classpath"> + <pathelement location="${build.classes}"/> + </classpath> + + <classpath id="run-time.classpath"> + <path refid="compile.classpath"/> + <pathelement path="${run-time.jars}"/> + </classpath> ++ +includeSemanticAttribute="true"
+This entry in a build file: +
<xmlproperty file="somefile.xml" + semanticAttributes="true" + includeSemanticAttribute="true"/> ++is equivalent to the following entries in a build file: ++ <property name="version.value" value="0.0.1"/> + <property name="build.folder" value="build"/> + <property name="build.classes.location" location="${build.folder}/classes"/> + <property name="build.reference.refid" refid="build.location"/> + + <property name="run-time.jars" value="*.jar/> + + <classpath id="compile.classpath"> + <pathelement location="${build.classes}"/> + </classpath> + + <classpath id="run-time.classpath"> + <path refid="compile.classpath"/> + <pathelement path="${run-time.jars}"/> + </classpath> +
diff --git a/src/etc/testcases/taskdefs/xmlproperty/goldfiles/keeproot-collapse-original.properties b/src/etc/testcases/taskdefs/xmlproperty/goldfiles/keeproot-collapse-original.properties new file mode 100644 index 000000000..8797a3f8f --- /dev/null +++ b/src/etc/testcases/taskdefs/xmlproperty/goldfiles/keeproot-collapse-original.properties @@ -0,0 +1,5 @@ +root-tag.myattr=true +root-tag.inner-tag=Text +root-tag.inner-tag.someattr=val +root-tag.a2.a3.a4=false + diff --git a/src/etc/testcases/taskdefs/xmlproperty/goldfiles/keeproot-nocollapse-original.properties b/src/etc/testcases/taskdefs/xmlproperty/goldfiles/keeproot-nocollapse-original.properties new file mode 100644 index 000000000..58b372ecd --- /dev/null +++ b/src/etc/testcases/taskdefs/xmlproperty/goldfiles/keeproot-nocollapse-original.properties @@ -0,0 +1,5 @@ +root-tag(myattr)=true +root-tag.inner-tag=Text +root-tag.inner-tag(someattr)=val +root-tag.a2.a3.a4=false + diff --git a/src/etc/testcases/taskdefs/xmlproperty/goldfiles/nokeeproot-collapse-original.properties b/src/etc/testcases/taskdefs/xmlproperty/goldfiles/nokeeproot-collapse-original.properties new file mode 100644 index 000000000..bc4a02c7f --- /dev/null +++ b/src/etc/testcases/taskdefs/xmlproperty/goldfiles/nokeeproot-collapse-original.properties @@ -0,0 +1,4 @@ +inner-tag=Text +inner-tag.someattr=val +a2.a3.a4=false + diff --git a/src/etc/testcases/taskdefs/xmlproperty/goldfiles/nokeeproot-nocollapse-original.properties b/src/etc/testcases/taskdefs/xmlproperty/goldfiles/nokeeproot-nocollapse-original.properties new file mode 100644 index 000000000..40a15a8b8 --- /dev/null +++ b/src/etc/testcases/taskdefs/xmlproperty/goldfiles/nokeeproot-nocollapse-original.properties @@ -0,0 +1,4 @@ +inner-tag=Text +inner-tag(someattr)=val +a2.a3.a4=false + diff --git a/src/etc/testcases/taskdefs/xmlproperty/inputs/original.xml b/src/etc/testcases/taskdefs/xmlproperty/inputs/original.xml new file mode 100644 index 000000000..2bf54a152 --- /dev/null +++ b/src/etc/testcases/taskdefs/xmlproperty/inputs/original.xml @@ -0,0 +1,5 @@ ++ + diff --git a/src/etc/testcases/taskdefs/xmlproperty/inputs/override.xml b/src/etc/testcases/taskdefs/xmlproperty/inputs/override.xml index 9ae88991f..ea01264eb 100644 --- a/src/etc/testcases/taskdefs/xmlproperty/inputs/override.xml +++ b/src/etc/testcases/taskdefs/xmlproperty/inputs/override.xml @@ -1,5 +1,10 @@Text ++ false \ No newline at end of file diff --git a/src/main/org/apache/tools/ant/taskdefs/XmlProperty.java b/src/main/org/apache/tools/ant/taskdefs/XmlProperty.java index 90ec7f48c..37bc35107 100644 --- a/src/main/org/apache/tools/ant/taskdefs/XmlProperty.java +++ b/src/main/org/apache/tools/ant/taskdefs/XmlProperty.java @@ -113,7 +113,7 @@ import org.xml.sax.SAXException; * * + Optionally, to more closely mirror the abilities of the Property * task, a selected set of attributes can be treated specially. To - * enable this behavior, the "semanticAttribute" property of this task + * enable this behavior, the "semanticAttributes" property of this task * must be set to true (it defaults to false). If this attribute is * specified, the following attributes take on special meaning * (setting this to true implicitly sets collapseAttributes to true as @@ -133,9 +133,10 @@ import org.xml.sax.SAXException; * *
* <root-tag> - * <build location="build"> - * <classes id="build.classes" location="${build.location}/classes"/> - * <reference refid="build.location"/> + * <build> + * <build folder="build"> + * <classes id="build.classes" location="${build.folder}/classes"/> + * <reference refid="build.classes"/> * </build> * <compile> * <classpath pathid="compile.classpath"> @@ -155,9 +156,9 @@ import org.xml.sax.SAXException; *is equivalent to the following entries in a build file:
* *- * <property name="build.location" location="build"/> - * <property name="build.classes.location" location="${build.location}/classes"/> - * <property name="build.reference" refid="build.location"/> + * <property name="build" location="build"/> + * <property name="build.classes" location="${build.location}/classes"/> + * <property name="build.reference" refid="build.classes"/> * * <property name="run-time.jars" value="*.jar/> * @@ -193,13 +194,13 @@ import org.xml.sax.SAXException; *