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: [email protected]
        ReportedBy: [EMAIL PROTECTED]


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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to