git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@811435 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -30,6 +30,7 @@ import java.util.Map; | |||
| import java.util.Properties; | |||
| import java.util.Vector; | |||
| import org.apache.tools.ant.AntClassLoader; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.PropertyHelper; | |||
| @@ -558,10 +559,11 @@ public class Property extends Task { | |||
| Properties props = new Properties(); | |||
| log("Resource Loading " + name, Project.MSG_VERBOSE); | |||
| InputStream is = null; | |||
| ClassLoader cL = null; | |||
| boolean cleanup = false; | |||
| try { | |||
| ClassLoader cL = null; | |||
| if (classpath != null) { | |||
| cleanup = true; | |||
| cL = getProject().createClassLoader(classpath); | |||
| } else { | |||
| cL = this.getClass().getClassLoader(); | |||
| @@ -589,6 +591,9 @@ public class Property extends Task { | |||
| // ignore | |||
| } | |||
| } | |||
| if (cleanup && cL != null) { | |||
| ((AntClassLoader) cL).cleanup(); | |||
| } | |||
| } | |||
| } | |||
| @@ -21,6 +21,7 @@ import java.io.File; | |||
| import java.io.IOException; | |||
| import java.rmi.Remote; | |||
| import java.util.Vector; | |||
| import org.apache.tools.ant.AntClassLoader; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.DirectoryScanner; | |||
| import org.apache.tools.ant.Project; | |||
| @@ -104,7 +105,7 @@ public class Rmic extends MatchingTask { | |||
| private Vector compileList = new Vector(); | |||
| private ClassLoader loader = null; | |||
| private AntClassLoader loader = null; | |||
| private FacadeTaskHelper facade; | |||
| /** unable to verify message */ | |||
| @@ -581,6 +582,7 @@ public class Rmic extends MatchingTask { | |||
| * if there's a problem with baseDir or RMIC | |||
| */ | |||
| public void execute() throws BuildException { | |||
| try { | |||
| compileList.clear(); | |||
| File outputDir = getOutputDir(); | |||
| @@ -659,6 +661,21 @@ public class Rmic extends MatchingTask { | |||
| } | |||
| } | |||
| } | |||
| } finally { | |||
| cleanup(); | |||
| } | |||
| } | |||
| /** | |||
| * Cleans up resources. | |||
| * | |||
| * @since Ant 1.8.0 | |||
| */ | |||
| protected void cleanup() { | |||
| if (loader != null) { | |||
| loader.cleanup(); | |||
| loader = null; | |||
| } | |||
| } | |||
| /** | |||
| @@ -126,15 +126,16 @@ public class WhichResource extends Task { | |||
| public void execute() throws BuildException { | |||
| validate(); | |||
| if (classpath != null) { | |||
| classpath = classpath.concatSystemClasspath("ignore"); | |||
| getProject().log("using user supplied classpath: " + classpath, | |||
| Project.MSG_DEBUG); | |||
| classpath = classpath.concatSystemClasspath("ignore"); | |||
| } else { | |||
| classpath = new Path(getProject()); | |||
| classpath = classpath.concatSystemClasspath("only"); | |||
| getProject().log("using system classpath: " + classpath, Project.MSG_DEBUG); | |||
| } | |||
| AntClassLoader loader; | |||
| AntClassLoader loader = null; | |||
| try { | |||
| loader = AntClassLoader.newAntClassLoader(getProject().getCoreLoader(), | |||
| getProject(), | |||
| classpath, false); | |||
| @@ -160,6 +161,11 @@ public class WhichResource extends Task { | |||
| loc = url.toExternalForm(); | |||
| getProject().setNewProperty(property, loc); | |||
| } | |||
| } finally { | |||
| if (loader != null) { | |||
| loader.cleanup(); | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| @@ -152,6 +152,7 @@ public final class CompilerAdapterFactory { | |||
| return new Sj(); | |||
| } | |||
| return resolveClassName(compilerType, | |||
| // Memory-Leak in line below | |||
| task.getProject().createClassLoader(classpath)); | |||
| } | |||
| @@ -110,7 +110,6 @@ public class HasMethod extends ProjectComponent implements Condition { | |||
| loader = getProject().createClassLoader(classpath); | |||
| loader.setParentFirst(false); | |||
| loader.addJavaLibraries(); | |||
| if (loader != null) { | |||
| try { | |||
| return loader.findClass(classname); | |||
| } catch (SecurityException se) { | |||
| @@ -118,11 +117,9 @@ public class HasMethod extends ProjectComponent implements Condition { | |||
| // actually the case we're looking for in JDK 1.3+, | |||
| // so catch the exception and return | |||
| return null; | |||
| } | |||
| } else { | |||
| return null; | |||
| } | |||
| } else if (loader != null) { | |||
| // How do we ever get here? | |||
| return loader.loadClass(classname); | |||
| } else { | |||
| ClassLoader l = this.getClass().getClassLoader(); | |||
| @@ -148,6 +145,8 @@ public class HasMethod extends ProjectComponent implements Condition { | |||
| if (classname == null) { | |||
| throw new BuildException("No classname defined"); | |||
| } | |||
| ClassLoader preLoadClass = loader; | |||
| try { | |||
| Class clazz = loadClass(classname); | |||
| if (method != null) { | |||
| return isMethodFound(clazz); | |||
| @@ -156,6 +155,12 @@ public class HasMethod extends ProjectComponent implements Condition { | |||
| return isFieldFound(clazz); | |||
| } | |||
| throw new BuildException("Neither method nor field defined"); | |||
| } finally { | |||
| if (preLoadClass != loader && loader != null) { | |||
| loader.cleanup(); | |||
| loader = null; | |||
| } | |||
| } | |||
| } | |||
| private boolean isFieldFound(Class clazz) { | |||
| @@ -103,6 +103,8 @@ public class XMLValidateTask extends Task { | |||
| public static final String MESSAGE_FILES_VALIDATED | |||
| = " file(s) have been successfully validated."; | |||
| private AntClassLoader readerLoader = null; | |||
| /** | |||
| * Specify how parser error are to be handled. | |||
| * Optional, default is <code>true</code>. | |||
| @@ -285,7 +287,7 @@ public class XMLValidateTask extends Task { | |||
| * @throws BuildException if <code>failonerror</code> is true and an error happens | |||
| */ | |||
| public void execute() throws BuildException { | |||
| try { | |||
| int fileProcessed = 0; | |||
| if (file == null && (filesets.size() == 0)) { | |||
| throw new BuildException( | |||
| @@ -321,6 +323,9 @@ public class XMLValidateTask extends Task { | |||
| } | |||
| } | |||
| onSuccessfulValidation(fileProcessed); | |||
| } finally { | |||
| cleanup(); | |||
| } | |||
| } | |||
| /** | |||
| @@ -389,9 +394,9 @@ public class XMLValidateTask extends Task { | |||
| try { | |||
| // load the parser class | |||
| if (classpath != null) { | |||
| AntClassLoader loader = | |||
| getProject().createClassLoader(classpath); | |||
| readerClass = Class.forName(readerClassName, true, loader); | |||
| readerLoader = getProject().createClassLoader(classpath); | |||
| readerClass = Class.forName(readerClassName, true, | |||
| readerLoader); | |||
| } else { | |||
| readerClass = Class.forName(readerClassName); | |||
| } | |||
| @@ -431,6 +436,18 @@ public class XMLValidateTask extends Task { | |||
| return newReader; | |||
| } | |||
| /** | |||
| * Cleans up resources. | |||
| * | |||
| * @since Ant 1.8.0 | |||
| */ | |||
| protected void cleanup() { | |||
| if (readerLoader != null) { | |||
| readerLoader.cleanup(); | |||
| readerLoader = null; | |||
| } | |||
| } | |||
| /** | |||
| * | |||
| * @return | |||
| @@ -929,6 +929,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool { | |||
| if (combinedClasspath == null) { | |||
| classpathLoader = getClass().getClassLoader(); | |||
| } else { | |||
| // Memory leak in line below | |||
| classpathLoader | |||
| = getTask().getProject().createClassLoader(combinedClasspath); | |||
| } | |||
| @@ -679,7 +679,10 @@ public class JonasDeploymentTool extends GenericDeploymentTool { | |||
| log("Looking for GenIC class in classpath: " | |||
| + classpath.toString(), Project.MSG_VERBOSE); | |||
| AntClassLoader cl = classpath.getProject().createClassLoader(classpath); | |||
| AntClassLoader cl = null; | |||
| try { | |||
| cl = classpath.getProject().createClassLoader(classpath); | |||
| try { | |||
| cl.loadClass(JonasDeploymentTool.GENIC_CLASS); | |||
| @@ -716,6 +719,11 @@ public class JonasDeploymentTool extends GenericDeploymentTool { | |||
| + "' not found in classpath.", | |||
| Project.MSG_VERBOSE); | |||
| } | |||
| } finally { | |||
| if (cl != null) { | |||
| cl.cleanup(); | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| @@ -27,6 +27,7 @@ import java.util.Iterator; | |||
| import java.util.jar.JarEntry; | |||
| import java.util.jar.JarFile; | |||
| import java.util.jar.JarOutputStream; | |||
| import org.apache.tools.ant.AntClassLoader; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.taskdefs.Java; | |||
| @@ -589,11 +590,9 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { | |||
| classpath = getCombinedClasspath(); | |||
| } | |||
| javaTask.setFork(true); | |||
| if (classpath != null) { | |||
| javaTask.setClasspath(classpath); | |||
| javaTask.setFork(true); | |||
| } else { | |||
| javaTask.setFork(true); | |||
| } | |||
| log("Calling websphere.ejbdeploy for " + sourceJar.toString(), | |||
| @@ -684,6 +683,7 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { | |||
| JarFile wasJar = null; | |||
| File newwasJarFile = null; | |||
| JarOutputStream newJarStream = null; | |||
| ClassLoader genericLoader = null; | |||
| try { | |||
| log("Checking if websphere Jar needs to be rebuilt for jar " | |||
| @@ -713,7 +713,7 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { | |||
| } | |||
| //Cycle Through generic and make sure its in websphere | |||
| ClassLoader genericLoader = getClassLoaderFromJar(genericJarFile); | |||
| genericLoader = getClassLoaderFromJar(genericJarFile); | |||
| for (Enumeration e = genericEntries.keys(); e.hasMoreElements();) { | |||
| String filepath = (String) e.nextElement(); | |||
| @@ -861,6 +861,11 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { | |||
| rebuild = true; | |||
| } | |||
| } | |||
| if (genericLoader != null | |||
| && genericLoader instanceof AntClassLoader) { | |||
| AntClassLoader loader = (AntClassLoader) genericLoader; | |||
| loader.cleanup(); | |||
| } | |||
| } | |||
| return rebuild; | |||
| @@ -889,4 +894,3 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { | |||
| return getTask().getProject().createClassLoader(lookupPath); | |||
| } | |||
| } | |||
| @@ -411,7 +411,9 @@ public class JavaCC extends Task { | |||
| String packagePrefix = null; | |||
| String mainClass = null; | |||
| AntClassLoader l = | |||
| AntClassLoader l = null; | |||
| try { | |||
| l = | |||
| AntClassLoader.newAntClassLoader(null, null, | |||
| path | |||
| .concatSystemClasspath("ignore"), | |||
| @@ -483,6 +485,11 @@ public class JavaCC extends Task { | |||
| throw new BuildException("unknown task type " + type); | |||
| } | |||
| return packagePrefix + mainClass; | |||
| } finally { | |||
| if (l != null) { | |||
| l.cleanup(); | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| @@ -86,6 +86,7 @@ public class JavahAdapterFactory { | |||
| return new SunJavah(); | |||
| } else if (choice != null) { | |||
| return resolveClassName(choice, | |||
| // Memory leak in line below | |||
| log.getProject() | |||
| .createClassLoader(classpath)); | |||
| } | |||
| @@ -22,6 +22,7 @@ import java.io.File; | |||
| import java.util.Date; | |||
| import java.util.Enumeration; | |||
| import java.util.Vector; | |||
| import org.apache.tools.ant.AntClassLoader; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.DirectoryScanner; | |||
| import org.apache.tools.ant.Project; | |||
| @@ -436,10 +437,12 @@ public class JspC extends MatchingTask { | |||
| File dest = getActualDestDir(); | |||
| AntClassLoader al = null; | |||
| try { | |||
| //bind to a compiler | |||
| JspCompilerAdapter compiler = | |||
| JspCompilerAdapterFactory.getCompiler(compilerName, this, | |||
| getProject().createClassLoader(compilerClasspath)); | |||
| al = getProject().createClassLoader(compilerClasspath)); | |||
| //if we are a webapp, hand off to the compiler, which had better handle it | |||
| if (webApp != null) { | |||
| @@ -503,6 +506,11 @@ public class JspC extends MatchingTask { | |||
| log("all files are up to date", Project.MSG_VERBOSE); | |||
| } | |||
| } | |||
| } finally { | |||
| if (al != null) { | |||
| al.cleanup(); | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| @@ -54,6 +54,7 @@ public final class JspCompilerAdapterFactory { | |||
| public static JspCompilerAdapter getCompiler(String compilerType, Task task) | |||
| throws BuildException { | |||
| return getCompiler(compilerType, task, | |||
| // Memory-Leak in line below | |||
| task.getProject().createClassLoader(null)); | |||
| } | |||
| @@ -1108,7 +1108,9 @@ public class JUnitTask extends Task { | |||
| if (!cmd.haveClasspath()) { | |||
| return; | |||
| } | |||
| AntClassLoader loader = AntClassLoader.newAntClassLoader(null, | |||
| AntClassLoader loader = null; | |||
| try { | |||
| loader = AntClassLoader.newAntClassLoader(null, | |||
| getProject(), cmd.createClasspath(getProject()), | |||
| true); | |||
| String projectResourceName = LoaderUtils.classNameToResource( | |||
| @@ -1131,6 +1133,11 @@ public class JUnitTask extends Task { | |||
| } catch (Exception ex) { | |||
| // Ignore exception | |||
| } | |||
| } finally { | |||
| if (loader != null) { | |||
| loader.cleanup(); | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| @@ -86,6 +86,7 @@ public class Native2AsciiAdapterFactory { | |||
| return new SunNative2Ascii(); | |||
| } else if (choice != null) { | |||
| return resolveClassName(choice, | |||
| // Memory leak in line below | |||
| log.getProject() | |||
| .createClassLoader(classpath)); | |||
| } | |||
| @@ -118,6 +118,7 @@ public final class RmicAdapterFactory { | |||
| } | |||
| //no match? ask for the non-lower-cased type | |||
| return resolveClassName(rmicType, | |||
| // Memory leak in line below | |||
| task.getProject().createClassLoader(classpath)); | |||
| } | |||
| @@ -261,6 +261,7 @@ public class Mapper extends DataType implements Cloneable { | |||
| ClassLoader loader = (classpath == null) | |||
| ? getClass().getClassLoader() | |||
| // Memory leak in line below | |||
| : getProject().createClassLoader(classpath); | |||
| return Class.forName(cName, true, loader); | |||
| @@ -500,7 +500,7 @@ public class XMLCatalog extends DataType | |||
| if (catalogResolver == null) { | |||
| AntClassLoader loader = null; | |||
| // Memory-Leak in line below | |||
| loader = getProject().createClassLoader(Path.systemClasspath); | |||
| try { | |||
| @@ -65,6 +65,7 @@ public class ExtendSelector extends BaseSelector { | |||
| if (classpath == null) { | |||
| c = Class.forName(classname); | |||
| } else { | |||
| // Memory-Leak in line below | |||
| AntClassLoader al | |||
| = getProject().createClassLoader(classpath); | |||
| c = Class.forName(classname, true, al); | |||
| @@ -646,6 +646,7 @@ public class ModifiedSelector extends BaseExtendSelector | |||
| // the usual classloader | |||
| ? getClass().getClassLoader() | |||
| // additional use the provided classpath | |||
| // Memory leak in line below | |||
| : getProject().createClassLoader(classpath); | |||
| } | |||
| return myClassLoader; | |||