You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@locus.apache.org on 2000/07/21 16:24:37 UTC

cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Ant.java Property.java

bodewig     00/07/21 07:24:36

  Modified:    src/main/org/apache/tools/ant Project.java
               src/main/org/apache/tools/ant/taskdefs Ant.java
                        Property.java
  Log:
  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 <gl...@ca.ibm.com>
  
  Revision  Changes    Path
  1.32      +1 -1      jakarta-ant/src/main/org/apache/tools/ant/Project.java
  
  Index: Project.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Project.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- Project.java	2000/07/12 11:51:29	1.31
  +++ Project.java	2000/07/21 14:24:35	1.32
  @@ -281,7 +281,7 @@
           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
  
  
  
  1.11      +55 -21    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Ant.java
  
  Index: Ant.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Ant.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Ant.java	2000/07/12 06:36:11	1.10
  +++ Ant.java	2000/07/21 14:24:35	1.11
  @@ -89,6 +89,29 @@
   
       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 @@
               }
           }
   
  -        p1.init();
  -
           Hashtable taskdefs = project.getTaskDefinitions();
           Enumeration et = taskdefs.keys();
           while (et.hasMoreElements()) {
  @@ -128,29 +149,39 @@
        * Do the execution.
        */
       public void execute() throws BuildException {
  -        if( dir==null) dir=".";
  -
  -        p1.setBasedir(dir);
  -        p1.setUserProperty("basedir" , dir);
  +        try {
  +            if (p1 == null) {
  +                reinit();
  +            }
  +        
  +            if( dir==null) 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();
  -        }
  +            initializeProject();
   
  -        if (antFile == null) antFile = dir + "/build.xml";
  +            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));
  +            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 @@
           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 );
  
  
  
  1.9       +8 -0      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Property.java
  
  Index: Property.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Property.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Property.java	2000/07/13 15:23:07	1.8
  +++ Property.java	2000/07/21 14:24:35	1.9
  @@ -95,8 +95,16 @@
           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 {