From 07736d7ee1669883169c7a10b0060e7b0afa315f Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 11 Jul 2001 09:58:09 +0000 Subject: [PATCH] help the garbage collector by cleaning out references in AntClassLoader and IntrospectionHelper after the build has finished. This helps applications that run Ant in the same VM over and over again like CruiseControl or wrappers that run Ant in incremental mode. PR: 2568 Submitted by: robert.watkins@qsipayments.com (Robert Watkins) git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269316 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/AntClassLoader.java | 25 ++++++++++++++++++- .../apache/tools/ant/IntrospectionHelper.java | 18 ++++++++++++- .../org/apache/tools/ant/ProjectHelper.java | 2 ++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/main/org/apache/tools/ant/AntClassLoader.java b/src/main/org/apache/tools/ant/AntClassLoader.java index 2748865ae..f9dc88dd6 100644 --- a/src/main/org/apache/tools/ant/AntClassLoader.java +++ b/src/main/org/apache/tools/ant/AntClassLoader.java @@ -70,7 +70,7 @@ import org.apache.tools.ant.types.Path; * @author Conor MacNeill * @author Jesse Glick */ -public class AntClassLoader extends ClassLoader { +public class AntClassLoader extends ClassLoader implements BuildListener { /** * An enumeration of all resources of a given name found within the @@ -228,6 +228,7 @@ public class AntClassLoader extends ClassLoader { */ public AntClassLoader(Project project, Path classpath) { this.project = project; + this.project.addBuildListener(this); this.classpath = classpath.concatSystemClasspath("ignore"); } @@ -839,4 +840,26 @@ public class AntClassLoader extends ClassLoader { return base.loadClass(name); } } + + public void buildStarted(BuildEvent event) {} + + public void buildFinished(BuildEvent event) { + classpath = null; + project = null; + } + + public void targetStarted(BuildEvent event) { + } + + public void targetFinished(BuildEvent event) { + } + + public void taskStarted(BuildEvent event) { + } + + public void taskFinished(BuildEvent event) { + } + + public void messageLogged(BuildEvent event) { + } } diff --git a/src/main/org/apache/tools/ant/IntrospectionHelper.java b/src/main/org/apache/tools/ant/IntrospectionHelper.java index bc99c4a4f..5a3dfd0bb 100644 --- a/src/main/org/apache/tools/ant/IntrospectionHelper.java +++ b/src/main/org/apache/tools/ant/IntrospectionHelper.java @@ -68,7 +68,7 @@ import java.util.*; * * @author Stefan Bodewig */ -public class IntrospectionHelper { +public class IntrospectionHelper implements BuildListener { /** * holds the types of the attributes that could be set. @@ -552,4 +552,20 @@ public class IntrospectionHelper { throws InvocationTargetException, IllegalAccessException, BuildException; } + + public void buildStarted(BuildEvent event) {} + public void buildFinished(BuildEvent event) { + attributeTypes.clear(); + attributeSetters.clear(); + nestedTypes.clear(); + nestedCreators.clear(); + addText = null; + helpers.clear(); + } + + public void targetStarted(BuildEvent event) {} + public void targetFinished(BuildEvent event) {} + public void taskStarted(BuildEvent event) {} + public void taskFinished(BuildEvent event) {} + public void messageLogged(BuildEvent event) {} } diff --git a/src/main/org/apache/tools/ant/ProjectHelper.java b/src/main/org/apache/tools/ant/ProjectHelper.java index 02ecdfba6..62bfb2b50 100644 --- a/src/main/org/apache/tools/ant/ProjectHelper.java +++ b/src/main/org/apache/tools/ant/ProjectHelper.java @@ -628,6 +628,8 @@ public class ProjectHelper { IntrospectionHelper ih = IntrospectionHelper.getHelper(target.getClass()); + project.addBuildListener(ih); + for (int i = 0; i < attrs.getLength(); i++) { // reflect these into the target String value=replaceProperties(project, attrs.getValue(i),