torsdag 9 april 2009

Pain Threshold

Finally the pain got too much. Once again I'd committed broken code into our Subversion  repository and the build server was glowing an irritating red.

It was a silly mistake and it wasn't the first time I'd made it. I'd run the test suite before committing but hadn't noticed the failing tests. Why? Because from Eclipse  we use ant  to execute maven. And the maven exit code is zero even when a build fails. This means that although maven writes "BUILD FAILURE" to the log, ant has the last word and logs "BUILD SUCCESSFUL".

Once again I'd been fooled by the bottom line and missed the critical text a few lines above it. It really was time to find a remedy for this affliction. It took a little bit of rooting around in the ant documentation but I eventually found a cure I could swallow:


<target name="_execute_maven">
<echo>mvn ${line}</echo>

<exec executable="${mvn}" dir="${execute.basedir}">
<!-- save the log to a property too -->
<redirector outputproperty="test.out"
alwayslog="true" />
<env key="JAVA_HOME" path="${java.home}" />
<env key="MAVEN_OPTS" value="${mvn_opts}" />
<arg line="${line}" />
</exec>

<condition property="fail.status">
<!-- search property for failure text -->
<or>
<contains string="${test.out}"
substring="BUILD FAILURE" />
<contains string="${test.out}"
substring="BUILD ERROR" />
</or>
</condition>

<fail if="fail.status" />
</target>

Why don't we use the maven plugin for eclipse? I don't know the definitive answer to this and it niggles me. The eclipse/maven/ant combination came with the project. A buggy maven plugin I'm told, but I ought to dig into this a bit more.  But so far this niggle hasn't breached my pain threshold.