From d891e90f617556a2f4694ce5878912a92a884c19 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Fri, 25 Jun 2004 13:42:10 +0000 Subject: [PATCH] Make work with JDK 1.5. PR: 27541 Most of the work has been done by Stephane, I just provided the finishing touches. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276641 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 14 + build.xml | 1 + docs/faq.html | 4 +- docs/manual/OptionalTasks/junitreport.html | 32 +- src/etc/junit-frames-xalan1.xsl | 716 ++++++++++++++++++ src/etc/junit-frames.xsl | 2 +- .../optional/junit/Xalan1Executor.java | 29 +- .../optional/junit/Xalan2Executor.java | 42 +- .../optional/junit/XalanExecutor.java | 95 ++- xdocs/faq.xml | 5 +- 10 files changed, 881 insertions(+), 59 deletions(-) create mode 100644 src/etc/junit-frames-xalan1.xsl diff --git a/WHATSNEW b/WHATSNEW index 088cec43c..cfe52b786 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -44,6 +44,17 @@ Changes that could break older environments: * Nested elements for namespaced tasks and types may belong to the Ant default namespace as well as the task's or type's namespace. +* will very likely no longer work with Xalan-J 1. + + Note that Xalan-J 1 has been deprecated for a very long time and we + highly recommend that you upgrade. + + If you really need to continue using Xalan-J 1, please copy the + junit-frames-xalan1.xsl from the distributions etc directory as + junit-frames.xsl into a new directory and use the tasks styledir + attribute to point to. This is the last version of the XSLT + stylesheet that is expected to be compatible with Xalan-J 1. + Fixed bugs: ----------- @@ -245,6 +256,9 @@ Other changes: which will allow nonexistent files specified via s to be passed to the executable. Bugzilla Report 29585. +* now also works with Xalan XSLTC and/or JDK 1.5. + Bugzilla Report 27541. + Changes from Ant 1.6.0 to Ant 1.6.1 ============================================= diff --git a/build.xml b/build.xml index 783bcb47b..f9537ef4b 100644 --- a/build.xml +++ b/build.xml @@ -1032,6 +1032,7 @@ + diff --git a/docs/faq.html b/docs/faq.html index e82713c43..e4e4ce268 100644 --- a/docs/faq.html +++ b/docs/faq.html @@ -1693,8 +1693,8 @@ mv /tmp/foo $ANT_HOME/bin/antRun extensions for its internal stylesheet, Ant doesn't support XSLTC yet. This means that you have to install Xalan-J 2 in order to use this task with JDK 1.5.

-

If you want to follow progress on this, here - is the relevant bug report.

+

Starting with Ant 1.6.2 <junitreport> + will support JDK 1.5.

diff --git a/docs/manual/OptionalTasks/junitreport.html b/docs/manual/OptionalTasks/junitreport.html index e2b61c6f0..9270e87a1 100644 --- a/docs/manual/OptionalTasks/junitreport.html +++ b/docs/manual/OptionalTasks/junitreport.html @@ -14,21 +14,25 @@ the Ant distribution. See Library Dependencies for more information.

Requirements

-

The task needs Xalan -2.x; although The task needs Apache Xalan 2.x or Xalan XSLTC +(JDK 1.4 contains a version of Xalan-J 2.x while JDK 1.5 ships with a +version of XSLTC). Versions prior to Ant 1.6.2 worked with Apache Xalan -1.2.2 does work, but as Xalan1 is not supported, we do not -recommend this. While JDK 1.4.x contains a version of Xalan-J 2, JDK -1.5 and later have moved -to XSLTC. Since this task uses Xalan's redirect extensions for -its internal stylesheet, Ant doesn't support XSLTC yet. This means -that you have to install Xalan-J 2 in order to use this task with JDK -1.5.

-

-If you do you use Xalan 1.2.2 you will need a compatible (older) version of Xerces. -as well as BSF(bsf.jar). Again, using Xalan 2 is simpler and supported. -

+1.2.2, but as Xalan1 is no longer supported, we do not recommend +this. With Ant 1.6.2 we had to decide between supporting Xalan-J 1 +and XSLTC, since there was no way to support both at the same +time.

+ +

If you want to use Xalan 1.2.2, the noframes report is still +supposed to work. If you want the frames support, copy the file +junit-frames-xalan1.xsl from the Ant distribution's etc directory to a +new directory, change its name to junit-frames.xsl and use the task's +styledir attribute to point to it. You will also need a compatible +(older) version of Xerces. as well as BSF(bsf.jar). Again, using +Xalan 2 is simpler and supported.

