ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Ant.java Property.java
Date Wed, 25 Sep 2002 12:38:22 GMT
bodewig     2002/09/25 05:38:22

  Modified:    src/main/org/apache/tools/ant/taskdefs Tag: ANT_15_BRANCH
                        Ant.java Property.java
  Log:
  Merge the patch that is supposed to reduce memory consumption of
  <ant*> from CVS HEAD.
  
  PR: 12499
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.56.2.9  +32 -26    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.56.2.8
  retrieving revision 1.56.2.9
  diff -u -r1.56.2.8 -r1.56.2.9
  --- Ant.java	5 Jul 2002 11:36:08 -0000	1.56.2.8
  +++ Ant.java	25 Sep 2002 12:38:22 -0000	1.56.2.9
  @@ -54,22 +54,22 @@
   
   package org.apache.tools.ant.taskdefs;
   
  -import org.apache.tools.ant.Task;
  -import org.apache.tools.ant.Project;
  -import org.apache.tools.ant.ProjectComponent;
  -import org.apache.tools.ant.BuildListener;
  -import org.apache.tools.ant.DefaultLogger;
  -import org.apache.tools.ant.BuildException;
  -import org.apache.tools.ant.ProjectHelper;
  -import org.apache.tools.ant.util.FileUtils;
   import java.io.File;
  -import java.io.PrintStream;
   import java.io.FileOutputStream;
   import java.io.IOException;
  +import java.io.PrintStream;
   import java.lang.reflect.Method;
  -import java.util.Vector;
  -import java.util.Hashtable;
   import java.util.Enumeration;
  +import java.util.Hashtable;
  +import java.util.Vector;
  +import org.apache.tools.ant.BuildException;
  +import org.apache.tools.ant.BuildListener;
  +import org.apache.tools.ant.DefaultLogger;
  +import org.apache.tools.ant.Project;
  +import org.apache.tools.ant.ProjectComponent;
  +import org.apache.tools.ant.ProjectHelper;
  +import org.apache.tools.ant.Task;
  +import org.apache.tools.ant.util.FileUtils;
   
   /**
    * Build a sub-project.
  @@ -99,9 +99,9 @@
       /** the basedir where is executed the build file */
       private File dir = null;
   
  -    /** 
  +    /**
        * the build.xml file (can be absolute) in this case dir will be
  -     * ignored 
  +     * ignored
        */
       private String antFile = null;
   
  @@ -152,7 +152,7 @@
           newProject = new Project();
           newProject.setJavaVersionProperty();
           newProject.addTaskDefinition("property",
  -                                     (Class) project.getTaskDefinitions()
  +                                     (Class) getProject().getTaskDefinitions()
                                                .get("property"));
       }
   
  @@ -208,7 +208,7 @@
       private void initializeProject() {
           newProject.setInputHandler(getProject().getInputHandler());
   
  -        Vector listeners = project.getBuildListeners();
  +        Vector listeners = getProject().getBuildListeners();
           final int count = listeners.size();
           for (int i = 0; i < count; i++) {
               newProject.addBuildListener((BuildListener) listeners.elementAt(i));
  @@ -233,7 +233,7 @@
               }
           }
   
  -        Hashtable taskdefs = project.getTaskDefinitions();
  +        Hashtable taskdefs = getProject().getTaskDefinitions();
           Enumeration et = taskdefs.keys();
           while (et.hasMoreElements()) {
               String taskName = (String) et.nextElement();
  @@ -245,7 +245,7 @@
               newProject.addTaskDefinition(taskName, taskClass);
           }
   
  -        Hashtable typedefs = project.getDataTypeDefinitions();
  +        Hashtable typedefs = getProject().getDataTypeDefinitions();
           Enumeration e = typedefs.keys();
           while (e.hasMoreElements()) {
               String typeName = (String) e.nextElement();
  @@ -322,7 +322,7 @@
               }
   
               if ((dir == null) && (inheritAll)) {
  -                dir = project.getBaseDir();
  +                dir = getProject().getBaseDir();
               }
   
               initializeProject();
  @@ -330,11 +330,11 @@
               if (dir != null) {
                   newProject.setBaseDir(dir);
                   if (savedDir != null) { // has been set explicitly
  -                    newProject.setInheritedProperty("basedir" , 
  +                    newProject.setInheritedProperty("basedir" ,
                                                       dir.getAbsolutePath());
                   }
               } else {
  -                dir = project.getBaseDir();
  +                dir = getProject().getBaseDir();
               }
   
               overrideProperties();
  @@ -372,6 +372,12 @@
           } finally {
               // help the gc
               newProject = null;
  +            Enumeration enum = properties.elements();
  +            while (enum.hasMoreElements()) {
  +                Property p = (Property) enum.nextElement();
  +                p.setProject(null);
  +            }
  +
               if (output != null && out != null) {
                   try {
                       out.close();
  @@ -406,7 +412,7 @@
        * requested.
        */
       private void addReferences() throws BuildException {
  -        Hashtable thisReferences = (Hashtable) project.getReferences().clone();
  +        Hashtable thisReferences = (Hashtable) getProject().getReferences().clone();
           Hashtable newReferences = newProject.getReferences();
           Enumeration e;
           if (references.size() > 0) {
  @@ -455,7 +461,7 @@
        * keep our fingers crossed.</p>
        */
       private void copyReference(String oldKey, String newKey) {
  -        Object orig = project.getReference(oldKey);
  +        Object orig = getProject().getReference(oldKey);
           Class c = orig.getClass();
           Object copy = orig;
           try {
  @@ -483,7 +489,7 @@
               } catch (Exception e2) {
                   String msg = "Error setting new project instance for "
                       + "reference with id " + oldKey;
  -                throw new BuildException(msg, e2, location);
  +                throw new BuildException(msg, e2, getLocation());
               }
           }
           newProject.addReference(newKey, copy);
  @@ -570,10 +576,10 @@
            * Set the id that this reference to be stored under in the
            * new project.
            *
  -         * @param targetid the id under which this reference will be passed to 
  -         *        the new project */ 
  +         * @param targetid the id under which this reference will be passed to
  +         *        the new project */
           public void setToRefid(String targetid) {
  -            this.targetid = targetid; 
  +            this.targetid = targetid;
           }
   
           /**
  
  
  
  1.48.2.7  +39 -40    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.48.2.6
  retrieving revision 1.48.2.7
  diff -u -r1.48.2.6 -r1.48.2.7
  --- Property.java	31 Jul 2002 06:43:10 -0000	1.48.2.6
  +++ Property.java	25 Sep 2002 12:38:22 -0000	1.48.2.7
  @@ -73,7 +73,7 @@
    * Sets a property by name, or set of properties (from file or
    * resource) in the project.  </p>
    * Properties are immutable: whoever sets a property first freezes it for the
  - * rest of the build; they are most definately not variable. 
  + * rest of the build; they are most definately not variable.
    * <p>There are five ways to set properties:</p>
    * <ul>
    *   <li>By supplying both the <i>name</i> and <i>value</i>
attribute.</li>
  @@ -162,12 +162,10 @@
        * Sets the value of the property.
        * @param value value to assign
        */
  -    
       public void setValue(String value) {
           this.value = value;
       }
   
  -    
       public String getValue() {
           return value;
       }
  @@ -183,10 +181,10 @@
       public File getFile() {
           return file;
       }
  -    
  +
       /**
        * Prefix to apply to properties loaded using <code>file</code>
  -     * or <code>resource</code>. 
  +     * or <code>resource</code>.
        * A "." is appended to the prefix if not specified.
        * @param prefix prefix string
        * @since Ant 1.5
  @@ -207,10 +205,10 @@
   
       /**
        * Sets a reference to an Ant datatype
  -     * declared elsewhere. 
  +     * declared elsewhere.
        * Only yields reasonable results for references
        * PATH like structures or properties.
  -     * @param ref reference 
  +     * @param ref reference
        */
       public void setRefid(Reference ref) {
           this.ref = ref;
  @@ -233,16 +231,16 @@
       }
   
       /**
  -    * the prefix to use when retrieving environment variables. 
  -    * Thus if you specify environment=&quot;myenv&quot; 
  -    * you will be able to access OS-specific 
  -    * environment variables via property names &quot;myenv.PATH&quot; or 
  -    * &quot;myenv.TERM&quot;. 
  +    * the prefix to use when retrieving environment variables.
  +    * Thus if you specify environment=&quot;myenv&quot;
  +    * you will be able to access OS-specific
  +    * environment variables via property names &quot;myenv.PATH&quot; or
  +    * &quot;myenv.TERM&quot;.
       * <p>
  -    * Note that if you supply a property name with a final 
  -    * &quot;.&quot; it will not be doubled. ie environment=&quot;myenv.&quot;
will still 
  -    * allow access of environment variables through &quot;myenv.PATH&quot; and

  -    * &quot;myenv.TERM&quot;. This functionality is currently only implemented

  +    * Note that if you supply a property name with a final
  +    * &quot;.&quot; it will not be doubled. ie environment=&quot;myenv.&quot;
will still
  +    * allow access of environment variables through &quot;myenv.PATH&quot; and
  +    * &quot;myenv.TERM&quot;. This functionality is currently only implemented
       * on select platforms. Feel free to send patches to increase the number of platforms
       * this functionality is supported on ;).<br>
       * Note also that properties are case sensitive, even if the
  @@ -250,7 +248,6 @@
       * will be ${env.Path} not ${env.PATH} on Windows 2000.
       * @param env prefix
       */
  -
       public void setEnvironment(String env) {
           this.env = env;
       }
  @@ -262,12 +259,10 @@
           return env;
       }
   
  -
       /**
        * The classpath to use when looking up a resource.
  -     * @param classpath to add to any existing classpath 
  +     * @param classpath to add to any existing classpath
        */
  -                        
       public void setClasspath(Path classpath) {
           if (this.classpath == null) {
               this.classpath = classpath;
  @@ -281,7 +276,7 @@
        */
       public Path createClasspath() {
           if (this.classpath == null) {
  -            this.classpath = new Path(project);
  +            this.classpath = new Path(getProject());
           }
           return this.classpath.createPath();
       }
  @@ -304,7 +299,7 @@
       /**
        * @deprecated This was never a supported feature and has been
        * deprecated without replacement
  -     * @ant.setter skip="true" 
  +     * @ant.setter skip="true"
        */
       public void setUserProperty(boolean userProperty) {
           log("DEPRECATED: Ignoring request to set user property in Property"
  @@ -320,28 +315,32 @@
       }
   
       /**
  -     * set the property in the project to the value. 
  +     * set the property in the project to the value.
        * if the task was give a file, resource or env attribute
        * here is where it is loaded
        */
       public void execute() throws BuildException {
  +        if (getProject() == null) {
  +            throw new IllegalStateException("project has not been set");
  +        }
  +
           if (name != null) {
               if (value == null && ref == null) {
                   throw new BuildException("You must specify value, location or "
                                            + "refid with the name attribute",
  -                                         location);
  +                                         getLocation());
               }
           } else {
               if (file == null && resource == null && env == null) {
                   throw new BuildException("You must specify file, resource or "
                                            + "environment when not using the "
  -                                         + "name attribute", location);
  +                                         + "name attribute", getLocation());
               }
           }
  -        
  +
           if (file == null && resource == null && prefix != null) {
               throw new BuildException("Prefix is only valid when loading from "
  -                                     + "a file or resource", location);
  +                                     + "a file or resource", getLocation());
           }
   
           if ((name != null) && (value != null)) {
  @@ -362,16 +361,16 @@
   
           if ((name != null) && (ref != null)) {
               try {
  -                addProperty(name, 
  +                addProperty(name,
                               ref.getReferencedObject(getProject()).toString());
               } catch (BuildException be) {
                   if (fallback != null) {
  -                    addProperty(name, 
  +                    addProperty(name,
                                   ref.getReferencedObject(fallback).toString());
                   } else {
                       throw be;
                   }
  -            }                
  +            }
           }
       }
   
  @@ -398,7 +397,7 @@
                       Project.MSG_VERBOSE);
               }
           } catch (IOException ex) {
  -            throw new BuildException(ex, location);
  +            throw new BuildException(ex, getLocation());
           }
       }
   
  @@ -414,7 +413,7 @@
               ClassLoader cL = null;
   
               if (classpath != null) {
  -                cL = new AntClassLoader(project, classpath);
  +                cL = new AntClassLoader(getProject(), classpath);
               } else {
                   cL = this.getClass().getClassLoader();
               }
  @@ -432,7 +431,7 @@
                   log("Unable to find resource " + name, Project.MSG_WARN);
               }
           } catch (IOException ex) {
  -            throw new BuildException(ex, location);
  +            throw new BuildException(ex, getLocation());
           } finally {
               if (is != null) {
                   try {
  @@ -440,7 +439,7 @@
                   } catch (IOException e) {}
               }
           }
  -        
  +
       }
   
       /**
  @@ -478,7 +477,7 @@
               String name = (String) e.nextElement();
               String value = props.getProperty(name);
   
  -            String v = project.replaceProperties(value);
  +            String v = getProject().replaceProperties(value);
   
               if (prefix != null) {
                   name = prefix + name;
  @@ -495,13 +494,13 @@
        */
       protected void addProperty(String n, String v) {
           if (userProperty) {
  -            if (project.getUserProperty(n) == null) {
  -                project.setInheritedProperty(n, v);
  +            if (getProject().getUserProperty(n) == null) {
  +                getProject().setInheritedProperty(n, v);
               } else {
                   log("Override ignored for " + n, Project.MSG_VERBOSE);
               }
           } else {
  -            project.setNewProperty(n, v);
  +            getProject().setNewProperty(n, v);
           }
       }
   
  @@ -518,7 +517,7 @@
               while (!resolved) {
                   Vector fragments = new Vector();
                   Vector propertyRefs = new Vector();
  -                ProjectHelper.parsePropertyString(value, fragments, 
  +                ProjectHelper.parsePropertyString(value, fragments,
                                                     propertyRefs);
   
                   resolved = true;
  @@ -531,7 +530,7 @@
                           if (fragment == null) {
                               String propertyName = (String) j.nextElement();
                               if (propertyName.equals(name)) {
  -                                throw new BuildException("Property " + name 
  +                                throw new BuildException("Property " + name
                                                            + " was circularly "
                                                            + "defined.");
                               }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message