Ask the BuildEvent for further information ...

Jan


---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<----
import org.apache.tools.ant.BuildListener;
import org.apache.tools.ant.BuildEvent;
import java.io.*;

public class BuildFailedListener implements BuildListener {

    // Implementation of BuildListener methods

    public void buildStarted(BuildEvent event) {}
    public void buildFinished(BuildEvent event) {
        // this is the only one we really need
        if (event.getException() == null) {
            buildSuccess(event);
        } else {
            buildFailed(event);
        }
    }
    public void targetStarted(BuildEvent event) {}
    public void targetFinished(BuildEvent event) {}
    public void taskStarted(BuildEvent event) {}
    public void taskFinished(BuildEvent event) {}
    public void messageLogged(BuildEvent event) {}
    
    // The "business" events
    
    public void buildSuccess(BuildEvent event) {
        log("Build Success");
    }
    public void buildFailed(BuildEvent event) {
        log("Build failed with '" + event.getException().getMessage() + "'");
    }
    
    // Log a message direct to disk 
    
    private String logFileName = "log.txt";
    private BufferedWriter writer = null;
    private BufferedWriter getOut() throws IOException {
        if (writer == null) {
            writer = new BufferedWriter(new FileWriter(logFileName, true));
        }
        return writer;
    }
    
    private void log(String message) {
        try {
            getOut().write(message);
            getOut().newLine();
            getOut().flush();
        } catch (IOException ioe) {
        }
    }

}
---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<----
 

>-----Ursprüngliche Nachricht-----
>Von: James Carr [mailto:[EMAIL PROTECTED] 
>Gesendet: Freitag, 12. Januar 2007 16:36
>An: Ant Users List
>Betreff: Re: On fail listener?
>
>I dont see any build event associated with build failures
>
>Thanks,
>James
>
>
>On 1/11/07, [EMAIL PROTECTED] 
><[EMAIL PROTECTED]> wrote:
>> Using custom BuildListeners.
>>
>> http://ant.apache.org/manual/listeners.html
>> http://ant.apache.org/manual/develop.html#buildevents
>> 
>http://svn.apache.org/repos/asf/ant/core/trunk/src/main/org/apache/too
>> ls/ant/BuildListener.java
>>
>>
>> Jan
>>
>>
>> >-----Ursprüngliche Nachricht-----
>> >Von: James Carr [mailto:[EMAIL PROTECTED]
>> >Gesendet: Donnerstag, 11. Januar 2007 03:35
>> >An: Ant Users List
>> >Betreff: On fail listener?
>> >
>> >Is there a way to attach a callback that is called when a build 
>> >fails, or even just ends, from within a custom task?
>> >
>> >Thanks,
>> >james
>> >
>> 
>>---------------------------------------------------------------------
>> >To unsubscribe, e-mail: [EMAIL PROTECTED] For 
>> >additional commands, e-mail: [EMAIL PROTECTED]
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED] For 
>additional 
>> commands, e-mail: [EMAIL PROTECTED]
>>
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED] For 
>additional commands, e-mail: [EMAIL PROTECTED]
>
>

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

Reply via email to