Browse Source

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
master
Stefan Bodewig 24 years ago
parent
commit
07736d7ee1
3 changed files with 43 additions and 2 deletions
  1. +24
    -1
      src/main/org/apache/tools/ant/AntClassLoader.java
  2. +17
    -1
      src/main/org/apache/tools/ant/IntrospectionHelper.java
  3. +2
    -0
      src/main/org/apache/tools/ant/ProjectHelper.java

+ 24
- 1
src/main/org/apache/tools/ant/AntClassLoader.java View File

@@ -70,7 +70,7 @@ import org.apache.tools.ant.types.Path;
* @author <a href="mailto:conor@cortexebusiness.com.au">Conor MacNeill</a>
* @author <a href="mailto:Jesse.Glick@netbeans.com">Jesse Glick</a>
*/
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) {
}
}

+ 17
- 1
src/main/org/apache/tools/ant/IntrospectionHelper.java View File

@@ -68,7 +68,7 @@ import java.util.*;
*
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/
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) {}
}

+ 2
- 0
src/main/org/apache/tools/ant/ProjectHelper.java View File

@@ -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),


Loading…
Cancel
Save