You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Christian Nerrière <ch...@akazi.com> on 2002/12/19 17:57:59 UTC
"finally" task, listener problem
Hello,
I have got a problem with build listener : I have created a <finally> task to perform some tasks when build is 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 is relatively simple.
When I use this task in the begin of build, it works good but when I use it in the middle of the script (900 code lines), the "finished build" event seems to be never received by the task...
Does someone has an idea about this ?
Thanks.
Christian.
Following, the code of this very complex 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 );
}