ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs XmlPropertyTest.java
Date Wed, 06 Nov 2002 08:43:46 GMT
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 <xmlproperty>.
  
  Submitted by:	Paul Christmann <paul at priorartisans.com>
  
  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 @@
   
   <body>
   
  -
   <h2><a name="xmlproperty">XmlProperty</a></h2>
   <h3>Description</h3>
   <p>
  -Loads property values from a valid xml file.
  +Loads property values from a valid xml file.  This XML property file:
  +<pre>
  +  &lt;root&gt;
  +    &lt;properties&gt;
  +      &lt;foo&gt;bar&lt;/foo&gt;
  +    &lt;/properties&gt;
  +  &lt;/root&gt;
  +</pre>
  +is roughly equivalent to this java property file:
  +<pre>
  +  root.properties.foo = bar
  +</pre>
  +
  +<p>
  +By default, this load
  +does <em>no</em> processing of the input.  In particular, unlike the
  +<a href="property.html">Property task</a>, property references
  +(i.e., ${foo}) are not resolved.
  +<p>
  +<a name="semanticAttributes">
  +<h3>Semantic Attributes</h3>
  +</a>
  +Input processing can be enabled by using the <b>semanticAttributes</b>
  +attribute.  If this attribute is set to <i>true</i> (its default is
  +<i>false</i>), the following processing occurs as the input XML file
  +is loaded:
  +<ul>
  +  <li>Property references are resolved.</li>
  +  <li>The following attriubtes are treated differently:
  +    <ul>
  +      <li><b>id</b>: The property is associated with the given id value.</li>
  +      <li><b>location</b>: The property is treated as a file location</li>
  +      <li><b>refid</b>: The property is set to the value of the
  +          referenced property.</li>
  +      <li><b>value</b>: The property is set to the value indicated.</li>
  +    </ul>
  +  </li>
  +  <li><a href="../using.html#path">Path-like Structures</a> can be defined
  +      by use of the following attributes:
  +    <ul>
  +      <li><b>pathid</b>: 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.</li>
  +    </ul>
  +  </li>
  +</ul>
  +<p>
  +For example, with semantic attribute processing enabled, this XML property
  +file:
  +<pre>
  +  &lt;root&gt;
  +    &lt;properties&gt;
  +      &lt;foo location="bar"/&gt;
  +      &lt;quux&gt;${root.properties.foo}&lt;/quux&gt;
  +    &lt;/properties&gt;
  +  &lt;/root&gt;
  +</pre>
  +is roughly equivalent to the following fragments in a build.xml file:
  +<pre>
  +  &lt;property name="root.properties.foo" location="bar"/&gt;
  +  &lt;property name="root.properties.quux" value="${root.properties.foo}"/&gt;
  +</pre>
  +
   </p>
   
   <h3>Parameters</h3>
  @@ -31,29 +92,51 @@
     </tr>
     <tr>
       <td valign="top">keepRoot</td>
  -    <td valign="top">If false, it doesn't include the xml root tag as a first
  -                     value in the property name.</td>
  +    <td valign="top">Keep the xml root tag as the
  +                     first value in the property name.</td>
       <td valign="top" align="center">No, default is <i>true</i>.</td>
     </tr>  
     <tr>
       <td valign="top">validate</td>
  -    <td valign="top">If true, it enables validation.</td>
  +    <td valign="top">Validate the input file.</td>
       <td valign="top" align="center">No, default is <i>false</i>.</td>
     </tr>
     <tr>
       <td valign="top">collapseAttributes</td>
  -    <td valign="top">If true, it treats attributes as nested elements.</td>
  +    <td valign="top">Treat attributes as nested elements.</td>
  +    <td valign="top" align="center">No, default is <i>false</i>.</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">semanticAttributes</td>
  +    <td valign="top">Enable special handling of certain attribute names.
  +                     See the <a href="#semanticAttributes">Semantic Attributes</a>
  +                     section for more information.</td>
       <td valign="top" align="center">No, default is <i>false</i>.</td>
     </tr>  
  +  <tr>
  +    <td valign="top">includeSemanticAttribute</td>
  +    <td valign="top">Include the semantic attribute name
  +                     as part of the property name.  Ignored if
  +                     <i>semanticAttributes</i> is not set to <i>true</i>.
  +                     See the <a href="#semanticAttributes">Semantic Attributes</a>
  +                     section for more information.</td>
  +    <td valign="top" align="center">No, default is <i>false</i>.</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">rootDirectory</td>
  +    <td valign="top">The directory to use for resolving file references. Ignored
  +                     if <i>semanticAttributes</i> is not set to <i>true</i>.</td>
  +    <td valign="top" align="center">No, default is <i>${basedir}</i>.</td>
  +  </tr>
   </table>
   
  -
  +<a name="examples">
   <h3>Examples</h3>
  -<pre>   &lt;xmlproperty file="somefile.xml" /&gt;</pre>
  +</a>
  +
  +<h4>Non-semantic Attributes</h4>
   
  -<p>Load contents of somefile.xml as Ant properties,
  -generating the property names from the 
  -file's element and attribute names.</p>
  +<p>Here is an example xml file that does not have any semantic attributes.</p>
   
   <pre> 
      &lt;root-tag myattr="true"&gt;
  @@ -62,28 +145,110 @@
      &lt;/root-tag&gt;
   </pre>
   
  -<p>This is an example xml file.</p>
  -
  -<pre>   root-tag(myattr)=true
  +<h5>default loading</h5>
  +<p>This entry in a build file:
  +<pre>   &lt;xmlproperty file="somefile.xml" /&gt;</pre>
  +is equivalent to the following properties:
  +<pre>
  +   root-tag(myattr)=true
      root-tag.inner-tag=Text
      root-tag.inner-tag(someattr)=val
      root-tag.a2.a3.a4=false
   </pre>
   
  -<p>These are the properties loaded by this task from the previous example file.</p>
  -
  +<h5>collapseAttributes=false</h5>
  +<p>This entry in a build file:
   <pre>   &lt;xmlproperty file="somefile.xml" collapseAttributes="true"/&gt;</pre>
  -
  -<p>Load contents of somefile.xml as Ant properties collapsing attributes as nodes.</p>
  -
  -<pre>   root-tag.myattr=true
  +is equivalent to the following properties:
  +<pre>
  +   root-tag.myattr=true
      root-tag.inner-tag=Text
      root-tag.inner-tag.someatt=val
      root-tag.a2.a3.a4=false
   </pre>
   
  -<p>These are the properties loaded by this task from the previous example file, with
  -   attribute collapsing true.</p>
  +<h5>keepRoot=false</h5>
  +<p>This entry in a build file:
  +<pre>   &lt;xmlproperty file="somefile.xml" keepRoot="false"/&gt;</pre>
  +is equivalent to the following properties:
  +<pre>
  +   inner-tag=Text
  +   inner-tag(someattr)=val
  +   a2.a3.a4=false
  +</pre>
  +
  +<h4>Semantic Attributes</h4>
  +
  +<p>Here is an example xml file that has semantic attributes.</p>
  +<pre>
  +  &lt;root-tag&gt;
  +    &lt;version value="0.0.1"/&gt;
  +    &lt;build folder="build"&gt;
  +      &lt;classes id="build.classes" location="${build.folder}/classes"/&gt;
  +      &lt;reference refid="build.classes"/&gt;
  +    &lt;/build&gt;
  +    &lt;compile&gt;
  +      &lt;classpath pathid="compile.classpath"&gt;
  +        &lt;pathelement location="${build.classes}"/&gt;
  +      &lt;/classpath&gt;
  +    &lt;/compile&gt;
  +    &lt;run-time&gt;
  +      &lt;jars&gt;*.jar&lt;/jars&gt;
  +      &lt;classpath pathid="run-time.classpath"&gt;
  +        &lt;path refid="compile.classpath"/&gt;
  +        &lt;pathelement path="${run-time.jars}"/&gt;
  +      &lt;/classpath&gt;
  +    &lt;/run-time&gt;
  +  &lt;/root-tag&gt;
  +</pre>
  +
  +<h5>default loading (semanticAttributes=true)</h5>
  +<p>This entry in a build file:
  +<pre>   &lt;xmlproperty file="somefile.xml"
  +                semanticAttributes="true"/&gt;</pre>
  +is equivalent to the following entries in a build file:
  +<pre>
  +  &lt;property name="version" value="0.0.1"/&gt;
  +  &lt;property name="build.folder" value="build"/&gt;
  +  &lt;property name="build.classes" location="${build.folder}/classes" id="build.classes"/&gt;
  +  &lt;property name="build.reference" refid="build.classes"/&gt;
  +
  +  &lt;property name="run-time.jars" value="*.jar/&gt;
  +
  +  &lt;classpath id="compile.classpath"&gt;
  +    &lt;pathelement location="${build.classes}"/&gt;
  +  &lt;/classpath&gt;
  +
  +  &lt;classpath id="run-time.classpath"&gt;
  +    &lt;path refid="compile.classpath"/&gt;
  +    &lt;pathelement path="${run-time.jars}"/&gt;
  +  &lt;/classpath&gt;
  +</pre>
  +
  +<h5>includeSemanticAttribute="true"</h5>
  +<p>This entry in a build file:
  +<pre>   &lt;xmlproperty file="somefile.xml"
  +                semanticAttributes="true"
  +                includeSemanticAttribute="true"/&gt;
  +</pre>
  +is equivalent to the following entries in a build file:
  +<pre>
  +  &lt;property name="version.value" value="0.0.1"/&gt;
  +  &lt;property name="build.folder" value="build"/&gt;
  +  &lt;property name="build.classes.location" location="${build.folder}/classes"/&gt;
  +  &lt;property name="build.reference.refid" refid="build.location"/&gt;
  +
  +  &lt;property name="run-time.jars" value="*.jar/&gt;
  +
  +  &lt;classpath id="compile.classpath"&gt;
  +    &lt;pathelement location="${build.classes}"/&gt;
  +  &lt;/classpath&gt;
  +
  +  &lt;classpath id="run-time.classpath"&gt;
  +    &lt;path refid="compile.classpath"/&gt;
  +    &lt;pathelement path="${run-time.jars}"/&gt;
  +  &lt;/classpath&gt;
  +</pre>
   
   <hr/>
   
  
  
  
  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 @@
   <root>
     <override>
  +    <!-- This property should not get set.  The
  +         XmlPropertyTest code explicitly sets
  +         override.property.test to foo to make
  +         sure that attempts to reset it via
  +         property file loads *fail*. -->
       <property test="bar"/>
     </override>
   </root>
  
  
  
  1.1                  jakarta-ant/src/etc/testcases/taskdefs/xmlproperty/inputs/original.xml
  
  Index: original.xml
  ===================================================================
  <root-tag myattr="true">
    <inner-tag someattr="val">Text</inner-tag>
    <a2><a3><a4>false</a4></a3></a2>
  </root-tag>
  
  
  
  
  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 @@
    *
    * <p>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 @@
    *
    * <pre>
    * &lt;root-tag&gt;
  - *   &lt;build location="build"&gt;
  - *     &lt;classes id="build.classes" location="${build.location}/classes"/&gt;
  - *     &lt;reference refid="build.location"/&gt;
  + *   &lt;build&gt;
  + *   &lt;build folder="build"&gt;
  + *     &lt;classes id="build.classes" location="${build.folder}/classes"/&gt;
  + *     &lt;reference refid="build.classes"/&gt;
    *   &lt;/build&gt;
    *   &lt;compile&gt;
    *     &lt;classpath pathid="compile.classpath"&gt;
  @@ -155,9 +156,9 @@
    * <p>is equivalent to the following entries in a build file:</p>
    *
    * <pre>
  - * &lt;property name="build.location" location="build"/&gt;
  - * &lt;property name="build.classes.location" location="${build.location}/classes"/&gt;
  - * &lt;property name="build.reference" refid="build.location"/&gt;
  + * &lt;property name="build" location="build"/&gt;
  + * &lt;property name="build.classes" location="${build.location}/classes"/&gt;
  + * &lt;property name="build.reference" refid="build.classes"/&gt;
    *
    * &lt;property name="run-time.jars" value="*.jar/&gt;
    *
  @@ -193,13 +194,13 @@
    * <li><b>semanticAttributes</b>: Indicate whether attributes
    *     named "location", "value", "refid" and "path"
    *     are interpreted as ant properties.  Defaults
  - *     to true.</li>
  + *     to false.</li>
    * <li><b>rootDirectory</b>: Indicate the directory to use
    *     as the root directory for resolving location
    *     properties.  Defaults to the directory
    *     of the project using the task.</li>
    * <li><b>includeSemanticAttribute</b>: 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.</li>
    * </ul>
    *
  @@ -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:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message