From 58069d34783fb894cc384be621f2867fb935f474 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 26 Nov 2008 09:21:17 +0000 Subject: [PATCH] Try to load TraX factory via configured classpath. PR 46172 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@720773 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 4 ++++ .../ant/taskdefs/optional/TraXLiaison.java | 23 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/WHATSNEW b/WHATSNEW index 6965369b2..b3c3263c5 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -296,6 +296,10 @@ Fixed bugs: without a name. It will now fail with a meaningful error message. Bugzilla Report 39960. + * now uses the configured classpath to load the factory (when + using TraX) before falling back to Ant's own classpath. + Bugzilla Report 46172. + Other changes: -------------- 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 ad8a47436..9ee7d0907 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java @@ -364,7 +364,28 @@ public class TraXLiaison implements XSLTLiaison3, ErrorListener, XSLTLoggerAware tfactory = TransformerFactory.newInstance(); } else { try { - Class clazz = Class.forName(factoryName); + Class clazz = null; + try { + clazz = + Class.forName(factoryName, true, + Thread.currentThread() + .getContextClassLoader()); + } catch (ClassNotFoundException cnfe) { + String msg = "Failed to load " + factoryName + + " via the configured classpath, will try" + + " Ant's classpath instead."; + if (logger != null) { + logger.log(msg); + } else if (project != null) { + project.log(msg, Project.MSG_WARN); + } else { + System.err.println(msg); + } + } + + if (clazz == null) { + clazz = Class.forName(factoryName); + } tfactory = (TransformerFactory) clazz.newInstance(); } catch (Exception e) { throw new BuildException(e);