Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@apache.org Received: (qmail 95877 invoked from network); 6 Nov 2002 08:44:17 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 6 Nov 2002 08:44:17 -0000 Received: (qmail 5753 invoked by uid 97); 6 Nov 2002 08:45:15 -0000 Delivered-To: qmlist-jakarta-archive-ant-dev@jakarta.apache.org Received: (qmail 5718 invoked by uid 97); 6 Nov 2002 08:45:14 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 5700 invoked by uid 97); 6 Nov 2002 08:45:13 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Date: 6 Nov 2002 08:43:46 -0000 Message-ID: <20021106084346.18047.qmail@icarus.apache.org> From: bodewig@apache.org To: jakarta-ant-cvs@apache.org Subject: cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs XmlPropertyTest.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N bodewig 2002/11/06 00:43:46 Modified: docs/manual/CoreTasks xmlproperty.html src/etc/testcases/taskdefs/xmlproperty/inputs override.xml src/main/org/apache/tools/ant/taskdefs XmlProperty.java src/testcases/org/apache/tools/ant/taskdefs XmlPropertyTest.java Added: src/etc/testcases/taskdefs/xmlproperty/goldfiles keeproot-collapse-original.properties keeproot-nocollapse-original.properties nokeeproot-collapse-original.properties nokeeproot-nocollapse-original.properties src/etc/testcases/taskdefs/xmlproperty/inputs original.xml Log: Doc patches and additional tests for . Submitted by: Paul Christmann Revision Changes Path 1.4 +187 -22 jakarta-ant/docs/manual/CoreTasks/xmlproperty.html Index: xmlproperty.html =================================================================== RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTasks/xmlproperty.html,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- xmlproperty.html 4 Sep 2002 11:05:16 -0000 1.3 +++ xmlproperty.html 6 Nov 2002 08:43:45 -0000 1.4 @@ -5,11 +5,72 @@ -

XmlProperty

Description

-Loads property values from a valid xml file. +Loads property values from a valid xml file. This XML property file: +

  +  <root>
  +    <properties>
  +      <foo>bar</foo>
  +    </properties>
  +  </root>
  +
+is roughly equivalent to this java property file: +
  +  root.properties.foo = bar
  +
+ +

+By default, this load +does no processing of the input. In particular, unlike the +Property task, property references +(i.e., ${foo}) are not resolved. +

+ +

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: +
    +
  • Property references are resolved.
  • +
  • The following attriubtes are treated differently: +
      +
    • id: The property is associated with the given id value.
    • +
    • location: The property is treated as a file location
    • +
    • refid: The property is set to the value of the + referenced property.
    • +
    • value: The property is set to the value indicated.
    • +
    +
  • +
  • Path-like Structures can be defined + by use of the following attributes: +
      +
    • pathid: The given id is used to identify a path. The + nested XML tag name is ignored. Child elements can be used + (XML tag names are ignored) to identify elements of the path.
    • +
    +
  • +
+

+For example, with semantic attribute processing enabled, this XML property +file: +

  +  <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}"/>
  +
+

Parameters

@@ -31,29 +92,51 @@ keepRoot - If false, it doesn't include the xml root tag as a first - value in the property name. + Keep the xml root tag as the + first value in the property name. No, default is true. validate - If true, it enables validation. + Validate the input file. No, default is false. collapseAttributes - If true, it treats attributes as nested elements. + Treat attributes as nested elements. + No, default is false. + + + semanticAttributes + Enable special handling of certain attribute names. + See the Semantic Attributes + section for more information. No, default is false. + + includeSemanticAttribute + Include the semantic attribute name + as part of the property name. Ignored if + semanticAttributes is not set to true. + See the Semantic Attributes + section for more information. + No, default is false. + + + rootDirectory + The directory to use for resolving file references. Ignored + if semanticAttributes is not set to true. + No, default is ${basedir}. + - +

Examples

-
   <xmlproperty file="somefile.xml" />
+
+ +

Non-semantic Attributes

-

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 @@
      </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>
  +

