diff --git a/build.xml b/build.xml index 0d2ad0ad77..c4d49c921c 100644 --- a/build.xml +++ b/build.xml @@ -170,21 +170,6 @@ =================================================================== --> - - - - - - - - - - - - - - - @@ -204,6 +189,7 @@ + @@ -300,6 +286,11 @@ + + + + + @@ -356,8 +347,6 @@ =================================================================== --> - - @@ -386,6 +375,9 @@ + @@ -445,14 +437,6 @@ - - - - - - - - @@ -521,11 +505,6 @@ classname="com.jcraft.jsch.Session" classpathref="classpath"/> - - - - - @@ -579,8 +558,6 @@ - - @@ -606,6 +583,10 @@ + + + @@ -704,7 +685,6 @@ - @@ -783,6 +763,7 @@ + @@ -823,6 +804,7 @@ + @@ -1755,15 +1737,6 @@ see ${build.junit.reports} / ${antunit.reports} - - - - - @@ -1873,7 +1846,7 @@ see ${build.junit.reports} / ${antunit.reports} + > diff --git a/lib/libraries.properties b/lib/libraries.properties index 6db88b4b0e..a00794897e 100644 --- a/lib/libraries.properties +++ b/lib/libraries.properties @@ -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 diff --git a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java index fac6608abd..147069b4c9 100644 --- a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java +++ b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java @@ -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 void addSyspropertyset(PropertySet sysp) { sysProperties.addSyspropertyset(sysp); } + /** + * Enables Xalan2 traces and uses the given configuration. + * + *

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.

+ * + * @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 String[] mapFileName(String xmlFile) { } } + /** + * 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); + } + } + } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java b/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java index 5a5e0b3569..a22fee0830 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java @@ -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 @@ private void createTransformer() throws Exception { 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 void configure(XSLTProcess xsltTask) { } suppressWarnings = xsltTask.getSuppressWarnings(); + + traceConfiguration = xsltTask.getTraceConfiguration(); } } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/XSLTTraceSupport.java b/src/main/org/apache/tools/ant/taskdefs/optional/XSLTTraceSupport.java new file mode 100644 index 0000000000..98ca15669c --- /dev/null +++ b/src/main/org/apache/tools/ant/taskdefs/optional/XSLTTraceSupport.java @@ -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); +} diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/Xalan2TraceSupport.java b/src/main/org/apache/tools/ant/taskdefs/optional/Xalan2TraceSupport.java new file mode 100644 index 0000000000..0e66cc4506 --- /dev/null +++ b/src/main/org/apache/tools/ant/taskdefs/optional/Xalan2TraceSupport.java @@ -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); + } + } + } +} diff --git a/src/tests/antunit/taskdefs/xslt-test.xml b/src/tests/antunit/taskdefs/xslt-test.xml index 2bb0e9877c..17576a4d23 100644 --- a/src/tests/antunit/taskdefs/xslt-test.xml +++ b/src/tests/antunit/taskdefs/xslt-test.xml @@ -146,4 +146,28 @@ undefined=''
+ + + + + + + + + + + + + + + + + + +