From 0b52075bb1a4f7ddc2a22342ff76faf61250fcd9 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Thu, 5 Aug 2010 18:45:11 +0000 Subject: [PATCH] better fix for bug 49271 as suggested by Jesse git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@982729 13f79535-47bb-0310-9956-ffa450edef68 --- .../tools/ant/taskdefs/XSLTProcess.java | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java index 1c3d73af4..553ae8622 100644 --- a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java +++ b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java @@ -108,10 +108,6 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { /** for resolving entities such as dtds */ private XMLCatalog xmlCatalog = new XMLCatalog(); - /** Name of the TRAX Liaison class */ - private static final String TRAX_LIAISON_CLASS = - "org.apache.tools.ant.taskdefs.optional.TraXLiaison"; - /** Utilities used for file operations */ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); @@ -340,6 +336,8 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { return; } try { + setupLoader(); + if (sysProperties.size() > 0) { sysProperties.setSystem(); } @@ -676,13 +674,12 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { private void resolveProcessor(String proc) throws Exception { String classname; if (proc.equals(PROCESSOR_TRAX)) { - classname = TRAX_LIAISON_CLASS; + liaison = new org.apache.tools.ant.taskdefs.optional.TraXLiaison(); } else { //anything else is a classname - classname = proc; + Class clazz = loadClass(proc); + liaison = (XSLTLiaison) clazz.newInstance(); } - Class clazz = loadClass(classname); - liaison = (XSLTLiaison) clazz.newInstance(); } /** @@ -695,14 +692,25 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { * @exception Exception if the class could not be loaded. */ private Class loadClass(String classname) throws Exception { - if (classpath == null) { + setupLoader(); + if (loader == null) { return Class.forName(classname); } - loader = getProject().createClassLoader(classpath); - loader.setThreadContextLoader(); return Class.forName(classname, true, loader); } + /** + * If a custom classpath has been defined but no loader created + * yet, create the classloader and set it as the context + * classloader. + */ + private void setupLoader() { + if (classpath != null && loader == null) { + loader = getProject().createClassLoader(classpath); + loader.setThreadContextLoader(); + } + } + /** * Specifies the output name for the styled result from the * in attribute; required if in is set