Skip to content

Commit

Permalink
Add support for Xalan2 Traces. PR 36670.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@722849 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
bodewig committed Dec 3, 2008
1 parent ab97747 commit ce748e7
Show file tree
Hide file tree
Showing 7 changed files with 290 additions and 44 deletions.
59 changes: 16 additions & 43 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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*"/>
Expand All @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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"/>
Expand Down Expand Up @@ -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"/>
Expand Down Expand Up @@ -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"/>
Expand Down Expand Up @@ -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-->
Expand Down Expand Up @@ -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"/>

Expand All @@ -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>
Expand Down Expand Up @@ -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"/>
Expand Down Expand Up @@ -783,6 +763,7 @@
<selector refid="needs.jdepend"/>
<selector refid="needs.swing"/>
<selector refid="needs.jsch"/>
<selector refid="needs.apache-xalan2"/>
</or>
</not>
</and>
Expand Down Expand Up @@ -823,6 +804,7 @@
<optional-jar dep="swing"/>
<optional-jar dep="jsch"/>
<optional-jar dep="jdepend"/>
<optional-jar dep="apache-xalan2"/>

</target>

Expand Down Expand Up @@ -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"/>
Expand Down Expand Up @@ -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"/>
Expand Down
2 changes: 1 addition & 1 deletion lib/libraries.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
130 changes: 130 additions & 0 deletions src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -631,6 +638,33 @@ public void addSyspropertyset(PropertySet sysp) {
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
Expand Down Expand Up @@ -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);
}
}

}
36 changes: 36 additions & 0 deletions src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
}
}

/**
Expand Down Expand Up @@ -583,5 +617,7 @@ public void configure(XSLTProcess xsltTask) {
}

suppressWarnings = xsltTask.getSuppressWarnings();

traceConfiguration = xsltTask.getTraceConfiguration();
}
}
Loading

0 comments on commit ce748e7

Please sign in to comment.