4.14. Measurement: Source code issues with Jira

Jira is a tool for management of issues, such as defects, that occur during software development. This section illustrates the use of two Ant tasks to measure the rate of issue creation and change during software development. The first Ant task, called the "Jira Issue Extractor", contacts a Jira server and downloads information about the set of issues associated with a given project into a set of XML files. These files are then processed by the second Ant task, called the "Jira Sensor", which reads in these files and sends Hackystat Issue sensor data to a Hackystat server.

4.14.1. Jira tool installation

Installation of a Jira system is beyond the scope of this section. Please consult the Jira installation guide for details.

4.14.2. The jira.build.xml file

Example 4.31, “jira.build.xml” shows the jira.build.xml file, which defines the Ant targets used to invoke the Jira tool and the Jira sensor.

Example 4.31. jira.build.xml

<project name="stackyhack.jira" default="jira">
  <description>
  Provides an Ant task to extract Issue data from a Jira server, then send this data off to Hackystat.

  Note: when invoking the sensor, you typically want to provide -Djira.default.userkey=[userkey] on the command line.
  </description>

  <import file="build.xml"/>
  <property environment="env"/>
  <property name="jira.dir" location="${build.dir}/jira" />
  <property name="jira.default.userkey" value="unknown"/>

  <target name="jira" depends="jira.tool, jira.sensor" description="Runs the FindBugs tool, report, and sensor."/>

  <target name="jira.tool" description="Extracts jira issues from a Jira server and saves it in XML format.." >
    <!-- Define the jira extractor taskdef, failing the build if the sensor is not installed. -->
    <available classname="org.hackystat.sensor.jira.JiraIssueExtractor" property="jira.extractor.available"/>
    <fail unless="jira.extractor.available" message="Error: Ant Jira Issue Extractor not installed."/>
    <taskdef name="jiraextract" classname="org.hackystat.sensor.jira.JiraIssueExtractor" />

    <mkdir dir="${jira.dir}" />
    <jiraextract outdir="${jira.dir}" 
                 verbose="off" 
                 projectPrefix="STACKYHACK" 
                 pid="10050" 
                 jiraServer="http://hackydev.ics.hawaii.edu:8080/" />
  </target>

  <target name="jira.sensor" description="Send extracted Jira issue data to Hackystat.">
    <!-- Define the jira sensor taskdef, failing the build if the sensor is not installed. -->
    <available classname="org.hackystat.sensor.jira.JiraIssueExtractorSensor" property="jira.sensor.available"/>
    <fail unless="jira.sensor.available" message="Error: Ant Jira Issue Sensor not installed."/>
    <taskdef name="hacky-jira" classname="org.hackystat.sensor.jira.JiraIssueExtractorSensor" />

    <hacky-jira verbose="${hackystat.verbose.mode}" 
                workspaceRoot="${basedir}" 
                defaultUserHackystatAccountKey="${jira.default.userkey}">
      <fileset dir="${jira.dir}" includes="*.xml"/>
    </hacky-jira>
  </target>
</project>

The jira.build.xml defines the <jira.tool> target to send a request to a Jira server to obtain a set of XML files, one for each issue associated with the given Jira project. The <jira.sensor> target reads in these files and sends data about them to the Hackystat server. The <jira> target simply invokes these two targets in sequence.

4.14.3. Running the Jira issue extractor target

The Jira Issue Extractor and the Jira sensor are bundled together in the Jira sensor package. 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 Jira configuration window should look something like the screen image in Figure 4.20, “ HackyInstaller configuration screen for Jira sensor ”.

Figure 4.20.  HackyInstaller configuration screen for Jira sensor


HackyInstaller configuration screen for Jira sensor

Example 4.32, “jira.tool invocation” shows the output from invoking the <jira.tool> target.

Example 4.32. jira.tool invocation

C:\svn-csdl\StackyHack>ant -f jira.build.xml jira.tool
Buildfile: jira.build.xml

jira.tool:
    [mkdir] Created dir: C:\svn-csdl\StackyHack\build\jira
[jiraextract] Jira lives at: http://hackydev.ics.hawaii.edu:8080/
[jiraextract] Downloading http://hackydev.ics.hawaii.edu:8080/secure/IssueNavigator.jspa?view=rss&pid=10050&sorter/field=issuekey&sorter/order=DESC&tempMax=1&reset=true&decorator=none
[jiraextract] Downloading http://hackydev.ics.hawaii.edu:8080/browse/STACKYHACK-1?decorator=none&view=rss

BUILD SUCCESSFUL
Total time: 0 seconds

4.14.4. Running the Jira sensor to send Issue data to Hackystat

After the Jira Issue Extractor has been invoked to download XML data regarding the set of issues associated with a Jira project, the Jira sensor can be invoked to read in the resulting XML files send the data to Hackystat as Issue sensor data.

Example 4.33, “jira.sensor invocation” illustrates the invocation of the Jira sensor. Note that a "jira.default.userkey" has been supplied on the command line (the actual value replaced with "XXXXXXXXXXXXX"). In normal circumstances, you will want to set up a usermaps file so that individual issues can be sent to different Hackystat users. In this case, we will not set up a usermaps file, and instead use the jira.default.userkey property to force all of the Jira issue data to be sent to a single Hackystat account.

Example 4.33. jira.sensor invocation

C:\svn-csdl\StackyHack>ant -Djira.default.userkey=XXXXXXXXXXXXXX -f jira.build.xml jira.sensor
Buildfile: jira.build.xml

jira.sensor:
[hacky-jira] Sensor enabled?: true
[hacky-jira] Processing file: C:\svn-csdl\StackyHack\build\jira\STACKYHACK-1.xml
[hacky-jira]   No mapping. Sending issue data to default Hackystat userKey 'XXXXXXXXXXXX'
[hacky-jira] Processing file: C:\svn-csdl\StackyHack\build\jira\STACKYHACK-2.xml
[hacky-jira]   No mapping. Sending issue data to default Hackystat userKey 'XXXXXXXXXXXX'
[hacky-jira] Attempted send for default user 'XXXXXXXXXXX' was successful.
[hacky-jira] Hackystat data on 2 Jira Issues sent to http://hackystat.ics.hawaii.edu/ (3 secs.)

BUILD SUCCESSFUL
Total time: 3 seconds

Once you've invoked the sensor, you can verify that this data was received at the server by using the List Sensor Data command. Figure 4.21, “ List Sensor Data with StackyHack Issue data ” illustrates what this page might look like after receiving the StackyHack data from the Jira sensor.

Figure 4.21.  List Sensor Data with StackyHack Issue data


List Sensor Data with StackyHack Issue data