1.1 jakarta-ant/src/etc/testcases/taskdefs/xmlproperty/goldfiles/keeproot-collapse-original.properties Index: keeproot-collapse-original.properties =================================================================== root-tag.myattr=true root-tag.inner-tag=Text root-tag.inner-tag.someattr=val root-tag.a2.a3.a4=false 1.1 jakarta-ant/src/etc/testcases/taskdefs/xmlproperty/goldfiles/keeproot-nocollapse-original.properties Index: keeproot-nocollapse-original.properties =================================================================== root-tag(myattr)=true root-tag.inner-tag=Text root-tag.inner-tag(someattr)=val root-tag.a2.a3.a4=false 1.1 jakarta-ant/src/etc/testcases/taskdefs/xmlproperty/goldfiles/nokeeproot-collapse-original.properties Index: nokeeproot-collapse-original.properties =================================================================== inner-tag=Text inner-tag.someattr=val a2.a3.a4=false 1.1 jakarta-ant/src/etc/testcases/taskdefs/xmlproperty/goldfiles/nokeeproot-nocollapse-original.properties Index: nokeeproot-nocollapse-original.properties =================================================================== inner-tag=Text inner-tag(someattr)=val a2.a3.a4=false 1.2 +5 -0 jakarta-ant/src/etc/testcases/taskdefs/xmlproperty/inputs/override.xml Index: override.xml =================================================================== RCS file: /home/cvs/jakarta-ant/src/etc/testcases/taskdefs/xmlproperty/inputs/override.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- override.xml 5 Nov 2002 14:51:52 -0000 1.1 +++ override.xml 6 Nov 2002 08:43:45 -0000 1.2 @@ -1,5 +1,10 @@ + 1.1 jakarta-ant/src/etc/testcases/taskdefs/xmlproperty/inputs/original.xml Index: original.xml =================================================================== Text false 1.9 +20 -9 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/XmlProperty.java Index: XmlProperty.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/XmlProperty.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- XmlProperty.java 5 Nov 2002 14:51:52 -0000 1.8 +++ XmlProperty.java 6 Nov 2002 08:43:45 -0000 1.9 @@ -113,7 +113,7 @@ * *

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 @@ * *

    * <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 @@
    * 

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 @@
    * 
  • semanticAttributes: Indicate whether attributes * named "location", "value", "refid" and "path" * are interpreted as ant properties. Defaults - * to true.
  • + * to false. *
  • rootDirectory: Indicate the directory to use * as the root directory for resolving location * properties. Defaults to the directory * of the project using the task.
  • *
  • includeSemanticAttribute: Indicate whether to include - * the semanticAttribute ("location" or "value") as + * the semantic attribute ("location" or "value") as * part of the property name. Defaults to false.
  • * * @@ -275,6 +276,10 @@ Element topElement = factory.newDocumentBuilder().parse(configurationStream).getDocumentElement(); + // Keep a hashtable of attributes added by this task. + // This task is allow to override its own properties + // but not other properties. So we need to keep track + // of which properties we've added. addedAttributes = new Hashtable(); if (keepRoot) { @@ -473,6 +478,12 @@ if (addedAttributes.containsKey(name)) { // If this attribute was added by this task, then // we append this value to the existing value. + // We use the setProperty method which will + // forcibly override the property if it already exists. + // We need to put these properties into the project + // when we read them, though (instead of keeping them + // outside of the project and batch adding them at the end) + // to allow other properties to reference them. value = (String)addedAttributes.get(name) + "," + value; getProject().setProperty(name, value); } else { 1.3 +5 -0 jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/XmlPropertyTest.java Index: XmlPropertyTest.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/XmlPropertyTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- XmlPropertyTest.java 5 Nov 2002 14:51:52 -0000 1.2 +++ XmlPropertyTest.java 6 Nov 2002 08:43:46 -0000 1.3 @@ -180,13 +180,18 @@ xmlproperty.setIncludeSemanticAttribute(include); xmlproperty.setRootDirectory(workingDir); + // Set a property on the project to make sure that loading + // a property with the same name from an xml file will + // *not* change it. project.setNewProperty("override.property.test", "foo"); + xmlproperty.execute(); Properties props = new Properties(); props.load(new FileInputStream(propertyFile)); //printProperties(project.getProperties()); + ensureProperties(msg, inputFile, workingDir, project, props); ensureReferences(msg, inputFile, project.getReferences()); -- To unsubscribe, e-mail: For additional commands, e-mail: