DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=15561>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=15561

event "build finished" not received in a <antcall>

           Summary: event "build finished" not received in a <antcall>
           Product: Ant
           Version: 1.5
          Platform: Other
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Build Process
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


Hello,

I have got a problem with build listener: I have created a <finally> task to 
perform some "rollback" work when build is badly finished. This tasks 
implements "TaskContainer" interface so it contains some sub-tasks to execute 
on build end and it implements "BuildListener" interface too to receive 
the "finished build" event. The code of this task is relatively simple.
When I use this task in the begin of build, it works good but when I use it in 
a target called by <antcall>, the "finished build" event seems to be never 
received by the task...

Below, the code of this "listener task":

public class Finally
  extends Task
  implements BuildListener, TaskContainer {

  private Vector _subTasks = new Vector();
  private String _buildSuccessProperty = null;

 /**
  * Set attribute "buildSuccessProperty"
  * @param onSuccessful
  */
  public void setBuildSuccessProperty( String buildSuccessProperty ) {
    _buildSuccessProperty = buildSuccessProperty;
  }

 /**
  * Signals that a build has finished.
  * @param event
  */
  public void buildFinished(BuildEvent event) {

trace("buildFinished");

    Throwable e = event.getException();
    if ( e == null ) {
      trace( "build successful." );
      if ( _buildSuccessProperty != null ) {
        // Build has succeeded: set the success property
        super.project.setProperty(_buildSuccessProperty, "true");
        trace( "property ["+_buildSuccessProperty+"] set!" );
      }
    }
    else {
      e.printStackTrace();
      trace( "build failed." );
    }

    for (int i=0 ; i< _subTasks.size() ; i++ ) {
      Task task = (Task) _subTasks.get(i);
      task.execute();
    }
  }

 /**
  * Signals that a build has started.
  * @param event
  */
  public void buildStarted(BuildEvent event) {
  }

 /**
  * Signals a message logging event.
  * @param event
  */
  public void messageLogged(BuildEvent event) {
  }

 /**
  * Signals that a target has finished.
  * @param event
  */
  public void targetFinished(BuildEvent event) {
    trace( "targetFinished" + event.getTarget());
  }

 /**
  * Signals that a target is starting.
  * @param event
  */
  public void targetStarted(BuildEvent event) {
    trace( "targetStarted" + event.getTarget());
  }

 /**
  * Signals that a task has finished.
  * @param event
  */
  public void taskFinished(BuildEvent event) {
    trace( "taskFinished" + event.getTask());
  }

 /**
  * Signals that a task is starting.
  * @param event
  */
  public void taskStarted(BuildEvent event) {
    trace( "taskStarted" + event.getTask());
  }

 /**
  * Task execution.
  * @throws BuildException
  */
  public void execute() throws BuildException {

    getProject().addBuildListener( this );
    trace( "execute: build listener added" );
  }

 /**
  * Adds a task to this task container
  * @param task
  * @see org.apache.tools.ant.TaskContainer
  */
  public void addTask(Task task) {

   _subTasks.add(task);
  }

 /**
  * Trace method.
  * @param message
  */
  public void trace( String message ) {
    getProject().log( this, message, Project.MSG_VERBOSE );
  }

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to