ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r292249 - in /ant/core/trunk: docs/manual/CoreTasks/style.html src/etc/testcases/taskdefs/style/build.xml src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java src/testcases/org/apache/tools/ant/taskdefs/StyleTest.java
Date Wed, 28 Sep 2005 18:46:49 GMT
Author: bodewig
Date: Wed Sep 28 11:46:40 2005
New Revision: 292249

URL: http://svn.apache.org/viewcvs?rev=292249&view=rev
Log:
resource collection support for xslt

Modified:
    ant/core/trunk/docs/manual/CoreTasks/style.html
    ant/core/trunk/src/etc/testcases/taskdefs/style/build.xml
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
    ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/StyleTest.java

Modified: ant/core/trunk/docs/manual/CoreTasks/style.html
URL: http://svn.apache.org/viewcvs/ant/core/trunk/docs/manual/CoreTasks/style.html?rev=292249&r1=292248&r2=292249&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/style.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/style.html Wed Sep 28 11:46:40 2005
@@ -42,6 +42,11 @@
 been matched.  If this behavior is not what you want, set the
 scanincludedirectories attribute to false.</p>
 
+<p>Starting with Ant 1.7 this task supports nested <a
+href="../CoreTypes/resources.html#collection">resource collection</a>s
+in addition to (or instead of, depending on the useImplicitFileset
+attribute) the implicit fileset formed by this task.</p>
+
 <p>This task supports the use of a nested <code>&lt;param&gt;</code>
element which is used to pass values
   to an <code>&lt;xsl:param&gt;</code> declaration.</p>
 <p>This task supports the use of a nested <a href="../CoreTypes/xmlcatalog.html">xmlcatalog</a>
@@ -176,8 +181,27 @@
     Default is <code>false</code>.  <em>Since Ant 1.5.2</em>.</td>
     <td valign="top" align="center">No</td>
   </tr>
+  <tr>
+    <td valign="top">useImplicitFileset</td>
+    <td valign="top">Whether the implicit fileset formed by this task
+    shall be used.  If you set this to false you must use nested
+    resource collections - or the in attribute, in which case this
+    attribute has no impact anyway.  Default is <code>true</code>.
+    <em>Since Ant 1.7</em>.</td>
+    <td valign="top" align="center">No</td>
+  </tr>
 </table>
 <h3>Parameters specified as nested elements</h3>
+
+<h4>any <a href="../CoreTypes/resources.html#collection">resource
+collection</a></h4>
+
+<p><em>since Ant 1.7</em></p>
+
+<p>Use resource collections to specify resources that the stylesheet
+should be applied to.  Use a nested mapper and the task's destdir
+attribute to specify the output files.</p>
+
 <h4>classpath</h4>
 <p>The classpath to load the processor from can be specified via a
 nested <code>&lt;classpath&gt;</code>, as well - that is, a

Modified: ant/core/trunk/src/etc/testcases/taskdefs/style/build.xml
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/etc/testcases/taskdefs/style/build.xml?rev=292249&r1=292248&r2=292249&view=diff
==============================================================================
--- ant/core/trunk/src/etc/testcases/taskdefs/style/build.xml (original)
+++ ant/core/trunk/src/etc/testcases/taskdefs/style/build.xml Wed Sep 28 11:46:40 2005
@@ -57,6 +57,15 @@
     </xslt>
   </target>
 
+  <target name="testExplicitFileset">
+    <property name="value" value="myvalue"/>
+    <xslt style="printParams.xsl" destDir="${out.dir}"
+          useImplicitFileset="false" basedir="..">
+      <param name="set" expression="${value}"/>
+      <fileset dir="."/>
+    </xslt>
+  </target>
+
   <target name="testNewerStylesheet">
       <antcall target="copyXsl">
         <param name="xsl.value" value="old-value"/>

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java?rev=292249&r1=292248&r2=292249&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java Wed Sep 28 11:46:40
2005
@@ -19,6 +19,7 @@
 
 import java.io.File;
 import java.util.Enumeration;
+import java.util.Iterator;
 import java.util.Vector;
 import org.apache.tools.ant.AntClassLoader;
 import org.apache.tools.ant.BuildException;
@@ -28,7 +29,11 @@
 import org.apache.tools.ant.types.Mapper;
 import org.apache.tools.ant.types.Path;
 import org.apache.tools.ant.types.Reference;
+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.types.resources.Union;
 import org.apache.tools.ant.util.FileNameMapper;
 import org.apache.tools.ant.util.FileUtils;
 
