ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Jan.Mate...@rzf.fin-nrw.de>
Subject AW: On fail listener?
Date Mon, 15 Jan 2007 08:14:25 GMT
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:james.r.carr@gmail.com] 
>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, Jan.Materne@rzf.fin-nrw.de 
><Jan.Materne@rzf.fin-nrw.de> 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:james.r.carr@gmail.com]
>> >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: user-unsubscribe@ant.apache.org For 
>> >additional commands, e-mail: user-help@ant.apache.org
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For 
>additional 
>> commands, e-mail: user-help@ant.apache.org
>>
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For 
>additional commands, e-mail: user-help@ant.apache.org
>
>

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


Mime
View raw message