4.16. Measurement: Ant build invocations

An interesting event in software development is the occurrence of a system build. For example, many projects incorporate a "daily build" procedure in which the entire system is built and tested once a day. In projects where running the complete set of test cases takes too long to be practical for individual developers, this provides a way of ensuring that the changes made by muliple developers integrate together without failure. Monitoring the frequency with which the build fails and looking for deviations from the baseline can provide useful insight. For example, increases in the daily build failure rate can reveal a degradation in the software development process.

Hackystat supports automated collection of Ant build invocations with an Ant sensor that implements a listener on the build process.

4.16.1. Ant tool installation

This subsection is included for consistency with the other sections in this chapter. Obviously, you've already installed Ant--you've been invoking it as part of every other section in this chapter!

4.16.2. The ant.build.xml file

Example 4.36, “ant.build.xml” shows the ant.build.xml file, which defines the Ant target used to invoke the Ant sensor. This target must be invoked in any build execution that wishes to have its results sent to the Hackystat server.

Example 4.36. ant.build.xml

<project name="stackyhack.ant" default="ant.sensor">
  <description>
  Provides the Ant Build sensor to the StackyHack system.
  </description>

  <import file="build.xml"/>

  <target name="ant.sensor" description="Incorporates the Ant build sensor into this run of the Ant build system.">
    <!-- Fail this target if Ant Build sensor is not installed. -->
    <available classname="org.hackystat.sensor.ant.BuildSensorInstallationAntTask" property="ant.sensor.available"/>
    <fail unless="ant.sensor.available" message="Error: Ant Sensor not installed."/>

    <!-- Now incorporate the Ant Build sensor into this run. -->
    <taskdef name="hacky-build" classname="org.hackystat.sensor.ant.BuildSensorInstallationAntTask" />
    <hacky-build verbose="${hackystat.verbose.mode}" />    
  </target>

</project>

The ant.build.xml file defines the <ant.sensor> target to obtain and send information about the current build to the Hackystat server. The ant.sensor target should be invoked as the initial target in any build.

4.16.3. Running the Ant sensor to send build data to Hackystat

Each time Ant is invoked to build the system, the Ant sensor can be used to capture data about that build and send it off to the Hackystat server.

To accomplish this, you must first install the Ant sensor. General instructions on installing sensors are provided in Chapter 2, Client-side configuration: Tool sensor installation; instructions for specific sensors are provided in Chapter 26, Sensors. After installation, your hackyInstaller Ant configuration window should look something like the screen image in Figure 4.24, “ HackyInstaller configuration screen for Ant sensor ”.

Figure 4.24.  HackyInstaller configuration screen for Ant sensor


HackyInstaller configuration screen for Ant sensor

Example 4.37, “ant.sensor invocation” illustrates the invocation of the Ant sensor.

Example 4.37. ant.sensor invocation

C:\svn-csdl\StackyHack>ant -f ant.build.xml ant.sensor compile
Buildfile: ant.build.xml

ant.sensor:
[hacky-build] Build sensor ant listener installed.

compile:

BUILD SUCCESSFUL
Total time: 3 seconds
Build Sensor Report:
  Start Time = Thu May 18 15:47:58 CEST 2006
  End Time = Thu May 18 15:47:59 CEST 2006
  Configuration = Unknown
  Start Type = Unknown
  Last Target = compile
  Build Location = C:\svn-csdl\StackyHack
  Build Result = Success
  Checkstyle Ran = false
  Compilation Ran = true
  Unittest Ran = false

Sending build result to Hackystat server... Done!

As you can see, invoking the Ant sensor means invoking the <ant.sensor> target, followed by the target you are actually interested in executing in order to build the system. In this case, we're interested in compiling the system. In general, you would normally make all targets depend (either implicitly or explicitly) on the ant.sensor target, so that you don't have to include it explicitly when invoking Ant.

Once you've built your system with the Ant sensor enabled, you can verify that this data was received at the server by using the List Sensor Data command. Figure 4.25, “ List Sensor Data with StackyHack Build data ” illustrates what this page might look like after receiving the StackyHack data.

Figure 4.25.  List Sensor Data with StackyHack Build data


List Sensor Data with StackyHack Build data

As you can see, the last line shows the build data for the "compile" target that was invoked above. The other build data for this day shows the times that I built the docbook documentation for this chapter!