26.17. JBlanket

26.17.1. Overview

The JBlanket Sensor is an Ant task that sends Java test coverage metrics produced by JBlanket to the Hackystat server. The JBlanket sensor represents this metric data using the Coverage sensor data type, documented in Section 25.8, “Coverage”

Table 26.9, “JBlanket Metrics” lists the coverage data gathered by the JBlanket sensor.

Table 26.9. JBlanket Metrics

MetricDescription
typeThe coverage type, which for JBlanket is method-level coverage.
timestampThe time at which JBlanket was invoked. (Accurate to within a few seconds.)
ClassThe fully qualified name of the class whose coverage is being represented.
Covered MethodsThe number of methods that were invoked during testing.
Uncovered MethodsThe number of methods that were not invoked during testing.

26.17.2. Installation

26.17.2.1. Prerequisites

The JBlanket sensor requires Java 1.5.0 or later, Ant 1.6.5 or later, and JBlanket 4.0 or later. JBlanket usage typically requires some sort of test infrastructure such as JUnit.

26.17.2.2. Install JBlanket

Download JBlanket 4.0 or later from its home page and install into your local environment. Section 4.12, “Measurement: Source code quality with FindBugs” provides a recommended approach to JBlanket installation for use with Hackystat.

26.17.2.3. Download HackyInstaller and set your Hackystat Host and User Key

Follow the instructions in Chapter 2, Client-side configuration: Tool sensor installation to set your Hackystat host and user key.

26.17.2.4. Configure and install the JBlanket sensor

In the HackyInstaller main window, select the JBlanket sensor and press "Configure Selected Sensor". Figure 26.1, “ Ant Build installer configuration window ” shows what the configuration window should look like after the path to Ant is set, the sensor is enabled, and the "Install" button has been pressed to install the sensor.

Figure 26.32.  JBlanket sensor installer configuration window


JBlanket sensor installer configuration window

This sensor supports the following properties and paths:

  • Enable JBlanket Sensor: This property controls whether the sensor is active or not. If not checked, the sensor will not collect or send data even if installed.

  • Ant home directory: This path specifies the top-level directory for Ant. The JBlanket sensor requires the placement of a sensor executable into Ant's lib/ directory.

26.17.2.5. Define Ant targets to run the JBlanket tool and the JBlanket sensor

Example 26.39, “An example JBlanket target” illustrates one possible definition of these targets.

Example 26.39. An example JBlanket target

  <target name="jblanket.tool" depends="clean, compile" 
    description="Cleans, compiles, instruments byte codes, runs unit tests, generates JBlanket report.">
    <!-- Check for the JBLANKET_HOME environment variable, failing the build if it can't be found. -->
    <available file="${env.JBLANKET_HOME}/lib/ant/jblanket.jar" property="jblanket.available"/>
    <fail unless="jblanket.available" message="Error: JBLANKET_HOME not set or jblanket.jar not found, indicating JBlanket is not installed."/>

    <path id="jblanket.libraries" >
      <pathelement location="${env.JBLANKET_HOME}/lib/ant/jblanket.jar" />
      <pathelement location="${env.JBLANKET_HOME}/lib/ant/jdom.jar" />
      <pathelement location="${env.JBLANKET_HOME}/lib/ant/bcel-5.1.jar" />
    </path>

    <taskdef name="jblanket" classname="csdl.jblanket.ant.JBlanketModifierTask" classpathref="jblanket.libraries"/>

    <mkdir dir="${jblanket.dir}"/>
    <jblanket testgrammar="Test*.class" excludeonelinemethods="on" verbose="${hackystat.verbose.mode}">
      <sysproperty key="jblanket.dir" value="${jblanket.dir}" />
      <fileset dir="${build.dir}/classes">
        <include name="**/*.class" />
      </fileset>
    </jblanket>

    <!-- Run unit tests with JBlanket modified code. -->
    <mkdir dir="${junit.dir}"/>
    <junit printsummary="withOutAndErr" fork="yes">
      <classpath> 
        <pathelement path="${java.class.path};${build.dir}/classes" />
        <path refid="jblanket.libraries"/>
      </classpath>
      <sysproperty key="jblanket.dir" value="${jblanket.dir}"/>
      <formatter type="xml" />
      <batchtest todir="${junit.dir}">
        <fileset dir="${src.dir}">
          <include name="**/Test*.java" />
        </fileset>
      </batchtest>
    </junit>

    <!-- Run the jblanket report. -->
    <taskdef name="jblanketreport" classname="csdl.jblanket.ant.JBlanketReportTask" classpathref="jblanket.libraries"/>
    <jblanketreport excludeonelinemethods="on" >
      <sysproperty key="jblanket.dir" value="${jblanket.dir}" />
    </jblanketreport>

    <!-- Now delete the classes/ dir containing the instrumented .class files. -->
    <delete dir="${build.dir}/classes" />
  </target>

  <target name="jblanket.sensor" description="Sends Coverage data to Hackystat using the JBlanket sensor.">
    <!-- Define the jblanket sensor taskdef, failing the build if the sensor is not installed. -->
    <available classname="org.hackystat.sensor.jblanket.JBlanketSensor" property="jblanket.sensor.available"/>
    <fail unless="jblanket.sensor.available" message="Error: JBlanket sensor not installed."/>
    <taskdef name="hacky-jblanket" classname="org.hackystat.sensor.jblanket.JBlanketSensor" />
    
    <!-- Send Coverage data to Hackystat using the JBlanket sensor. --> 
    <hacky-jblanket verbose="${hackystat.verbose.mode}" methodsetsxmlfile="${jblanket.dir}/COVER-MethodSets.xml" />
  </target>