@@ -141,6 +146,20 @@
     private Mapper mapperElement = null;
 
     /**
+     * Additional resource collections to process.
+     *
+     * @since Ant 1.7
+     */
+    private Union resources = new Union();
+
+    /**
+     * Whether to use the implicit fileset.
+     *
+     * @since Ant 1.7
+     */
+    private boolean useImplicitFileset = true;
+
+    /**
      * Creates a new XSLTProcess Task.
      */
     public XSLTProcess() {
@@ -184,6 +203,17 @@
     }
 
     /**
+     * Adds a collection of resources to style in addition to the
+     * given file or the implicit fileset.
+     *
+     * @param rc the collection of resources to style
+     * @since Ant 1.7
+     */
+    public void add(ResourceCollection rc) {
+	resources.add(rc);
+    }
+
+    /**
      * Executes the task.
      *
      * @exception BuildException if there is an execution problem.
@@ -248,11 +278,10 @@
              * in batch processing mode.
              */
 
-            //-- make sure Source directory exists...
-            if (destDir == null) {
-                String msg = "destdir attributes must be set!";
-                throw new BuildException(msg);
-            }
+            //-- make sure destination directory exists...
+	    checkDest();
+
+	    if (useImplicitFileset) {
             scanner = getDirectoryScanner(baseDir);
             log("Transforming into " + destDir, Project.MSG_INFO);
 
@@ -272,6 +301,12 @@
                     }
                 }
             }
+	    } else { // only resource collections, there better be some
+		if (resources.size() == 0) {
+		    throw new BuildException("no resources specified");
+		}
+	    }
+	    processResources(stylesheet);
         } finally {
             if (loader != null) {
                 loader.resetThreadContextLoader();
@@ -283,7 +318,7 @@
             baseDir = savedBaseDir;
         }
     }
-
+    
     /**
      * Set whether to check dependencies, or always generate;
      * optional, default is false.
@@ -377,6 +412,18 @@
     }
 
     /**
+     * Whether to use the implicit fileset.
+     *
+     * <p>Set this to false if you want explicit control with nested
+     * resource collections.</p>
+     *
+     * @since Ant 1.7
+     */
+    public void setUseImplicitFileset(boolean b) {
+	useImplicitFileset = b;
+    }
+
+    /**
      * Add the catalog to our internal catalog
      *
      * @param xmlCatalog the XMLCatalog instance to use to look up DTDs
@@ -449,6 +496,43 @@
      */
     public void setIn(File inFile) {
         this.inFile = inFile;
+    }
+
+    /**
+     * Throws a BuildException if the destination directory hasn't
+     * been specified.
+     * @since Ant 1.7
+     */
+    private void checkDest() {
+	if (destDir == null) {
+	    String msg = "destdir attributes must be set!";
+	    throw new BuildException(msg);
+	}
+    }
+
+    /**
+     * Styles all existing resources.
+     *
+     * @since Ant 1.7
+     */
+    private void processResources(File stylesheet) {
+	Iterator iter = resources.iterator();
+	while (iter.hasNext()) {
+	    Resource r = (Resource) iter.next();
+	    if (!r.isExists()) {
+		continue;
+	    }
+	    File base = baseDir;
+	    String name = r.getName();
+	    if (r instanceof FileResource) {
+		FileResource f = (FileResource) r;
+		base = f.getBaseDir();
+		if (base == null) {
+		    name = f.getFile().getAbsolutePath();
+		}
+	    }
+	    process(base, name, destDir, stylesheet);
+	}
     }
 
     /**

Modified: ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/StyleTest.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/StyleTest.java?rev=292249&r1=292248&r2=292249&view=diff
==============================================================================
--- ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/StyleTest.java (original)
+++ ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/StyleTest.java Wed Sep 28 11:46:40
2005
@@ -84,8 +84,16 @@
 
 
     public void testDefaultMapper() throws Exception {
+	testDefaultMapper("testDefaultMapper");
+    }
+
+    public void testExplicitFileset() throws Exception {
+	testDefaultMapper("testExplicitFileset");
+    }
+
+    public void testDefaultMapper(String target) throws Exception {
         assertTrue(!getProject().resolveFile("out/data.html").exists());
-        expectFileContains("testDefaultMapper",
+        expectFileContains(target,
                            "out/data.html",
                            "set='myvalue'");
     }



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


Mime
View raw message