ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject [6/7] ant git commit: use the undocumented TraX factory feature for extensions
Date Sun, 04 Sep 2016 14:25:03 GMT
use the undocumented TraX factory feature for extensions

https://bz.apache.org/bugzilla/show_bug.cgi?id=60060

won't work until https://bugs.openjdk.java.net/browse/JDK-8165116 has
been fixed.


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

Branch: refs/heads/1.9.x
Commit: 7e55fea85d915ba19a4c8526d46dcf05fd415cf3
Parents: cac55fb
Author: Stefan Bodewig <bodewig@apache.org>
Authored: Sun Sep 4 15:54:33 2016 +0200
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Sun Sep 4 15:54:33 2016 +0200

----------------------------------------------------------------------
 .../optional/junit/AggregateTransformer.java    | 36 +++++++++++++++++++-
 .../ant/taskdefs/optional/TraXLiaisonTest.java  |  2 ++
 2 files changed, 37 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/7e55fea8/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 ec3506d..51be1b2 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
@@ -29,6 +29,8 @@ import java.util.Vector;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerFactoryConfigurationError;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
@@ -43,6 +45,7 @@ import org.apache.tools.ant.types.resources.FileResource;
 import org.apache.tools.ant.types.resources.URLResource;
 import org.apache.tools.ant.util.FileUtils;
 import org.apache.tools.ant.util.JAXPUtils;
+import org.apache.tools.ant.util.JavaEnvUtils;
 import org.w3c.dom.Document;
 
 /**
@@ -98,6 +101,11 @@ public class AggregateTransformer {
     private XSLTProcess xsltTask;
 
     /**
+     * The JAXP factory used for the internal XSLT task.
+     */
+    private XSLTProcess.Factory xsltFactory;
+
+    /**
      * Instance of a utility class to use for file operations.
      *
      * @since Ant 1.7
@@ -231,7 +239,8 @@ public class AggregateTransformer {
      * @since Ant 1.9.5
      */
     public XSLTProcess.Factory createFactory() {
-        return xsltTask.createFactory();
+        return xsltFactory != null ? xsltFactory
+            : (xsltFactory = xsltTask.createFactory());
     }
 
     /**
@@ -266,6 +275,7 @@ public class AggregateTransformer {
         paramx.setProject(task.getProject());
         paramx.setName("output.dir");
         paramx.setExpression(toDir.getAbsolutePath());
+        configureForRedirectExtension();
         final long t0 = System.currentTimeMillis();
         try {
             xsltTask.execute();
@@ -343,4 +353,28 @@ public class AggregateTransformer {
         return JAXPUtils.getSystemId(file);
     }
 
+    private static final String JDK_INTERNAL_FACTORY = "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl";
+
+    /**
+     * If we end up using the JDK's own TraX factory on Java 9+, then
+     * set the features and attributes necessary to allow redirect
+     * extensions to be used.
+     * @since Ant 1.9.8
+     */
+    protected void configureForRedirectExtension() {
+        XSLTProcess.Factory factory = createFactory();
+        String factoryName = factory.getName();
+        if (factoryName == null) {
+            try {
+                factoryName = TransformerFactory.newInstance().getClass().getName();
+            } catch (TransformerFactoryConfigurationError exc) {
+                throw new BuildException(exc);
+            }
+        }
+        if (JDK_INTERNAL_FACTORY.equals(factoryName)
+            && JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_9)) {
+            factory.addFeature(new XSLTProcess.Factory.Feature("http://www.oracle.com/xml/jaxp/properties/enableExtensionFunctions",
+                                                               true));
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/ant/blob/7e55fea8/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java
index d4ff72a..f36a4db 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java
@@ -67,6 +67,8 @@ public class TraXLiaisonTest extends AbstractXSLTLiaisonTest
         }
         File xsl = getFile("/taskdefs/optional/xalan-redirect-in.xsl");
         liaison.setStylesheet(xsl);
+        ((TraXLiaison) liaison)
+            .setFeature("http://www.oracle.com/xml/jaxp/properties/enableExtensionFunctions",
true);
         File out = new File("xalan2-redirect-out-dummy.tmp");
         File in = getFile("/taskdefs/optional/xsltliaison-in.xsl");
         ClassLoader orig = Thread.currentThread().getContextClassLoader();


Mime
View raw message