ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: ant/src/main/org/apache/tools/ant/taskdefs Ant.java Recorder.java RecorderEntry.java
Date Mon, 28 Jun 2004 07:47:06 GMT
bodewig     2004/06/28 00:47:06

  Modified:    .        Tag: ANT_16_BRANCH TODO
               docs/manual Tag: ANT_16_BRANCH develop.html
               src/main/org/apache/tools/ant Tag: ANT_16_BRANCH
                        AntClassLoader.java Project.java
               src/main/org/apache/tools/ant/taskdefs Tag: ANT_16_BRANCH
                        Ant.java Recorder.java RecorderEntry.java
  Added:       src/main/org/apache/tools/ant Tag: ANT_16_BRANCH
                        SubBuildListener.java
  Log:
  Merge fix for 8689 from HEAD
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.3.2.24  +0 -2      ant/Attic/TODO
  
  Index: TODO
  ===================================================================
  RCS file: /home/cvs/ant/Attic/TODO,v
  retrieving revision 1.3.2.23
  retrieving revision 1.3.2.24
  diff -u -r1.3.2.23 -r1.3.2.24
  --- TODO	25 Jun 2004 13:50:16 -0000	1.3.2.23
  +++ TODO	28 Jun 2004 07:47:05 -0000	1.3.2.24
  @@ -7,8 +7,6 @@
   
   * Fix or at least document support for tomcat 5.0 jsp
   
  -* review claimed AntClassLoader memory leak [Stefan]
  -
   * AntClassLoader parent loader [Start thread, Peter]
   
   * delete - do not follow symlinks [Peter, may be dropped for 1.6.2]
  
  
  
  No                   revision
  No                   revision
  1.13.2.6  +16 -0     ant/docs/manual/develop.html
  
  Index: develop.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/develop.html,v
  retrieving revision 1.13.2.5
  retrieving revision 1.13.2.6
  diff -u -r1.13.2.5 -r1.13.2.6
  --- develop.html	23 Jun 2004 06:38:12 -0000	1.13.2.5
  +++ develop.html	28 Jun 2004 07:47:05 -0000	1.13.2.6
  @@ -435,6 +435,22 @@
   <li>Message logged</li>
   </ul>
   
  +<p>If the build file invokes another build file via <a
  +href="CoreTasks/ant.html">&lt;ant&gt;</a> or <a
  +href="CoreTasks/subant.html">&lt;subant&gt;</a> or uses <a
  +href="CoreTasks/antcall.html">&lt;antcall&gt;</a>, you are creating a
  +new Ant "project" that will send target and task level events of its
  +own but never sends build started/finished events.  Ant 1.6.2
  +introduces an extension of the BuildListener interface named
  +SubBuildListener that will receive two new events for</p>
  +<ul>
  +<li>SubBuild started</li>
  +<li>SubBuild finished</li>
  +</ul>
  +<p>If you are interested in those events, all you need to do is to
  +implement the new interface instead of BuildListener (and register the
  +listener, of course).</p>
  +
   <p>
   If you wish to attach a listener from the command line you may use the
   <code>-listener</code> option. For example:</p>
  
  
  
  No                   revision
  No                   revision
  1.76.2.7  +26 -1     ant/src/main/org/apache/tools/ant/AntClassLoader.java
  
  Index: AntClassLoader.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/AntClassLoader.java,v
  retrieving revision 1.76.2.6
  retrieving revision 1.76.2.7
  diff -u -r1.76.2.6 -r1.76.2.7
  --- AntClassLoader.java	20 Apr 2004 13:25:15 -0000	1.76.2.6
  +++ AntClassLoader.java	28 Jun 2004 07:47:05 -0000	1.76.2.7
  @@ -44,7 +44,7 @@
    * class will then use this loader rather than the system class loader.
    *
    */
  -public class AntClassLoader extends ClassLoader implements BuildListener {
  +public class AntClassLoader extends ClassLoader implements SubBuildListener {
   
       private static final FileUtils fileUtils = FileUtils.newFileUtils();
   
  @@ -1217,6 +1217,31 @@
        */
       public void buildFinished(BuildEvent event) {
           cleanup();
  +    }
  +
  +    /**
  +     * Cleans up any resources held by this classloader at the end of
  +     * a subbuild if it has been created for the subbuild's project
  +     * instance.
  +     *
  +     * @param event the buildFinished event
  +     *
  +     * @since Ant 1.6.2
  +     */
  +    public void subBuildFinished(BuildEvent event) {
  +        if (event.getProject() == project) {
  +            cleanup();
  +        }
  +    }
  +
  +    /**
  +     * Empty implementation to satisfy the BuildListener interface.
  +     *
  +     * @param event the buildStarted event
  +     *
  +     * @since Ant 1.6.2
  +     */
  +    public void subBuildStarted(BuildEvent event) {
       }
   
       /**
  
  
  
  1.154.2.10 +38 -1     ant/src/main/org/apache/tools/ant/Project.java
  
  Index: Project.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/Project.java,v
  retrieving revision 1.154.2.9
  retrieving revision 1.154.2.10
  diff -u -r1.154.2.9 -r1.154.2.10
  --- Project.java	20 Apr 2004 22:47:46 -0000	1.154.2.9
  +++ Project.java	28 Jun 2004 07:47:05 -0000	1.154.2.10
  @@ -1797,6 +1797,43 @@
           }
       }
   
  +    /**
  +     * Sends a "subbuild started" event to the build listeners for
  +     * this project.
  +     *
  +     * @since Ant 1.6.2
  +     */
  +    public void fireSubBuildStarted() {
  +        BuildEvent event = new BuildEvent(this);
  +        Iterator iter = listeners.iterator();
  +        while (iter.hasNext()) {
  +            Object listener = iter.next();
  +            if (listener instanceof SubBuildListener) {
  +                ((SubBuildListener) listener).subBuildStarted(event);
  +            }
  +        }
  +    }
  +
  +    /**
  +     * Sends a "subbuild finished" event to the build listeners for
  +     * this project.
  +     * @param exception an exception indicating a reason for a build
  +     *                  failure. May be <code>null</code>, indicating
  +     *                  a successful build.
  +     *
  +     * @since Ant 1.6.2
  +     */
  +    public void fireSubBuildFinished(Throwable exception) {
  +        BuildEvent event = new BuildEvent(this);
  +        event.setException(exception);
  +        Iterator iter = listeners.iterator();
  +        while (iter.hasNext()) {
  +            Object listener = iter.next();
  +            if (listener instanceof SubBuildListener) {
  +                ((SubBuildListener) listener).subBuildFinished(event);
  +            }
  +        }
  +    }
   
       /**
        * Sends a "target started" event to the build listeners for this project.
  
  
  
  No                   revision
  
  Index: Project.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/Project.java,v
  retrieving revision 1.154.2.9
  retrieving revision 1.154.2.10
  diff -u -r1.154.2.9 -r1.154.2.10
  --- Project.java	20 Apr 2004 22:47:46 -0000	1.154.2.9
  +++ Project.java	28 Jun 2004 07:47:05 -0000	1.154.2.10
  @@ -1797,6 +1797,43 @@
           }
       }
   
  +    /**
  +     * Sends a "subbuild started" event to the build listeners for
  +     * this project.
  +     *
  +     * @since Ant 1.6.2
  +     */
  +    public void fireSubBuildStarted() {
  +        BuildEvent event = new BuildEvent(this);
  +        Iterator iter = listeners.iterator();
  +        while (iter.hasNext()) {
  +            Object listener = iter.next();
  +            if (listener instanceof SubBuildListener) {
  +                ((SubBuildListener) listener).subBuildStarted(event);
  +            }
  +        }
  +    }
  +
  +    /**
  +     * Sends a "subbuild finished" event to the build listeners for
  +     * this project.
  +     * @param exception an exception indicating a reason for a build
  +     *                  failure. May be <code>null</code>, indicating
  +     *                  a successful build.
  +     *
  +     * @since Ant 1.6.2
  +     */
  +    public void fireSubBuildFinished(Throwable exception) {
  +        BuildEvent event = new BuildEvent(this);
  +        event.setException(exception);
  +        Iterator iter = listeners.iterator();
  +        while (iter.hasNext()) {
  +            Object listener = iter.next();
  +            if (listener instanceof SubBuildListener) {
  +                ((SubBuildListener) listener).subBuildFinished(event);
  +            }
  +        }
  +    }
   
       /**
        * Sends a "target started" event to the build listeners for this project.
  
  
  
  No                   revision
  
  Index: Project.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/Project.java,v
  retrieving revision 1.154.2.9
  retrieving revision 1.154.2.10
  diff -u -r1.154.2.9 -r1.154.2.10
  --- Project.java	20 Apr 2004 22:47:46 -0000	1.154.2.9
  +++ Project.java	28 Jun 2004 07:47:05 -0000	1.154.2.10
  @@ -1797,6 +1797,43 @@
           }
       }
   
  +    /**
  +     * Sends a "subbuild started" event to the build listeners for
  +     * this project.
  +     *
  +     * @since Ant 1.6.2
  +     */
  +    public void fireSubBuildStarted() {
  +        BuildEvent event = new BuildEvent(this);
  +        Iterator iter = listeners.iterator();
  +        while (iter.hasNext()) {
  +            Object listener = iter.next();
  +            if (listener instanceof SubBuildListener) {
  +                ((SubBuildListener) listener).subBuildStarted(event);
  +            }
  +        }
  +    }
  +
  +    /**
  +     * Sends a "subbuild finished" event to the build listeners for
  +     * this project.
  +     * @param exception an exception indicating a reason for a build
  +     *                  failure. May be <code>null</code>, indicating
  +     *                  a successful build.
  +     *
  +     * @since Ant 1.6.2
  +     */
  +    public void fireSubBuildFinished(Throwable exception) {
  +        BuildEvent event = new BuildEvent(this);
  +        event.setException(exception);
  +        Iterator iter = listeners.iterator();
  +        while (iter.hasNext()) {
  +            Object listener = iter.next();
  +            if (listener instanceof SubBuildListener) {
  +                ((SubBuildListener) listener).subBuildFinished(event);
  +            }
  +        }
  +    }
   
       /**
        * Sends a "target started" event to the build listeners for this project.
  
  
  
  1.1.2.1   +0 -0      ant/src/main/org/apache/tools/ant/SubBuildListener.java
  
  Index: SubBuildListener.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/SubBuildListener.java,v
  retrieving revision 1.1
  retrieving revision 1.1.2.1
  diff -u -r1.1 -r1.1.2.1
  
  
  
  No                   revision
  No                   revision
  1.92.2.8  +18 -7     ant/src/main/org/apache/tools/ant/taskdefs/Ant.java
  
  Index: Ant.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Ant.java,v
  retrieving revision 1.92.2.7
  retrieving revision 1.92.2.8
  diff -u -r1.92.2.7 -r1.92.2.8
  --- Ant.java	8 Apr 2004 14:59:52 -0000	1.92.2.7
  +++ Ant.java	28 Jun 2004 07:47:06 -0000	1.92.2.8
  @@ -24,6 +24,7 @@
   import java.lang.reflect.Method;
   import java.util.Enumeration;
   import java.util.Hashtable;
  +import java.util.Iterator;
   import java.util.Vector;
   import java.util.Set;
   import java.util.HashSet;
  @@ -148,10 +149,9 @@
       private void initializeProject() {
           newProject.setInputHandler(getProject().getInputHandler());
   
  -        Vector listeners = getProject().getBuildListeners();
  -        final int count = listeners.size();
  -        for (int i = 0; i < count; i++) {
  -            newProject.addBuildListener((BuildListener) listeners.elementAt(i));
  +        Iterator iter = getBuildListeners();
  +        while (iter.hasNext()) {
  +            newProject.addBuildListener((BuildListener) iter.next());
           }
   
           if (output != null) {
  @@ -379,14 +379,18 @@
               addReferences();
   
               if (target != null && !"".equals(target)) {
  +                Throwable t = null;
                   try {
                       log("Entering " + antFile + "...", Project.MSG_VERBOSE);
  +                    newProject.fireSubBuildStarted();
                       newProject.executeTarget(target);
                   } catch (BuildException ex) {
  -                    throw ProjectHelper.addLocationToBuildException(
  -                        ex, getLocation());
  -              } finally {
  +                    t = ProjectHelper
  +                        .addLocationToBuildException(ex, getLocation());
  +                    throw (BuildException) t;
  +                } finally {
                       log("Exiting " + antFile + ".", Project.MSG_VERBOSE);
  +                    newProject.fireSubBuildFinished(t);
                   }
               }
           } finally {
  @@ -645,6 +649,13 @@
        */
       public void addPropertyset(PropertySet ps) {
           propertySets.addElement(ps);
  +    }
  +
  +    /**
  +     * @since Ant 1.6.2
  +     */
  +    private Iterator getBuildListeners() {
  +        return getProject().getBuildListeners().iterator();
       }
   
       /**
  
  
  
  1.16.2.5  +1 -1      ant/src/main/org/apache/tools/ant/taskdefs/Recorder.java
  
  Index: Recorder.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Recorder.java,v
  retrieving revision 1.16.2.4
  retrieving revision 1.16.2.5
  diff -u -r1.16.2.4 -r1.16.2.5
  --- Recorder.java	9 Mar 2004 17:01:34 -0000	1.16.2.4
  +++ Recorder.java	28 Jun 2004 07:47:06 -0000	1.16.2.5
  @@ -211,7 +211,7 @@
                   throw new BuildException("Problems creating a recorder entry",
                       ioe);
               }
  -            proj.addBuildListener(entry);
  +            entry.setProject(proj);
               recorderEntries.put(name, entry);
           } else {
               entry = (RecorderEntry) o;
  
  
  
  1.11.2.6  +56 -3     ant/src/main/org/apache/tools/ant/taskdefs/RecorderEntry.java
  
  Index: RecorderEntry.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/RecorderEntry.java,v
  retrieving revision 1.11.2.5
  retrieving revision 1.11.2.6
  diff -u -r1.11.2.5 -r1.11.2.6
  --- RecorderEntry.java	9 Mar 2004 17:01:34 -0000	1.11.2.5
  +++ RecorderEntry.java	28 Jun 2004 07:47:06 -0000	1.11.2.6
  @@ -21,6 +21,7 @@
   import org.apache.tools.ant.BuildLogger;
   import org.apache.tools.ant.DefaultLogger;
   import org.apache.tools.ant.Project;
  +import org.apache.tools.ant.SubBuildListener;
   import org.apache.tools.ant.util.StringUtils;
   
   /**
  @@ -30,7 +31,7 @@
    * @version 0.5
    * @since Ant 1.4
    */
  -public class RecorderEntry implements BuildLogger {
  +public class RecorderEntry implements BuildLogger, SubBuildListener {
   
       //////////////////////////////////////////////////////////////////////
       // ATTRIBUTES
  @@ -47,6 +48,8 @@
       private long targetStartTime = 0L;
       /** Strip task banners if true.  */
       private boolean emacsMode = false;
  +    /** project instance the recorder is associated with */
  +    private Project project;
   
       //////////////////////////////////////////////////////////////////////
       // CONSTRUCTORS / INITIALIZERS
  @@ -99,8 +102,32 @@
                    + StringUtils.LINE_SEP);
               error.printStackTrace(out);
           }
  -        out.flush();
  -        out.close();
  +        cleanup();
  +    }
  +
  +    /**
  +     * Cleans up any resources held by this recorder entry at the end
  +     * of a subbuild if it has been created for the subbuild's project
  +     * instance.
  +     *
  +     * @param event the buildFinished event
  +     *
  +     * @since Ant 1.6.2
  +     */
  +    public void subBuildFinished(BuildEvent event) {
  +        if (event.getProject() == project) {
  +            cleanup();
  +        }
  +    }
  +
  +    /**
  +     * Empty implementation to satisfy the BuildListener interface.
  +     *
  +     * @param event the buildStarted event
  +     *
  +     * @since Ant 1.6.2
  +     */
  +    public void subBuildStarted(BuildEvent event) {
       }
   
   
  @@ -207,6 +234,32 @@
                    + (seconds % 60 == 1 ? "" : "s");
           }
   
  +    }
  +
  +    /**
  +     * Set the project associated with this recorder entry.
  +     *
  +     * @param project the project instance
  +     *
  +     * @since 1.6.2
  +     */
  +    public void setProject(Project project) {
  +        this.project = project;
  +        if (project != null) {
  +            project.addBuildListener(this);
  +        }
  +    }
  +
  +    /**
  +     * @since 1.6.2
  +     */
  +    public void cleanup() {
  +        out.flush();
  +        out.close();
  +        if (project != null) {
  +            project.removeBuildListener(this);
  +        }
  +        project = null;
       }
   }
   
  
  
  

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


Mime
View raw message