ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dale Anson <dan...@grafidog.com>
Subject Re: svn commit: r344333 - in /ant/core/trunk: docs/manual/CoreTasks/xmlproperty.html src/etc/testcases/taskdefs/xmlproperty.xml src/main/org/apache/tools/ant/taskdefs/XmlProperty.java src/testcases/org/apache/tools/ant/taskdefs/XmlPropertyTest.java
Date Wed, 16 Nov 2005 15:57:01 GMT
Thanks!  How close is 1.7 to release?

bodewig@apache.org wrote:

>Author: bodewig
>Date: Tue Nov 15 00:30:40 2005
>New Revision: 344333
>
>URL: http://svn.apache.org/viewcvs?rev=344333&view=rev
>Log:
>add resource support to xmlproperty
>
>Modified:
>    ant/core/trunk/docs/manual/CoreTasks/xmlproperty.html
>    ant/core/trunk/src/etc/testcases/taskdefs/xmlproperty.xml
>    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/XmlProperty.java
>    ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/XmlPropertyTest.java
>
>Modified: ant/core/trunk/docs/manual/CoreTasks/xmlproperty.html
>URL: http://svn.apache.org/viewcvs/ant/core/trunk/docs/manual/CoreTasks/xmlproperty.html?rev=344333&r1=344332&r2=344333&view=diff
>==============================================================================
>--- ant/core/trunk/docs/manual/CoreTasks/xmlproperty.html (original)
>+++ ant/core/trunk/docs/manual/CoreTasks/xmlproperty.html Tue Nov 15 00:30:40 2005
>@@ -85,7 +85,7 @@
>   <tr>
>     <td valign="top">file</td>
>     <td valign="top">The XML file to parse.</td>
>-    <td valign="top" align="center">Yes</td>
>+    <td valign="top" align="center">Yes, or a nested resource collection.</td>
>   </tr>
>   <tr>
>     <td valign="top">prefix</td>
>@@ -136,6 +136,11 @@
> <h4>xmlcatalog</h4>
> <p>The <a href="../CoreTypes/xmlcatalog.html"><tt>&lt;xmlcatalog&gt;</tt></a>
> element is used to perform entity resolution.</p>
>+
>+<h4>any <a href="../CoreTypes/resources.html">resource</a> or single
element
>+resource collection</h4>
>+
>+<p>The specified resource will be used as input.</p>
> 
> <a name="examples">
> <h3>Examples</h3>
>
>Modified: ant/core/trunk/src/etc/testcases/taskdefs/xmlproperty.xml
>URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/etc/testcases/taskdefs/xmlproperty.xml?rev=344333&r1=344332&r2=344333&view=diff
>==============================================================================
>--- ant/core/trunk/src/etc/testcases/taskdefs/xmlproperty.xml (original)
>+++ ant/core/trunk/src/etc/testcases/taskdefs/xmlproperty.xml Tue Nov 15 00:30:40 2005
>@@ -8,6 +8,13 @@
>     <xmlproperty file="xmlproperty_withdtd.xml"/>
>   </target>
> 
>+  <target name="testResource">
>+    <loadfile srcfile="xmlproperty_data.xml" property="prop"/>
>+    <xmlproperty>
>+      <string value="${prop}"/>
>+    </xmlproperty>
>+  </target>
>+
>   <target name="testneedscat">
>     <xmlproperty file="xmlproperty_needscat.xml">
>       <xmlcatalog>
>
>Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/XmlProperty.java
>URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/XmlProperty.java?rev=344333&r1=344332&r2=344333&view=diff
>==============================================================================
>--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/XmlProperty.java (original)
>+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/XmlProperty.java Tue Nov 15
00:30:40 2005
>@@ -26,7 +26,10 @@
> import org.apache.tools.ant.BuildException;
> import org.apache.tools.ant.Project;
> import org.apache.tools.ant.types.Path;
>+import org.apache.tools.ant.types.Resource;
>+import org.apache.tools.ant.types.ResourceCollection;
> import org.apache.tools.ant.types.XMLCatalog;
>+import org.apache.tools.ant.types.resources.FileResource;
> import org.apache.tools.ant.util.FileUtils;
> import org.w3c.dom.Document;
> import org.w3c.dom.Element;
>@@ -171,7 +174,7 @@
> 
> public class XmlProperty extends org.apache.tools.ant.Task {
> 
>-    private File src;
>+    private Resource src;
>     private String prefix = "";
>     private boolean keepRoot = true;
>     private boolean validate = false;
>@@ -226,22 +229,29 @@
>     public void execute()
>             throws BuildException {
> 
>-        if (getFile() == null) {
>-            String msg = "XmlProperty task requires a file attribute";
>+        Resource r = getResource();
>+
>+        if (r == null) {
>+            String msg = "XmlProperty task requires a source resource";
>             throw new BuildException(msg);
>         }
> 
>         try {
>-            log("Loading " + src.getAbsolutePath(), Project.MSG_VERBOSE);
>+            log("Loading " + src, Project.MSG_VERBOSE);
> 
>-            if (src.exists()) {
>+            if (r.isExists()) {
> 
>               DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
>               factory.setValidating(validate);
>               factory.setNamespaceAware(false);
>               DocumentBuilder builder = factory.newDocumentBuilder();
>               builder.setEntityResolver(getEntityResolver());
>-              Document document = builder.parse(src);
>+              Document document = null;
>+              if (src instanceof FileResource) {
>+                  document = builder.parse(((FileResource) src).getFile());
>+              } else {
>+                  document = builder.parse(src.getInputStream());
>+              }
>               Element topElement = document.getDocumentElement();
> 
>               // Keep a hashtable of attributes added by this task.
>@@ -261,7 +271,7 @@
>               }
> 
>             } else {
>-                log("Unable to find property file: " + src.getAbsolutePath(),
>+                log("Unable to find property resource: " + r,
>                     Project.MSG_VERBOSE);
>             }
> 
>@@ -547,10 +557,37 @@
>      * @param src the file to parse
>      */
>     public void setFile(File src) {
>+        setSrcResource(new FileResource(src));
>+    }
>+
>+    /**
>+     * The resource to pack; required.
>+     * @param src resource to expand
>+     */
>+    public void setSrcResource(Resource src) {
>+        if (src.isDirectory()) {
>+            throw new BuildException("the source can't be a directory");
>+        }
>+        if (src instanceof FileResource && !supportsNonFileResources()) {
>+            throw new BuildException("Only FileSystem resources are"
>+                                     + " supported.");
>+        }
>         this.src = src;
>     }
> 
>     /**
>+     * Set the source resource.
>+     * @param a the resource to pack as a single element Resource collection.
>+     */
>+    public void addConfigured(ResourceCollection a) {
>+        if (a.size() != 1) {
>+            throw new BuildException("only single argument resource collections"
>+                                     + " are supported as archives");
>+        }
>+        setSrcResource((Resource) a.iterator().next());
>+    }
>+
>+    /**
>      * the prefix to prepend to each property
>      * @param prefix the prefix to prepend to each property
>      */
>@@ -626,7 +663,25 @@
>      * @return the file attribute.
>      */
>     protected File getFile () {
>-        return this.src;
>+        if (src instanceof FileResource) {
>+            return ((FileResource) src).getFile();
>+        } else {
>+            return null;
>+        }
>+    }
>+
>+    /**
>+     * @return the resource.
>+     */
>+    protected Resource getResource() {
>+        // delegate this way around to support subclasses that
>+        // overwrite getFile
>+        File f = getFile();
>+        if (f != null) {
>+            return new FileResource(f);
>+        } else {
>+            return src;
>+        }
>     }
> 
>     /**
>@@ -689,4 +744,18 @@
>         return FILE_UTILS.resolveFile(rootDirectory, fileName);
>     }
> 
>+    /**
>+     * Whether this task can deal with non-file resources.
>+     *
>+     * <p>This implementation returns true only if this task is
>+     * &lt;gzip&gt;.  Any subclass of this class that also wants to
>+     * support non-file resources needs to override this method.  We
>+     * need to do so for backwards compatibility reasons since we
>+     * can't expect subclasses to support resources.</p>
>+     *
>+     * @since Ant 1.7
>+     */
>+    protected boolean supportsNonFileResources() {
>+        return getClass().equals(XmlProperty.class);
>+    }
> }
>
>Modified: ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/XmlPropertyTest.java
>URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/XmlPropertyTest.java?rev=344333&r1=344332&r2=344333&view=diff
>==============================================================================
>--- ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/XmlPropertyTest.java (original)
>+++ ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/XmlPropertyTest.java Tue
Nov 15 00:30:40 2005
>@@ -44,8 +44,16 @@
>         configureProject("src/etc/testcases/taskdefs/xmlproperty.xml");
>     }
> 
>-    public void testProperties() {
>-        executeTarget("test");
>+    public void testFile() {
>+        testProperties("test");
>+    }
>+
>+    public void testResource() {
>+        testProperties("testResource");
>+    }
>+
>+    private void testProperties(String target) {
>+        executeTarget(target);
>         assertEquals("true", getProject().getProperty("root-tag(myattr)"));
>         assertEquals("Text", getProject().getProperty("root-tag.inner-tag"));
>         assertEquals("val",
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
>For additional commands, e-mail: dev-help@ant.apache.org
>
>  
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message