ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 39671] New: - BuildListener
Date Sun, 28 May 2006 10:03:04 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=39671>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=39671

           Summary: BuildListener
           Product: Ant
           Version: 1.6.5
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Core
        AssignedTo: dev@ant.apache.org
        ReportedBy: philippe26@wanadoo.fr


I would like to dynamically modifiy a <junit> target.
For this i implement a buil listener.
The following code does not work.

public class AntListener implements BuildListener
  {
[...]

  public AntListener()
    {
    }

[...]

  public void taskStarted(BuildEvent event)
    {
    Task task = (Task) event.getSource();
    if (task instanceof UnknownElement)
      {
      taskStarted(((UnknownElement) task).getTask(), event);
      }
    }

  private void taskStarted(Task task, BuildEvent event)
    {
    if (task instanceof JUnitTask)  >>>>>>>>>>>>>>>>
I NEVER SEE THE JunitTask 
      {
      taskStarted((JUnitTask) task, event);
      }
    }

  private void taskStarted(JUnitTask task, BuildEvent event)
    {
    [...] // some processing here
    }
  }


And i think its because in package org.apache.tools.ant.Target,
builder listeners are not notified in the right place. See below:

-----------------------------------------------------------------------
current code
-------------------------------------------------------------------------

    /**
     * Performs this task if it's still valid, or gets a replacement
     * version and performs that otherwise.
     *
     * Performing a task consists of firing a task started event,
     * configuring the task, executing it, and then firing task finished
     * event. If a runtime exception is thrown, the task finished event
     * is still fired, but with the exception as the cause.
     */
    public final void perform() {
        if (!invalid) {
            getProject().fireTaskStarted(this);   >>>>>>>>>>>>
EVENT FIRED BUT
JUNIT TASK IS NOT BUILT
            Throwable reason = null;
            try {
                maybeConfigure(); 		  >>>>>>>>>>>> JUNIT
TASK IS BUILT HERE
                execute();
            } catch (BuildException ex) {
                if (ex.getLocation() == Location.UNKNOWN_LOCATION) {
                    ex.setLocation(getLocation());
                }
                reason = ex;
                throw ex;
            } catch (Exception ex) {
                reason = ex;
                BuildException be = new BuildException(ex);
                be.setLocation(getLocation());
                throw be;
            } catch (Error ex) {
                reason = ex;
                throw ex;
            } finally {
                getProject().fireTaskFinished(this, reason);
            }
        } else {
            UnknownElement ue = getReplacement();
            Task task = ue.getTask();
            task.perform();
        }
    }

------------------------------------------------------------------------------
BUGFIX
------------------------------------------------------------------------------

    /**
     * Performs this task if it's still valid, or gets a replacement
     * version and performs that otherwise.
     *
     * Performing a task consists of firing a task started event,
     * configuring the task, executing it, and then firing task finished
     * event. If a runtime exception is thrown, the task finished event
     * is still fired, but with the exception as the cause.
     */
    public final void perform() {
        if (!invalid) {
            Throwable reason = null;
            try {
                maybeConfigure(); 		      >>>>>>>>>>>>
JUNIT TASK IS BUILT HERE
                getProject().fireTaskStarted(this);   >>>>>>>>>>>>
EVENT FIRED
BUT JUNIT TASK IS BUILT
                execute();
            } catch (BuildException ex) {
                if (ex.getLocation() == Location.UNKNOWN_LOCATION) {
                    ex.setLocation(getLocation());
                }
                reason = ex;
                throw ex;
            } catch (Exception ex) {
                reason = ex;
                BuildException be = new BuildException(ex);
                be.setLocation(getLocation());
                throw be;
            } catch (Error ex) {
                reason = ex;
                throw ex;
            } finally {
                getProject().fireTaskFinished(this, reason);
            }
        } else {
            UnknownElement ue = getReplacement();
            Task task = ue.getTask();
            task.perform();
        }
    }

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

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


Mime
View raw message