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
Date Wed, 10 Apr 2002 09:32:38 GMT
bodewig     02/04/10 02:32:38

  Modified:    src/main/org/apache/tools/ant/taskdefs Ant.java
  Log:
  Bug 7552 auditing of <ant> - antFile, dir and target need to be reset
  at the end of execute to get back to the state before execute has been
  called.
  
  Add some documentation while I was at it.
  
  Revision  Changes    Path
  1.47      +53 -8     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.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- Ant.java	8 Apr 2002 17:45:41 -0000	1.46
  +++ Ant.java	10 Apr 2002 09:32:38 -0000	1.47
  @@ -97,7 +97,10 @@
       /** 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 */
  +    /** 
  +     * the build.xml file (can be absolute) in this case dir will be
  +     * ignored 
  +     */
       private String antFile = null;
   
       /** the target to call if any */
  @@ -142,13 +145,27 @@
          inheritRefs = value;
       }
   
  +    /**
  +     * Creates a Project instance for the project to call.
  +     */
       public void init() {
           newProject = new Project();
           newProject.setJavaVersionProperty();
           newProject.addTaskDefinition("property",
  -                             (Class)project.getTaskDefinitions().get("property"));
  +                                     (Class) project.getTaskDefinitions()
  +                                             .get("property"));
       }
   
  +    /**
  +     * Called in execute or createProperty of newProject is null.
  +     *
  +     * <p>This can happen if the same instance of this task is run
  +     * twice as newProject is set to null at the end of execute (to
  +     * save memory and help the GC).</p>
  +     *
  +     * <p>Sets all properties that have been defined as nested
  +     * property elements.</p>
  +     */
       private void reinit() {
           init();
           final int count = properties.size();
  @@ -169,6 +186,13 @@
           }
       }
   
  +    /**
  +     * Attaches the build listeners of the current project to the new
  +     * project, configures a possible logfile, transfers task and
  +     * data-type definitions, transfers properties (either all or just
  +     * the ones specified as user properties to the current project,
  +     * depending on inheritall).
  +     */
       private void initializeProject() {
           Vector listeners = project.getBuildListeners();
           final int count = listeners.size();
  @@ -245,6 +269,11 @@
           }
       }
   
  +    /**
  +     * Pass output sent to System.out to the new project.
  +     *
  +     * @since Ant 1.5
  +     */
       protected void handleOutput(String line) {
           if (newProject != null) {
               newProject.demuxOutput(line, false);
  @@ -253,6 +282,11 @@
           }
       }
   
  +    /**
  +     * Pass output sent to System.err to the new project.
  +     *
  +     * @since Ant 1.5
  +     */
       protected void handleErrorOutput(String line) {
           if (newProject != null) {
               newProject.demuxOutput(line, true);
  @@ -265,6 +299,9 @@
        * Do the execution.
        */
       public void execute() throws BuildException {
  +        File savedDir = dir;
  +        String savedAntFile = antFile;
  +        String savedTarget = target;
           try {
               if (newProject == null) {
                   reinit();
  @@ -292,7 +329,6 @@
               File file = FileUtils.newFileUtils().resolveFile(dir, antFile);
               antFile = file.getAbsolutePath();
   
  -
               log("calling target "+(target!=null?target:"[default]")
                       + " in build file "+  antFile.toString(),
                       Project.MSG_VERBOSE);
  @@ -325,6 +361,9 @@
                       //ignore
                   }
               }
  +            dir = savedDir;
  +            antFile = savedAntFile;
  +            target = savedTarget;
           }
       }
   
  @@ -344,7 +383,7 @@
       /**
        * Add the references explicitly defined as nested elements to the
        * new project.  Also copy over all references that don't override
  -     * existing references in the new project if inheritall has been
  +     * existing references in the new project if inheritrefs has been
        * requested.
        */
       private void addReferences() throws BuildException {
  @@ -356,7 +395,8 @@
                   Reference ref = (Reference)e.nextElement();
                   String refid = ref.getRefId();
                   if (refid == null) {
  -                    throw new BuildException("the refid attribute is required for reference
elements");
  +                    throw new BuildException("the refid attribute is required"
  +                                             + " for reference elements");
                   }
                   if (!thisReferences.containsKey(refid)) {
                       log("Parent project doesn't contain any reference '"
  @@ -422,8 +462,8 @@
                   // ignore this if the class being referenced does not have
                   // a set project method.
               } catch(Exception e2) {
  -                String msg = "Error setting new project instance for reference with id
"
  -                    + oldKey;
  +                String msg = "Error setting new project instance for "
  +                    + "reference with id " + oldKey;
                   throw new BuildException(msg, e2, location);
               }
           }
  @@ -431,7 +471,7 @@
       }
   
       /**
  -     * ...
  +     * Set the dir attribute.
        */
       public void setDir(File d) {
           this.dir = d;
  @@ -457,6 +497,11 @@
           this.target = s;
       }
   
  +    /**
  +     * Set the name of a log file.  This will be resolved relative to
  +     * the dir attribute if specified, relative to the current
  +     * project's basedir otherwise.
  +     */
       public void setOutput(String s) {
           this.output = s;
       }
  
  
  

--
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