+

Parameters

diff --git a/src/etc/junit-frames-xalan1.xsl b/src/etc/junit-frames-xalan1.xsl new file mode 100644 index 000000000..114e45973 --- /dev/null +++ b/src/etc/junit-frames-xalan1.xsl @@ -0,0 +1,716 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + . + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Unit Test Results. + + + + + + + + + <h2>Frame Alert</h2> + <p> + This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. + </p> + + + + + + + +body { + font:normal 68% verdana,arial,helvetica; + color:#000000; +} +table tr td, table tr th { + font-size: 68%; +} +table.details tr th{ + font-weight: bold; + text-align:left; + background:#a6caf0; +} +table.details tr td{ + background:#eeeee0; +} + +p { + line-height:1.5em; + margin-top:0.5em; margin-bottom:1.0em; +} +h1 { + margin: 0px 0px 5px; font: 165% verdana,arial,helvetica +} +h2 { + margin-top: 1em; margin-bottom: 0.5em; font: bold 125% verdana,arial,helvetica +} +h3 { + margin-bottom: 0.5em; font: bold 115% verdana,arial,helvetica +} +h4 { + margin-bottom: 0.5em; font: bold 100% verdana,arial,helvetica +} +h5 { + margin-bottom: 0.5em; font: bold 100% verdana,arial,helvetica +} +h6 { + margin-bottom: 0.5em; font: bold 100% verdana,arial,helvetica +} +.Error { + font-weight:bold; color:red; +} +.Failure { + font-weight:bold; color:purple; +} +.Properties { + text-align:right; +} + + + + + + + . + + + Unit Test Results: <xsl:value-of select="$class.name"/> + + + + + + + + +

Class

+ + +
+ + +
+ +

Tests

+ + + + + + + + + +
+ + + + + + + + + + + + + + cur = TestCases['.'] = new Array(); + + + cur[''] = ''; + + + + + + + + + + + Unit Test Classes: <xsl:value-of select="$name"/> + + + + + + + + + +
+

+ + <none> +

+
+ +

Classes

+ + + + + + + +
+ +
+ + +
+ + + + + + + All Unit Test Classes + + + + + +

Classes

+ + + + +
+ + +
+ + + + + + + + + / + .html + + + + + + + + + + + + + All Unit Test Packages + + + + + +

Home

+

Packages

+ + + + +
+ + +
+ + + + + + + <none> + + + + + + + + + + Unit Test Results: Summary + + + + + + open('allclasses-frame.html','classListFrame') + +

Summary

+ + + + + + + + + + + + + + + + + Error + Failure + Pass + + + + + + + + +
TestsFailuresErrorsSuccess rateTime
+ + + + + + + +
+ + + + +
+ Note: failures are anticipated and checked for with assertions while errors are unanticipated. +
+ +

Packages

+ + + + + + + + + + + Error + Failure + Pass + + + + + + + + + + + +
+ + <none> + + + + +
+ + +
+ + + + + + + + + + + + open('package-frame.html','classListFrame') + +

Package

+ + + + + +

Classes

+

+ + + + + +
+

+
+ + +
+ + + + + + + ../ + + + + + + ../ + + + + + + + + stylesheet.css + + + + + +

Unit Test Results

+ + + + + +
Designed for use with JUnit and Ant.
+
+
+ + + + + Name + Tests + Errors + Failures + Time(s) + Time Stamp + Host + + + + + + + Name + Status + Type + Time(s) + + + + + + + + + + Error + Failure + Pass + + + + + + + + + + + + + + + + + + + + Error + Failure + TableRowColor + + + + + + Failure + + + + Error + + + + Success + + + + + + + + + + + + + + + + + + + + + + + + + N/A + + + + + +

+ + + + + + + +
+ + + + + + + + + + + + +
+ +
+ + + + + + + + + + + diff --git a/src/etc/junit-frames.xsl b/src/etc/junit-frames.xsl index 114e45973..28d43221a 100644 --- a/src/etc/junit-frames.xsl +++ b/src/etc/junit-frames.xsl @@ -1,6 +1,6 @@ diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/Xalan1Executor.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/Xalan1Executor.java index fb3af7145..0b5e558b3 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/Xalan1Executor.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/Xalan1Executor.java @@ -30,10 +30,35 @@ import org.apache.xalan.xslt.XSLTResultTarget; * @ant.task ignore="true" */ public class Xalan1Executor extends XalanExecutor { + + private static final String xsltP = "org.apache.xalan.xslt.XSLTProcessor"; + + private XSLTProcessor processor = XSLTProcessorFactory.getProcessor(); + + protected String getImplementation() { + return processor.getClass().getName(); + } + + protected String getProcVersion(String classNameImpl) + throws BuildException { + try { + // xalan 1 + if (classNameImpl.equals(xsltP)){ + return getXalanVersion(xsltP + "Version"); + } + throw new BuildException("Could not find a valid processor version" + + " implementation from " + + classNameImpl); + } catch (ClassNotFoundException e){ + throw new BuildException("Could not find processor version " + + "implementation", e); + } + } + void execute() throws Exception { - XSLTProcessor processor = XSLTProcessorFactory.getProcessor(); // need to quote otherwise it breaks because of "extra illegal tokens" - processor.setStylesheetParam("output.dir", "'" + caller.toDir.getAbsolutePath() + "'"); + processor.setStylesheetParam("output.dir", "'" + + caller.toDir.getAbsolutePath() + "'"); XSLTInputSource xml_src = new XSLTInputSource(caller.document); String system_id = caller.getStylesheetSystemId(); XSLTInputSource xsl_src = new XSLTInputSource(system_id); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/Xalan2Executor.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/Xalan2Executor.java index ab7a4be82..08e906844 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/Xalan2Executor.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/Xalan2Executor.java @@ -25,6 +25,8 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; +import org.apache.tools.ant.BuildException; + /** * Xalan executor via JAXP. Nothing special must exists in the classpath * besides of course, a parser, jaxp and xalan. @@ -32,8 +34,46 @@ import javax.xml.transform.stream.StreamSource; * @ant.task ignore="true" */ public class Xalan2Executor extends XalanExecutor { + + private static final String aPack = "org.apache.xalan."; + private static final String sPack = "com.sun.org.apache.xalan."; + + private TransformerFactory tfactory = TransformerFactory.newInstance(); + + protected String getImplementation() throws BuildException { + return tfactory.getClass().getName(); + } + + protected String getProcVersion(String classNameImpl) + throws BuildException { + try { + // xalan 2 + if (classNameImpl.equals(aPack + "processor.TransformerFactoryImpl") + || + classNameImpl.equals(aPack + "xslt.XSLTProcessorFactory")) { + return getXalanVersion(aPack + "processor.XSLProcessorVersion"); + } + // xalan xsltc + if (classNameImpl.equals(aPack + + "xsltc.trax.TransformerFactoryImpl")){ + return getXSLTCVersion(aPack +"xsltc.ProcessorVersion"); + } + // jdk 1.5 xsltc + if (classNameImpl + .equals(sPack + "internal.xsltc.trax.TransformerFactoryImpl")){ + return getXSLTCVersion(sPack + + "internal.xsltc.ProcessorVersion"); + } + throw new BuildException("Could not find a valid processor version" + + " implementation from " + + classNameImpl); + } catch (ClassNotFoundException e){ + throw new BuildException("Could not find processor version " + + "implementation", e); + } + } + void execute() throws Exception { - TransformerFactory tfactory = TransformerFactory.newInstance(); String system_id = caller.getStylesheetSystemId(); Source xsl_src = new StreamSource(system_id); Transformer tformer = tfactory.newTransformer(xsl_src); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/XalanExecutor.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/XalanExecutor.java index ad13c6fca..bfb613755 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/XalanExecutor.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/XalanExecutor.java @@ -33,9 +33,12 @@ import org.apache.tools.ant.util.JavaEnvUtils; * Command class that encapsulate specific behavior for each * Xalan version. The right executor will be instantiated at * runtime via class lookup. For instance, it will check first - * for Xalan2, then for Xalan1. + * for Xalan2/XSLTC, then for Xalan1. */ abstract class XalanExecutor { + private static final String pack = + "org.apache.tools.ant.taskdefs.optional.junit."; + /** the transformer caller */ protected AggregateTransformer caller; @@ -45,7 +48,7 @@ abstract class XalanExecutor { } /** get the appropriate stream based on the format (frames/noframes) */ - protected OutputStream getOutputStream() throws IOException { + protected final OutputStream getOutputStream() throws IOException { if (AggregateTransformer.FRAMES.equals(caller.format)) { // dummy output for the framed report // it's all done by extension... @@ -66,53 +69,73 @@ abstract class XalanExecutor { * @throws BuildException thrown if it could not find a valid xalan * executor. */ - static XalanExecutor newInstance(AggregateTransformer caller) throws BuildException { - Class procVersion = null; + static XalanExecutor newInstance(AggregateTransformer caller) + throws BuildException { XalanExecutor executor = null; try { - procVersion = Class.forName("org.apache.xalan.processor.XSLProcessorVersion"); - executor = (XalanExecutor) Class.forName( - "org.apache.tools.ant.taskdefs.optional.junit.Xalan2Executor").newInstance(); - } catch (Exception xalan2missing) { - StringWriter swr = new StringWriter(); - xalan2missing.printStackTrace(new PrintWriter(swr)); - caller.task.log("Didn't find Xalan2.", Project.MSG_DEBUG); - caller.task.log(swr.toString(), Project.MSG_DEBUG); + Class clazz = Class.forName(pack + "Xalan2Executor"); + executor = (XalanExecutor)clazz.newInstance(); + } catch (Exception xsltcApacheMissing){ + caller.task.log(xsltcApacheMissing.toString()); try { - procVersion = Class.forName("org.apache.xalan.xslt.XSLProcessorVersion"); - executor = (XalanExecutor) Class.forName( - "org.apache.tools.ant.taskdefs.optional.junit.Xalan1Executor").newInstance(); - } catch (Exception xalan1missing) { - swr = new StringWriter(); - xalan1missing.printStackTrace(new PrintWriter(swr)); - caller.task.log("Didn't find Xalan1.", Project.MSG_DEBUG); - caller.task.log(swr.toString(), Project.MSG_DEBUG); - String msg = "Could not find xalan2 nor xalan1 " - + "in the classpath. Check http://xml.apache.org/xalan-j/"; - if (!JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1) - && !JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2) - && !JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_3) - && !JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_4)) { - msg += "\r\nStarting with JDK 1.5, the built-in processor " - + "of the JDK is no longer Xalan\r\nbut XSLTC which is " - + "not (yet) supported by the junitreport task."; - } - throw new BuildException(msg); + Class clazz = Class.forName(pack + "Xalan1Executor"); + executor = (XalanExecutor) clazz.newInstance(); + } catch (Exception xalan1Missing){ + caller.task.log(xalan1Missing.toString()); + throw new BuildException("Could not find xstlc nor xalan2 nor " + + "xalan1 in the classpath. Check " + + "http://xml.apache.org/xalan-j"); } } - String version = getXalanVersion(procVersion); - caller.task.log("Using Xalan version: " + version); + String classNameImpl = executor.getImplementation(); + String version = executor.getProcVersion(classNameImpl); + caller.task.log("Using " + version, Project.MSG_VERBOSE); executor.setCaller(caller); return executor; } + /** + * This methods should return the classname implementation of the + * underlying xslt processor + * @return the classname of the implementation, for example: + * org.apache.xalan.processor.TransformerFactoryImpl + * @see #getProcVersion(String) + */ + protected abstract String getImplementation(); + + /** + * Try to discover the xslt processor version based on the + * className. There is nothing carved in stone and it can change + * anytime, so this is just for the sake of giving additional + * information if we can find it. + * @param classNameImpl the classname of the underlying xslt processor + * @return a string representing the implementation version. + * @throws BuildException + */ + protected abstract String getProcVersion(String classNameImpl) + throws BuildException; + + /** a bit simplistic but xsltc data are conveniently private non final */ + protected final String getXSLTCVersion(String procVersionClassName) + throws ClassNotFoundException { + // there's a convenient xsltc class version but data are + // private so use package information + Class procVersion = Class.forName(procVersionClassName); + Package pkg = procVersion.getPackage(); + return pkg.getName() + " " + pkg.getImplementationTitle() + + " " + pkg.getImplementationVersion(); + } + /** pretty useful data (Xalan version information) to display. */ - private static String getXalanVersion(Class procVersion) { + protected final String getXalanVersion(String procVersionClassName) + throws ClassNotFoundException { + Class procVersion = Class.forName(procVersionClassName); + String pkg = procVersion.getPackage().getName(); try { Field f = procVersion.getField("S_VERSION"); - return f.get(null).toString(); + return pkg + " " + f.get(null).toString(); } catch (Exception e) { - return "?"; + return pkg + " ?.?"; } } } diff --git a/xdocs/faq.xml b/xdocs/faq.xml index 955d3ae42..664ccb976 100644 --- a/xdocs/faq.xml +++ b/xdocs/faq.xml @@ -1507,9 +1507,8 @@ mv /tmp/foo $ANT_HOME/bin/antRun href="http://xml.apache.org/xalan-j/">Xalan-J 2 in order to use this task with JDK 1.5.

-

If you want to follow progress on this, here - is the relevant bug report.

+

Starting with Ant 1.6.2 <junitreport> + will support JDK 1.5.