org.sandev.sandbuild
Class SandLogger

java.lang.Object
  extended byorg.apache.tools.ant.DefaultLogger
      extended byorg.sandev.sandbuild.SandLogger
All Implemented Interfaces:
org.apache.tools.ant.BuildListener, org.apache.tools.ant.BuildLogger, java.util.EventListener

public class SandLogger
extends org.apache.tools.ant.DefaultLogger

BuildLogger that fails the build if any warning or error messages are logged. Since failing the build as soon as an error or warning occurs is counterproductive, the logger waits until the end of the build before failing. Error and warning messages are detected by listening for BuildEvent messages with a priority of Project.MSG_ERR or Project.MSG_WARN, respectively.

If this turns out to be insufficient for capturing all warning or error messages, future implementations of this class may include a configurable list of strings to watch for; if any string in the watchlist appears in a build message, that message is considered an error.

While it would be nice if this class were a BuildListener and not a BuildLogger (we could add it to an ant project programmatically), we can't throw the right exception in that case.


Field Summary
protected  java.util.ArrayList errorList
          List of warning/error messages we've seen so far.
 
Fields inherited from class org.apache.tools.ant.DefaultLogger
emacsMode, err, LEFT_COLUMN_SIZE, lSep, msgOutputLevel, out
 
Constructor Summary
SandLogger()
           
 
Method Summary
 void buildFinished(org.apache.tools.ant.BuildEvent event)
          Fail the build if there were any warnings or errors.
protected  java.lang.String getErrors()
          Return a list of the errors + warnings in the build, if any.
 void messageLogged(org.apache.tools.ant.BuildEvent event)
          Trap + record any warnings or errors.
 
Methods inherited from class org.apache.tools.ant.DefaultLogger
buildStarted, formatTime, log, printMessage, setEmacsMode, setErrorPrintStream, setMessageOutputLevel, setOutputPrintStream, targetFinished, targetStarted, taskFinished, taskStarted
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

errorList

protected java.util.ArrayList errorList
List of warning/error messages we've seen so far. If we get a buildFinished build event and this list is empty, there weren't any problems and the build was successful.

Constructor Detail

SandLogger

public SandLogger()
Method Detail

messageLogged

public void messageLogged(org.apache.tools.ant.BuildEvent event)
Trap + record any warnings or errors.

See Also:
DefaultLogger.messageLogged(org.apache.tools.ant.BuildEvent)

buildFinished

public void buildFinished(org.apache.tools.ant.BuildEvent event)
Fail the build if there were any warnings or errors.

See Also:
DefaultLogger.buildFinished(org.apache.tools.ant.BuildEvent)

getErrors

protected java.lang.String getErrors()
Return a list of the errors + warnings in the build, if any. Since builds can potentially have thousands of errors, cap the list at 100 entries.