For more details on these targets, see Section 4.8, “Measurement: Test coverage with JBlanket”, which illustrates the installation and use of JBlanket on a sample Java system called StackyHack.

26.17.3. Installation verification

26.17.3.1. Verify verbose mode output

To verify your JBlanket sensor installation, invoke the target and check to see that data is sent to the server. Example 26.40, “Example JBlanket output” shows the shell output from an example run on the Stack system.

Example 26.40. Example JBlanket output

C:\cvs413\Stack>ant jblanket
Buildfile: build.xml

init:

clean:
   [delete] Deleting directory C:\cvs413\Stack\build

checkstyle:

compile:
    [mkdir] Created dir: C:\cvs413\Stack\build\classes
    [javac] Compiling 5 source files to C:\cvs413\Stack\build\classes

jblanket:
 [jblanket] modifying: classes\edu\hawaii\stack\ClearStack.class
 [jblanket] modifying: classes\edu\hawaii\stack\EmptyStackException.class
 [jblanket] modifying: classes\edu\hawaii\stack\Stack.class
 [jblanket] modifying: classes\edu\hawaii\stack\TestClearStack.class
 [jblanket] modifying: classes\edu\hawaii\stack\TestStack.class
 [jblanket] JBlanket modify task completed (0 secs.)

init:

checkstyle:

compile:

