Browse Source

Set context classloader in <xslt>, PR: 24802

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276320 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 21 years ago
parent
commit
990243c785
2 changed files with 23 additions and 2 deletions
  1. +3
    -0
      WHATSNEW
  2. +20
    -2
      src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java

+ 3
- 0
WHATSNEW View File

@@ -113,6 +113,9 @@ Fixed bugs:
* <import optional="false"> and <import optional="true"> * <import optional="false"> and <import optional="true">
behaved identically. behaved identically.


* <xslt> now sets the context classloader if you've specified a nested
<classpath>. Bugzilla report 24802.

Other changes: Other changes:
-------------- --------------




+ 20
- 2
src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java View File

@@ -120,6 +120,18 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*/ */
private boolean reuseLoadedStylesheet = true; private boolean reuseLoadedStylesheet = true;


/**
* AntClassLoader for the nested &lt;classpath&gt; - if set.
*
* <p>We keep this here in order to reset the context classloader
* in execute. We can't use liaison.getClass().getClassLoader()
* since the actual liaison class may have been loaded by a loader
* higher up (system classloader, for example).</p>
*
* @since Ant 1.6.2
*/
private AntClassLoader loader = null;

/** /**
* Creates a new XSLTProcess Task. * Creates a new XSLTProcess Task.
*/ */
@@ -170,6 +182,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
if (inFile != null && !inFile.exists()) { if (inFile != null && !inFile.exists()) {
throw new BuildException("input file " + inFile.toString() + " does not exist", getLocation()); throw new BuildException("input file " + inFile.toString() + " does not exist", getLocation());
} }

try { try {
if (baseDir == null) { if (baseDir == null) {
baseDir = getProject().resolveFile("."); baseDir = getProject().resolveFile(".");
@@ -233,6 +246,10 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
} }
} }
} finally { } finally {
if (loader != null) {
loader.resetThreadContextLoader();
loader = null;
}
liaison = null; liaison = null;
stylesheetLoaded = false; stylesheetLoaded = false;
baseDir = savedBaseDir; baseDir = savedBaseDir;
@@ -379,8 +396,9 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
if (classpath == null) { if (classpath == null) {
return Class.forName(classname); return Class.forName(classname);
} else { } else {
AntClassLoader al = getProject().createClassLoader(classpath);
Class c = Class.forName(classname, true, al);
loader = getProject().createClassLoader(classpath);
loader.setThreadContextLoader();
Class c = Class.forName(classname, true, loader);
return c; return c;
} }
} }


Loading…
Cancel
Save