git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@722849 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -170,21 +170,6 @@ | |||
| =================================================================== | |||
| --> | |||
| <!-- depends on JDK version --> | |||
| <selector id="needs.jdk1.3+"> | |||
| <or> | |||
| <filename name="${ant.package}/taskdefs/TestProcess*"/> | |||
| <filename name="${optional.package}/extension/**"/> | |||
| </or> | |||
| </selector> | |||
| <selector id="needs.jdk1.4+"> | |||
| <or> | |||
| <filename name="${regexp.package}/Jdk14Regexp*"/> | |||
| <filename name="${ant.package}/types/AssertionsTest.java"/> | |||
| <filename name="${ant.package}/launch/LocatorTest*"/> | |||
| </or> | |||
| </selector> | |||
| <selector id="needs.jdk1.5+"> | |||
| <or> | |||
| <filename name="${taskdefs.package}/AptTest*"/> | |||
| @@ -204,6 +189,7 @@ | |||
| <selector id="needs.trax"> | |||
| <or> | |||
| <filename name="${optional.package}/TraXLiaison*"/> | |||
| <filename name="${optional.package}/XSLTTraceSupport*"/> | |||
| <filename name="${optional.package}/XsltTest*"/> | |||
| <filename name="${type.package}/XMLCatalogBuildFileTest*"/> | |||
| </or> | |||
| @@ -300,6 +286,11 @@ | |||
| <filename name="${optional.package}/ssh/*"/> | |||
| </selector> | |||
| <!-- needs TraceListenerEx3 interface implemented by PrintTraceListener --> | |||
| <selector id="needs.apache-xalan2"> | |||
| <filename name="${optional.package}/Xalan2TraceSupport*"/> | |||
| </selector> | |||
| <selector id="ant.launcher"> | |||
| <filename name="${ant.package}/launch/**/*"/> | |||
| </selector> | |||
| @@ -356,8 +347,6 @@ | |||
| =================================================================== | |||
| --> | |||
| <target name="check_for_optional_packages"> | |||
| <available property="jdk1.3+" classname="java.lang.StrictMath"/> | |||
| <available property="jdk1.4+" classname="java.lang.CharSequence"/> | |||
| <available property="jdk1.5+" classname="java.net.Proxy"/> | |||
| <available property="jdk1.6+" classname="java.util.ServiceLoader"/> | |||
| <available property="kaffe" classname="kaffe.util.NotImplemented"/> | |||
| @@ -386,6 +375,9 @@ | |||
| <available property="xalan2.present" | |||
| classname="org.apache.xalan.transformer.TransformerImpl" | |||
| classpathref="classpath"/> | |||
| <available property="recent.xalan2.present" | |||
| classname="org.apache.xalan.trace.TraceListenerEx3" | |||
| classpathref="classpath"/> | |||
| <available property="junit.present" | |||
| classname="junit.framework.TestCase" | |||
| classpathref="classpath"/> | |||
| @@ -445,14 +437,6 @@ | |||
| </and> | |||
| </condition> | |||
| <condition property="some.regexp.support"> | |||
| <or> | |||
| <isset property="jdk1.4+"/> | |||
| <isset property="apache.regexp.present"/> | |||
| <isset property="apache.oro.present"/> | |||
| </or> | |||
| </condition> | |||
| <condition property="tests.and.ant.share.classloader"> | |||
| <or> | |||
| <equals arg1="${junit.fork}" arg2="true"/> | |||
| @@ -521,11 +505,6 @@ | |||
| classname="com.jcraft.jsch.Session" | |||
| classpathref="classpath"/> | |||
| <condition property="build.compiler" value="classic"> | |||
| <not> | |||
| <isset property="jdk1.3+"/> | |||
| </not> | |||
| </condition> | |||
| <property name="build.compiler" value="modern"/> | |||
| <!--check for XSD support in the parser--> | |||
| @@ -579,8 +558,6 @@ | |||
| <selector id="conditional-patterns"> | |||
| <not> | |||
| <or> | |||
| <selector refid="needs.jdk1.3+" unless="jdk1.3+"/> | |||
| <selector refid="needs.jdk1.4+" unless="jdk1.4+"/> | |||
| <selector refid="needs.jdk1.5+" unless="jdk1.5+"/> | |||
| <selector refid="not.in.kaffe" if="kaffe"/> | |||
| @@ -606,6 +583,10 @@ | |||
| <selector refid="needs.swing" unless="swing.present"/> | |||
| <selector refid="needs.jsch" unless="jsch.present"/> | |||
| <selector refid="needs.xmlschema" unless="xmlschema.present"/> | |||
| <selector refid="needs.apache-xalan2" | |||
| unless="recent.xalan2.present"/> | |||
| <!-- Java 1.4's built-in Xalan is first on the classpath --> | |||
| <selector refid="needs.apache-xalan2" unless="jdk1.5+"/> | |||
| </or> | |||
| </not> | |||
| </selector> | |||
| @@ -704,7 +685,6 @@ | |||
| <selector refid="needs.apache-regexp"/> | |||
| <selector refid="needs.apache-resolver"/> | |||
| <selector refid="needs.apache-oro"/> | |||
| <selector refid="needs.jdk1.4+"/> | |||
| <selector refid="needs.jdk1.5+"/> | |||
| <selector refid="needs.javamail"/> | |||
| <selector refid="ant.launcher"/> | |||
| @@ -783,6 +763,7 @@ | |||
| <selector refid="needs.jdepend"/> | |||
| <selector refid="needs.swing"/> | |||
| <selector refid="needs.jsch"/> | |||
| <selector refid="needs.apache-xalan2"/> | |||
| </or> | |||
| </not> | |||
| </and> | |||
| @@ -823,6 +804,7 @@ | |||
| <optional-jar dep="swing"/> | |||
| <optional-jar dep="jsch"/> | |||
| <optional-jar dep="jdepend"/> | |||
| <optional-jar dep="apache-xalan2"/> | |||
| </target> | |||
| @@ -1755,15 +1737,6 @@ see ${build.junit.reports} / ${antunit.reports} | |||
| <!-- failing tests excluded unless run.failing.tests is set --> | |||
| <patternset refid="teststhatfail"/> | |||
| <!-- runtime dependencies that are different from compile | |||
| time dependencies --> | |||
| <exclude name="${optional.package}/ReplaceRegExpTest.java" | |||
| unless="some.regexp.support"/> | |||
| <exclude name="${ant.package}/types/selectors/ContainsRegexpTest.java" | |||
| unless="some.regexp.support"/> | |||
| <exclude name="${ant.package}/types/mappers/RegexpPatternMapperTest.java" | |||
| unless="some.regexp.support"/> | |||
| <!-- needs BSF to work --> | |||
| <exclude name="${optional.package}/Rhino*.java" | |||
| unless="bsf.present"/> | |||
| @@ -1873,7 +1846,7 @@ see ${build.junit.reports} / ${antunit.reports} | |||
| <target name="interactive-tests" description="--> runs interactive tests" | |||
| depends="compile-tests" | |||
| if="jdk1.3+"> | |||
| > | |||
| <java classpathref="tests-classpath" | |||
| classname="org.apache.tools.ant.taskdefs.TestProcess" | |||
| fork="true"/> | |||
| @@ -59,7 +59,7 @@ xercesImpl.version=${xerces.version} | |||
| #xmlParserAPIs.version=${xerces.version} | |||
| #xmlParserAPIs.version=2.6.1 | |||
| xml-apis.version=2.0.2 | |||
| xalan.version=2.7.0 | |||
| xalan.version=2.7.1 | |||
| xml-resolver.version=1.2 | |||
| mail.version=1.4 | |||
| #paired | |||
| @@ -209,6 +209,13 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||
| private CommandlineJava.SysProperties sysProperties = | |||
| new CommandlineJava.SysProperties(); | |||
| /** | |||
| * Trace configuration for Xalan2. | |||
| * | |||
| * @since Ant 1.8.0 | |||
| */ | |||
| private TraceConfiguration traceConfiguration; | |||
| /** | |||
| * Creates a new XSLTProcess Task. | |||
| */ | |||
| @@ -631,6 +638,33 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||
| sysProperties.addSyspropertyset(sysp); | |||
| } | |||
| /** | |||
| * Enables Xalan2 traces and uses the given configuration. | |||
| * | |||
| * <p>Note that this element doesn't have any effect with a | |||
| * processor other than trax or if the Transformer is not Xalan2's | |||
| * transformer implementation.</p> | |||
| * | |||
| * @since Ant 1.8.0 | |||
| */ | |||
| public TraceConfiguration createTrace() { | |||
| if (traceConfiguration != null) { | |||
| throw new BuildException("can't have more than one trace" | |||
| + " configuration"); | |||
| } | |||
| traceConfiguration = new TraceConfiguration(); | |||
| return traceConfiguration; | |||
| } | |||
| /** | |||
| * Configuration for Xalan2 traces. | |||
| * | |||
| * @since Ant 1.8.0 | |||
| */ | |||
| public TraceConfiguration getTraceConfiguration() { | |||
| return traceConfiguration; | |||
| } | |||
| /** | |||
| * Load processor here instead of in setProcessor - this will be | |||
| * called from within execute, so we have access to the latest | |||
| @@ -1358,4 +1392,100 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||
| } | |||
| } | |||
| /** | |||
| * Configuration for Xalan2 traces. | |||
| * | |||
| * @since Ant 1.8.0 | |||
| */ | |||
| public final class TraceConfiguration { | |||
| private boolean elements, extension, generation, selection, templates; | |||
| /** | |||
| * Set to true if the listener is to print events that occur | |||
| * as each node is 'executed' in the stylesheet. | |||
| */ | |||
| public void setElements(boolean b) { | |||
| elements = b; | |||
| } | |||
| /** | |||
| * True if the listener is to print events that occur as each | |||
| * node is 'executed' in the stylesheet. | |||
| */ | |||
| public boolean getElements() { | |||
| return elements; | |||
| } | |||
| /** | |||
| * Set to true if the listener is to print information after | |||
| * each extension event. | |||
| */ | |||
| public void setExtension(boolean b) { | |||
| extension = b; | |||
| } | |||
| /** | |||
| * True if the listener is to print information after each | |||
| * extension event. | |||
| */ | |||
| public boolean getExtension() { | |||
| return extension; | |||
| } | |||
| /** | |||
| * Set to true if the listener is to print information after | |||
| * each result-tree generation event. | |||
| */ | |||
| public void setGeneration(boolean b) { | |||
| generation = b; | |||
| } | |||
| /** | |||
| * True if the listener is to print information after each | |||
| * result-tree generation event. | |||
| */ | |||
| public boolean getGeneration() { | |||
| return generation; | |||
| } | |||
| /** | |||
| * Set to true if the listener is to print information after | |||
| * each selection event. | |||
| */ | |||
| public void setSelection(boolean b) { | |||
| selection = b; | |||
| } | |||
| /** | |||
| * True if the listener is to print information after each | |||
| * selection event. | |||
| */ | |||
| public boolean getSelection() { | |||
| return selection; | |||
| } | |||
| /** | |||
| * Set to true if the listener is to print an event whenever a | |||
| * template is invoked. | |||
| */ | |||
| public void setTemplates(boolean b) { | |||
| templates = b; | |||
| } | |||
| /** | |||
| * True if the listener is to print an event whenever a | |||
| * template is invoked. | |||
| */ | |||
| public boolean getTemplates() { | |||
| return templates; | |||
| } | |||
| /** | |||
| * The stream to write traces to. | |||
| */ | |||
| public java.io.OutputStream getOutputStream() { | |||
| return new LogOutputStream(XSLTProcess.this); | |||
| } | |||
| } | |||
| } | |||
| @@ -125,6 +125,9 @@ public class TraXLiaison implements XSLTLiaison3, ErrorListener, XSLTLoggerAware | |||
| /** whether to suppress warnings */ | |||
| private boolean suppressWarnings = false; | |||
| /** optional trace configuration. */ | |||
| private XSLTProcess.TraceConfiguration traceConfiguration = null; | |||
| /** | |||
| * Constructor for TraXLiaison. | |||
| * @throws Exception never | |||
| @@ -324,6 +327,37 @@ public class TraXLiaison implements XSLTLiaison3, ErrorListener, XSLTLoggerAware | |||
| final String[] pair = (String[]) outputProperties.elementAt(i); | |||
| transformer.setOutputProperty(pair[0], pair[1]); | |||
| } | |||
| if (traceConfiguration != null) { | |||
| if ("org.apache.xalan.transformer.TransformerImpl" | |||
| .equals(transformer.getClass().getName())) { | |||
| try { | |||
| Class traceSupport = | |||
| Class.forName("org.apache.tools.ant.taskdefs.optional." | |||
| + "Xalan2TraceSupport", true, | |||
| Thread.currentThread() | |||
| .getContextClassLoader()); | |||
| XSLTTraceSupport ts = | |||
| (XSLTTraceSupport) traceSupport.newInstance(); | |||
| ts.configureTrace(transformer, traceConfiguration); | |||
| } catch (Exception e) { | |||
| String msg = "Failed to enable tracing because of " + e; | |||
| if (project != null) { | |||
| project.log(msg, Project.MSG_WARN); | |||
| } else { | |||
| System.err.println(msg); | |||
| } | |||
| } | |||
| } else { | |||
| String msg = "Not enabling trace support for transformer" | |||
| + " implementation" + transformer.getClass().getName(); | |||
| if (project != null) { | |||
| project.log(msg, Project.MSG_WARN); | |||
| } else { | |||
| System.err.println(msg); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| @@ -583,5 +617,7 @@ public class TraXLiaison implements XSLTLiaison3, ErrorListener, XSLTLoggerAware | |||
| } | |||
| suppressWarnings = xsltTask.getSuppressWarnings(); | |||
| traceConfiguration = xsltTask.getTraceConfiguration(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,31 @@ | |||
| /* | |||
| * Licensed to the Apache Software Foundation (ASF) under one or more | |||
| * contributor license agreements. See the NOTICE file distributed with | |||
| * this work for additional information regarding copyright ownership. | |||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | |||
| * (the "License"); you may not use this file except in compliance with | |||
| * the License. You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| * | |||
| */ | |||
| package org.apache.tools.ant.taskdefs.optional; | |||
| import org.apache.tools.ant.taskdefs.XSLTProcess; | |||
| import javax.xml.transform.Transformer; | |||
| /** | |||
| * Sets up trace support for a given transformer. | |||
| * | |||
| * @since Ant 1.8.0 | |||
| */ | |||
| public interface XSLTTraceSupport { | |||
| void configureTrace(Transformer t, XSLTProcess.TraceConfiguration conf); | |||
| } | |||
| @@ -0,0 +1,52 @@ | |||
| /* | |||
| * Licensed to the Apache Software Foundation (ASF) under one or more | |||
| * contributor license agreements. See the NOTICE file distributed with | |||
| * this work for additional information regarding copyright ownership. | |||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | |||
| * (the "License"); you may not use this file except in compliance with | |||
| * the License. You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| * | |||
| */ | |||
| package org.apache.tools.ant.taskdefs.optional; | |||
| import java.io.PrintWriter; | |||
| import java.util.TooManyListenersException; | |||
| import javax.xml.transform.Transformer; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.taskdefs.XSLTProcess; | |||
| import org.apache.xalan.trace.PrintTraceListener; | |||
| import org.apache.xalan.transformer.TransformerImpl; | |||
| /** | |||
| * Sets up trace support for a given transformer. | |||
| * | |||
| * @since Ant 1.8.0 | |||
| */ | |||
| public class Xalan2TraceSupport implements XSLTTraceSupport { | |||
| public void configureTrace(Transformer t, | |||
| XSLTProcess.TraceConfiguration conf) { | |||
| if (t instanceof TransformerImpl && conf != null) { | |||
| PrintWriter w = new PrintWriter(conf.getOutputStream(), false); | |||
| PrintTraceListener tl = new PrintTraceListener(w); | |||
| tl.m_traceElements = conf.getElements(); | |||
| tl.m_traceExtension = conf.getExtension(); | |||
| tl.m_traceGeneration = conf.getGeneration(); | |||
| tl.m_traceSelection = conf.getSelection(); | |||
| tl.m_traceTemplates = conf.getTemplates(); | |||
| try { | |||
| ((TransformerImpl) t).getTraceManager().addTraceListener(tl); | |||
| } catch (TooManyListenersException tml) { | |||
| throw new BuildException(tml); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -146,4 +146,28 @@ undefined='<xsl:value-of select="$undefined"/>' | |||
| </fileset> | |||
| </xslt> | |||
| </target> | |||
| <available property="jdk1.5+" classname="java.net.Proxy"/> | |||
| <target name="testTraceJdk14" unless="jdk1.5+" depends="setUp"> | |||
| <xslt in="${legacy.dir}/data.xml" | |||
| out="${output}/out.xml" | |||
| style="${legacy.dir}/printParams.xsl"> | |||
| <param name="set" expression="myvalue"/> | |||
| <trace templates="true"/> | |||
| </xslt> | |||
| <au:assertLogContains text="Failed to enable tracing" level="warning"/> | |||
| </target> | |||
| <target name="testTraceJdk15+" if="jdk1.5+" depends="setUp"> | |||
| <xslt in="${legacy.dir}/data.xml" | |||
| out="${output}/out.xml" | |||
| style="${legacy.dir}/printParams.xsl"> | |||
| <param name="set" expression="myvalue"/> | |||
| <trace templates="true" elements="true" generation="true" | |||
| selection="true" extension="true"/> | |||
| </xslt> | |||
| <au:assertLogDoesntContain text="Failed to enable tracing"/> | |||
| </target> | |||
| </project> | |||