Browse Source

Modified Ant task to be less memory consuming.

I've modified Glenn's initial patch to defer the copying of taskdefs
as well and save the initial p1.init call - this even makes the ant
task faster.

Should be suited for situations where a single instance of the task is
executed more than once as well.

Submitted by:	Glenn McAllister <glennm@ca.ibm.com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267816 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 25 years ago
parent
commit
12f19c9321
3 changed files with 67 additions and 25 deletions
  1. +1
    -1
      src/main/org/apache/tools/ant/Project.java
  2. +58
    -24
      src/main/org/apache/tools/ant/taskdefs/Ant.java
  3. +8
    -0
      src/main/org/apache/tools/ant/taskdefs/Property.java

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

@@ -281,7 +281,7 @@ public class Project {
return javaVersion;
}

private void detectJavaVersion() {
public void detectJavaVersion() {

// Determine the Java version by looking at available classes
// java.lang.StrictMath was introduced in JDK 1.3


+ 58
- 24
src/main/org/apache/tools/ant/taskdefs/Ant.java View File

@@ -89,6 +89,29 @@ public class Ant extends Task {

public void init() {
p1 = new Project();
p1.detectJavaVersion();
p1.addTaskDefinition("property",
(Class)project.getTaskDefinitions().get("property"));
}

private void reinit() {
init();
for (int i=0; i<properties.size(); i++) {
Property p = (Property) properties.elementAt(i);
Property newP = (Property) p1.createTask("property");
newP.setName(p.getName());
if (p.getValue() != null) {
newP.setValue(p.getValue());
} else if (p.getFile() != null) {
newP.setFile(p.getFile());
} else if (p.getResource() != null) {
newP.setResource(p.getResource());
}
properties.setElementAt(newP, i);
}
}

private void initializeProject() {
Vector listeners = project.getBuildListeners();
for (int i = 0; i < listeners.size(); i++) {
p1.addBuildListener((BuildListener)listeners.elementAt(i));
@@ -104,8 +127,6 @@ public class Ant extends Task {
}
}

p1.init();

Hashtable taskdefs = project.getTaskDefinitions();
Enumeration et = taskdefs.keys();
while (et.hasMoreElements()) {
@@ -128,29 +149,39 @@ public class Ant extends Task {
* Do the execution.
*/
public void execute() throws BuildException {
if( dir==null) dir=".";

p1.setBasedir(dir);
p1.setUserProperty("basedir" , dir);

// Override with local-defined properties
Enumeration e = properties.elements();
while (e.hasMoreElements()) {
Property p=(Property) e.nextElement();
// System.out.println("Setting " + p.getName()+ " " + p.getValue());
p.init();
}

if (antFile == null) antFile = dir + "/build.xml";

p1.setUserProperty( "ant.file" , antFile );
ProjectHelper.configureProject(p1, new File(antFile));
try {
if (p1 == null) {
reinit();
}
if( dir==null) dir=".";

initializeProject();

p1.setBasedir(dir);
p1.setUserProperty("basedir" , dir);
// Override with local-defined properties
Enumeration e = properties.elements();
while (e.hasMoreElements()) {
Property p=(Property) e.nextElement();
p.init();
}
if (antFile == null) antFile = dir + "/build.xml";

p1.setUserProperty( "ant.file" , antFile );
ProjectHelper.configureProject(p1, new File(antFile));
if (target == null) {
target = p1.getDefaultTarget();
}

if (target == null) {
target = p1.getDefaultTarget();
p1.executeTarget(target);
} finally {
// help the gc
p1 = null;
}

p1.executeTarget(target);
}

public void setDir(String d) {
@@ -169,8 +200,11 @@ public class Ant extends Task {
this.output = s;
}

// XXX replace with createProperty!!
public Property createProperty() {
if (p1 == null) {
reinit();
}

Property p=(Property)p1.createTask("property");
p.setUserProperty(true);
properties.addElement( p );


+ 8
- 0
src/main/org/apache/tools/ant/taskdefs/Property.java View File

@@ -95,10 +95,18 @@ public class Property extends Task {
this.file = file;
}

public String getFile() {
return file;
}

public void setResource(String resource) {
this.resource = resource;
}

public String getResource() {
return resource;
}

public void init() throws BuildException {
try {
if ((name != null) && (value != null)) {


Loading…
Cancel
Save