Browse Source

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.
master
Stefan Bodewig 9 years ago
parent
commit
7e55fea85d
2 changed files with 37 additions and 1 deletions
  1. +35
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java
  2. +2
    -0
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java

+ 35
- 1
src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java View File

@@ -29,6 +29,8 @@ import java.util.Vector;


import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; 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.BuildException;
import org.apache.tools.ant.Project; 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.types.resources.URLResource;
import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.JAXPUtils; import org.apache.tools.ant.util.JAXPUtils;
import org.apache.tools.ant.util.JavaEnvUtils;
import org.w3c.dom.Document; import org.w3c.dom.Document;


/** /**
@@ -97,6 +100,11 @@ public class AggregateTransformer {
*/ */
private XSLTProcess xsltTask; 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. * Instance of a utility class to use for file operations.
* *
@@ -231,7 +239,8 @@ public class AggregateTransformer {
* @since Ant 1.9.5 * @since Ant 1.9.5
*/ */
public XSLTProcess.Factory createFactory() { 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.setProject(task.getProject());
paramx.setName("output.dir"); paramx.setName("output.dir");
paramx.setExpression(toDir.getAbsolutePath()); paramx.setExpression(toDir.getAbsolutePath());
configureForRedirectExtension();
final long t0 = System.currentTimeMillis(); final long t0 = System.currentTimeMillis();
try { try {
xsltTask.execute(); xsltTask.execute();
@@ -343,4 +353,28 @@ public class AggregateTransformer {
return JAXPUtils.getSystemId(file); 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));
}
}
} }

+ 2
- 0
src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java View File

@@ -67,6 +67,8 @@ public class TraXLiaisonTest extends AbstractXSLTLiaisonTest
} }
File xsl = getFile("/taskdefs/optional/xalan-redirect-in.xsl"); File xsl = getFile("/taskdefs/optional/xalan-redirect-in.xsl");
liaison.setStylesheet(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 out = new File("xalan2-redirect-out-dummy.tmp");
File in = getFile("/taskdefs/optional/xsltliaison-in.xsl"); File in = getFile("/taskdefs/optional/xsltliaison-in.xsl");
ClassLoader orig = Thread.currentThread().getContextClassLoader(); ClassLoader orig = Thread.currentThread().getContextClassLoader();


Loading…
Cancel
Save