junit:
    [mkdir] Created dir: C:\cvs413\Stack\build\junit
    [junit] Running edu.hawaii.stack.TestClearStack
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.27 sec
    [junit] Running edu.hawaii.stack.TestStack
    [junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.32 sec
[junitreport] Transform time: 471ms
     [echo] JUnit results in C:\cvs413\Stack\build\junit/index.html
[hacky-junit] JUnitSensor disabled; no data sent.
[jblanketreport] *******************************************************
[jblanketreport] Method-level Coverage:
[jblanketreport] All methods       : {total=16}
[jblanketreport] One-line methods  : {total=5}
[jblanketreport] Remaining methods : {total=11}
[jblanketreport] Tested methods    : {total=11, percent=100%}
[jblanketreport] Untested methods  : {total=0, percent=0%}
[jblanketreport] *******************************************************
[jblanketreport] JBlanket results in C:\cvs413\Stack\build\jblanket\index.html
[jblanketreport] JBlanket report task completed (0 secs.)
[hacky-jblanket] Processing file: C:\cvs413\Stack\build\jblanket\COVER-MethodSets.xml
[hacky-jblanket] Hackystat data on 5 JBlanket coverage entries sent to http://localhost:8080/ (0 secs.)
   [delete] Deleting directory C:\cvs413\Stack\build\classes

BUILD SUCCESSFUL
Total time: 9 seconds
C:\cvs413\Stack>

26.17.3.2. List Sensor Data

Once you verify that JBlanket data is being sent from the client using verbose mode, login to your account on your Hackystat server, and use the "List Sensor Data" command on the Extras page to verify that Coverage data for today's date was received by the server for the JBlanket tool, as illustrated in Figure 26.33, “ List Sensor Data with JBlanket data ”.

Figure 26.33.  List Sensor Data with JBlanket data


List Sensor Data with JBlanket data

26.17.4. Installation troubleshooting

26.17.4.1. Troubleshooting general client-server problems

The first step in troubleshooting your sensor installation is to verify that your Hackystat host and key settings are valid and that you can contact the Hackystat server, as described in Section 2.4, “HackyInstaller GUI: Setting and verifying the Hackystat host and user key”

26.17.4.2. Checking client-side logging

The JBlanket sensor writes out a file called jblanket.0.log to the .hackystat/logs directory that can be useful in debugging your installation. Under normal conditions, this file should look similar to Example 26.41, “Log file for JBlanket sensor”.

Example 26.41. Log file for JBlanket sensor

Hackystat Version: 6.3.1026 (October 26 2004 08:58:52)
SensorShell started at: 10/27/2004 13:20:31
Type 'help' for a list of commands.
Host: http://hackystat.ics.hawaii.edu/ is available and key is valid.
Defined shell command: Issue
Defined shell command: Perf
Defined shell command: FileMetric
Defined shell command: ReviewIssue
Defined shell command: Activity
Defined shell command: Cli
Defined shell command: ReviewActivity
Defined shell command: Coverage
Defined shell command: BuffTrans
Defined shell command: Commit
Defined shell command: UnitTest
Defined shell command: Build
#> AutoSend [10]
AutoSend OK (set to 10 minutes)
AutoSend enabled every 10 minutes.
Checking for offline data to recover.
No offline data found.
#> Coverage [setTool, JBlanket]
setTool OK
#> Coverage [add, method, 1098919227000, edu.hawaii.stack.ClearStack, 0, 0, ]
Coverage add OK (1 total)
#> Coverage [add, method, 1098919227000, edu.hawaii.stack.EmptyStackException, 1, 0, ]
Coverage add OK (2 total)
#> Coverage [add, method, 1098919227000, edu.hawaii.stack.Stack, 5, 0, ]
Coverage add OK (3 total)
#> Coverage [add, method, 1098919227000, edu.hawaii.stack.TestClearStack, 2, 0, ]
Coverage add OK (4 total)
#> Coverage [add, method, 1098919227000, edu.hawaii.stack.TestStack, 3, 0, ]
Coverage add OK (5 total)
#> send
Sending sensor data (10/27 13:20:32)
  Ping: Ping OK (contacted server http://hackystat.ics.hawaii.edu/ with valid key.)
  AutoSend: AutoSend OK ('send' command ignored)
  Issue: Send OK (No entries to send.)
  Perf: Send OK (No entries to send.)
  FileMetric: Send OK (No entries to send.)
  ReviewIssue: Send OK (No entries to send.)
  Activity: Send OK (No entries to send.)
  Cli: Send OK (No entries to send.)
  ReviewActivity: Send OK (No entries to send.)
  Coverage: Send OK (5 entries)
  BuffTrans: Send OK (No entries to send.)
  Commit: Send OK (No entries to send.)
  UnitTest: Send OK (No entries to send.)
  Build: Send OK (No entries to send.)

26.17.4.3. Submit a trouble report

If none of the above troubleshooting activities solves your problem, then you should send an email to your Hackystat Administrator to request help. Please include in your email the following information:

  • The output from 'java -version'.

  • The output from 'java -jar sensorshell.jar -verify'.

  • The contents of your sensor.properties file.

  • The contents of the jblanket.0.log file.

  • A description of the problem you are having.

26.17.5. Usage tips

26.17.5.1. Integrate JBlanket data collection into your development process

You probably don't want to have to invoke "ant jblanket" manually each time you want coverage data sent to Hackystat. It is better to have the JBlanket coverage data calculated and sent to Hackystat automatically as a natural course of development. One strategy is to make the jblanket target a dependent target of an "install" or "distribution" target so that coverage data is recorded each time significant changes occur to the system. This provides a historical record of the structural evolution that can be later used by Hackystat analyses.

26.17.5.2. Disable verbose mode

Set verbose="off" once things are working correctly.

26.17.6. Uninstallation

To disable JBlanket data collection temporarily, invoke HackyInstaller, bring up the JBlanket configuration window, and uncheck the "Enable JBlanket sensor" property, and apply the setting. To permanently uninstall the JBlanket sensor, press the "Uninstall" button and remove the JBlanket sensor targets from your Ant build.xml files.