ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject [1/3] ant git commit: junitreport: Expose classpath and factory of internal XSLTProcess task.
Date Wed, 26 Nov 2014 19:54:34 GMT
Repository: ant
Updated Branches:
  refs/heads/master fae798e81 -> c8edc8e0f


junitreport: Expose classpath and factory of internal XSLTProcess task.

This patch creates the nested XSLTProcess at creation of the
AggregateTransformer, not upon execution of the transformation.  This way it
is much easier to simply wrap parts of the interface I'd like to expose,
like the new <classpath> and <factory> nested elements, but also the
existing <param> elements.

I haven't called XSLTProcess.init(), as the previous code didn't do that
either.  I don't fully understand the difference between init() and a
constructor, but it might be a good thing to init the task somewhere.

The approach I chose is something like a whitelist delegation: the
XSLTProcess is a private member, and only selected methods of its interface
are wrapped and thus exposed to be configured.  As an alternative, one could
do something like a blacklist delegation by deriving a class from
XSLTProcess and forbidding access to certain settings by ovverriding the
corresponding methods and throwing exceptions therein.  In that case, one
might even turn the class derived from XSLTProcess into a nested <xslt>
element, which would be probably much clearer, as it would be configured in
the same way that a top-level <xslt> task is.  I didn't choose this approach
in my patch for now.


Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/95ea95ce
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/95ea95ce
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/95ea95ce

Branch: refs/heads/master
Commit: 95ea95ce56b27a68660a04bcfa8abde2add0dcf3
Parents: fae798e
Author: Martin von Gagern <Martin.vGagern@gmx.net>
Authored: Wed Nov 26 13:50:50 2014 +0100
Committer: Martin von Gagern <Martin.vGagern@gmx.net>
Committed: Wed Nov 26 13:50:50 2014 +0100

----------------------------------------------------------------------
 manual/Tasks/junitreport.html                   |  9 ++++
 manual/Tasks/style.html                         |  4 +-
 .../optional/junit/AggregateTransformer.java    | 44 ++++++++++++--------
 3 files changed, 38 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/95ea95ce/manual/Tasks/junitreport.html
----------------------------------------------------------------------
diff --git a/manual/Tasks/junitreport.html b/manual/Tasks/junitreport.html
index cdf171e..365afe6 100644
--- a/manual/Tasks/junitreport.html
+++ b/manual/Tasks/junitreport.html
@@ -167,6 +167,15 @@ These tags can pass XSL parameters to the stylesheet.
   </tr>
 </table>
 
+<h4>classpath</h4>
+<p><em>Since Ant 1.10.</em>
+Like for the <a href="../CoreTasks/style.html#classpath">XSLT task</a>,
+a nested &lt;classpath&gt; will be used to load the processor.</p>
+
+<h4>factory</h4>
+<p><em>Since Ant 1.10.</em>
+Like for the <a href="../CoreTasks/style.html#factory">XSLT task</a>,
+a nested &lt;factory&gt; can be used to specify factory settings.</p>
 
 
 <h3>Example of report</h3>

http://git-wip-us.apache.org/repos/asf/ant/blob/95ea95ce/manual/Tasks/style.html
----------------------------------------------------------------------
diff --git a/manual/Tasks/style.html b/manual/Tasks/style.html
index 6e2a2a5..f02b98e 100644
--- a/manual/Tasks/style.html
+++ b/manual/Tasks/style.html
@@ -269,7 +269,7 @@ collection</a></h4>
 should be applied to.  Use a nested mapper and the task's destdir
 attribute to specify the output files.</p>
 
-<h4>classpath</h4>
+<h4><a name="classpath">classpath</a></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
 <a href="../using.html#path">path</a>-like structure.</p>
@@ -372,7 +372,7 @@ XSLT specifications</a>.
 </table>
 </blockquote>
 
-<h4>factory ('trax' processors only)</h4>
+<h4><a name="factory">factory ('trax' processors only)</a></h4>
 Used to specify factory settings.
 <blockquote>
 <h4>Parameters</h4>

http://git-wip-us.apache.org/repos/asf/ant/blob/95ea95ce/src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java
b/src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java
index 46c4406..c22bbc8 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java
@@ -37,6 +37,7 @@ import org.apache.tools.ant.taskdefs.Delete;
 import org.apache.tools.ant.taskdefs.TempFile;
 import org.apache.tools.ant.taskdefs.XSLTProcess;
 import org.apache.tools.ant.types.EnumeratedAttribute;
+import org.apache.tools.ant.types.Path;
 import org.apache.tools.ant.types.Resource;
 import org.apache.tools.ant.types.resources.FileResource;
 import org.apache.tools.ant.types.resources.URLResource;
@@ -90,11 +91,11 @@ public class AggregateTransformer {
     protected File toDir;
 
     /**
-     * The params that will be sent to the XSL transformation
+     * The internal XSLT task used to perform the transformation.
      *
-     * @since Ant 1.7
+     * @since Ant 1.10
      */
-    private List params;
+    private XSLTProcess xsltTask;
 
     /**
      * Instance of a utility class to use for file operations.
@@ -129,7 +130,8 @@ public class AggregateTransformer {
      */
     public AggregateTransformer(Task task) {
         this.task = task;
-        params = new Vector();
+        xsltTask = new XSLTProcess();
+        xsltTask.bindToOwner(task);
     }
 
     /**
@@ -209,9 +211,27 @@ public class AggregateTransformer {
      * @since Ant 1.7
      */
     public XSLTProcess.Param createParam() {
-        XSLTProcess.Param p = new XSLTProcess.Param();
-        params.add(p);
-        return p;
+        return xsltTask.createParam();
+    }
+
+    /**
+     * Creates a classpath to be used for the internal XSLT task.
+     *
+     * @return the classpath to be configured
+     * @since Ant 1.10
+     */
+    public Path createClasspath() {
+        return xsltTask.createClasspath();
+    }
+
+    /**
+     * Creates a factory configuration to be used for the internal XSLT task.
+     *
+     * @return the factory description to be configured
+     * @since Ant 1.10
+     */
+    public XSLTProcess.Factory createFactory() {
+        return xsltTask.createFactory();
     }
 
     /**
@@ -225,9 +245,6 @@ public class AggregateTransformer {
         TempFile tempFileTask = new TempFile();
         tempFileTask.bindToOwner(task);
 
-        XSLTProcess xsltTask = new XSLTProcess();
-        xsltTask.bindToOwner(task);
-
         xsltTask.setXslResource(getStylesheet());
 
         // acrobatic cast.
@@ -245,13 +262,6 @@ public class AggregateTransformer {
             outputFile = new File(toDir, "junit-noframes.html");
         }
         xsltTask.setOut(outputFile);
-        for (Iterator i = params.iterator(); i.hasNext();) {
-            XSLTProcess.Param param = (XSLTProcess.Param) i.next();
-            XSLTProcess.Param newParam = xsltTask.createParam();
-            newParam.setProject(task.getProject());
-            newParam.setName(param.getName());
-            newParam.setExpression(param.getExpression());
-        }
         XSLTProcess.Param paramx = xsltTask.createParam();
         paramx.setProject(task.getProject());
         paramx.setName("output.dir");


Mime
View raw message