26.30. Subversion

26.30.1. Overview

The Subversion (SVN) sensor collects information about each revision of a file maintained in a SVN repository. The SVN sensor represents this information using the Commit sensor data type, documented in Section 25.7, “Commit”. This sensor can track file rename.

26.30.2. Installation

26.30.2.1. Prerequisites

The SVN Server sensor requires Java 1.5.0 or later, Ant 1.6.5 or later, and Subversion 1.2.1 or later. It also requires an SVN URL for connection purposes. The http:, https:, and svn: protocols are supported, but the file: protocol is not. This sensor has been tested only with Subversion 1.2.1 using the svn: protocol on Windows XP. Please let us know if this sensor fails under different conditions.

26.30.2.2. 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.30.2.3. Configure and install the Subversion sensor

In the HackyInstaller main window, select the SVN sensor and press "Configure Selected Sensor". Figure 26.56, “ Subversion sensor 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.56.  Subversion sensor installer configuration window


Subversion sensor installer configuration window

This sensor supports the following properties and paths:

  • Enable SVN 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 SVN sensor requires the placement of a sensor executable into Ant's lib/ directory.

26.30.2.4. Configure usermaps.xml

Use HackyInstaller to configure the usermaps.xml file, as documented in Section 2.7, “Sensors for multi-user tools and the usermaps.xml file”.

[Note]Note

The tool name in the usermaps.xml file must be "SVN". You can also specify a default user. The default user will be used if no username is present on the commit (i.e. the SVN server allows anonymous commit) or the user Hackystat account is not found through usermaps.xml.

26.30.2.5. Run the SVN Sensor

The SVN sensor is written as an Ant task. Example 26.70, “Invoking the SVN sensor with ANT” illustrates an example Ant target. Section 4.15, “Measurement: Version control commits with Subversion” provides an example use of the Subversion sensor with a sample Java system called StackyHack.

Example 26.70. Invoking the SVN sensor with ANT

  <target name="run">
    <taskdef name="svn-sensor" classname="org.hackystat.sensor.svn.SvnSensorAntTask" />
    <svn-sensor repositoryName="Local" 
                repositoryUrl="svn://localhost:9999/test"
                userName="myUserName" 
                password="myPassword"
                fileNamePrefix="c:/svn/project"
                defaultHackystatAccountKey="defaultUserKey"
                verbose="true"
                fromDate="2006-01-01" 
                toDate="2006-05-01"
                fromEmail="joe@foo.com" 
                toEmail="joe@foo.com" 
                smtpServer="smtp.foo.com"
                debug="true" />
  </target>

As illustrated above, the sensor accepts a variety of attributes. Below is a table describing the valid attributes.

Table 26.14. Subversion Sensor Ant Task Attributes

AttributeDescriptionRequired?
repositoryNameSVN repository name.Required
repositoryUrlThe url to the svn repository. HTTP|HTTPS|SVN protocols are supported. File protocol is not supported.Required
userNameThe user name to gain read access, if the SVN repository does not allow anonymous access.Optional
passwordThe password corresponds to the user name. This attribute is ignored if userName is not set.Optional
fileNamePrefixThe sensor can only retrieve the file name relative to SVN repository root. However Hackystat analysis requires fully qualified file name. The attribute allows you to specify a path to be prepended to the SVN relative file name.Optional.
defaultHackystatAccountKeyFor each revision, the sensor finds out the hackystat account associated with the committer, and send metrics to that account. The mapping is defined in a xml map file. Refer to "hackyKernel/sensor/usermap" package for detailed information. If the sensor cannot determine the associated Hackystat account, and if this attribute is specified, then the metrics will be sent to the default Hackystat account. In other words, if you want all commit information sent to one single account, don't define any mapping and use this attribute.Optional. Default is no default Hackystat account.
verboseIf set to true, information about each file being process will be output. Optional. Default is false.
fromDateThe date from which to record commit information. It must be in yyyy-MM-dd format.Optional. If set, ToDate must also be set. If not set, only previous day's commit information if recorded.
toDateThe date to which to record commit information. It must be in yyyy-MM-dd format.Optional. If set, FromDate must also be set. If not set, only previous day's commit information if recorded.
fromEmailThe email account of the person who would be listed in the From: field if the sensor malfunctions and an email notification is generated by the sensor.Optional, but fromEmail, toEmail, smtpServer must be used together.
toEmailThe To: field of the alert message generated if the sensor malfunctions.Optional, but fromEmail, toEmail, smtpServer must be used together.
smtpServerThe SMTP server used to send out alert message if the sensor malfunctions.Optional, but fromEmail, toEmail, smtpServer must be used together.
debugIf set to true, information about all captured commit metrics is written to console. Note that metrics will NOT be sent to Hackystat server if debug=true.Optional. Default is false.

26.30.2.6. Configure each user's workspace roots for this SVN data

By setting up the usermaps.xml file, the SVN sensor can send SVN sensor data to the Hackystat accounts associated with a set of users. This SVN data will contain a fully qualified file name that starts with the fileNamePrefix. In the above example invocation of the SVN sensor listed above, the fileNamePrefix is "c:\svn\project".

In order for this SVN data to be associated with a Hackystat project, each user's Workspace Root must be set correctly for the SVN data. In most cases, this means that each user must login to the Hackystat server, go to the Preferences page, and use the Workspace Roots command to add the fileNamePrefix value as one of their workspace roots. (This prefix value will not appear in the set of possible Workspace Roots until after some SVN data has been sent to the user's account.) For more details on Workspace Roots, see Section 3.3, “Overview of Workspaces, WorkspaceFiles, and Workspace Roots”.

26.30.2.7. Schedule your script to run once a day

The typical way to invoke the Subversion sensor is to use an operating system facility to run your script once a day at a convenient time, and configure the sensor to capture the previous day's commits. In Unix, the facility is called "cron", in Windows, the facility is called "Scheduled Tasks" and is found in the Control Panel. Each day when it runs, it will process all commit data from the previous day. Thus, you will need to wait a day to see commit data show up in your Hackystat analyses.

The sensor can also be configured to capture commit information between any arbitrary period by specifying 'fromDate' and 'toDate' attributes. This is useful when you want to recover historical commit records. The sensor is written in such a way that it is safe to run multiple times for the same period. There will be no duplicated commit records.

26.30.3. Installation verification

26.30.3.1. Invoke the SVN sensor with debug flag on

To verify your SVN sensor installation, turn the debug flag on and invoke the sensor. You will see detailed information in the console windows. Note that when debug flag is on, no commit metrics will be sent to Hackystat server.

26.30.4. Installation troubleshooting

26.30.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.30.4.2. Troubleshooting local caching of sensor data

The SVN sensor will cache data locally if it cannot find the user associated with an account and no default user is supplied. If you are obtaining the error message that the data is cached locally, be sure that you are supply a default user (the defaultHackystatAccountKey).

26.30.4.3. Checking client-side logging

The SVN sensor writes out a file called SVN.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.71, “Log file for SVN sensor”.

Example 26.71. Log file for SVN sensor

Hackystat Version: 6.4.204 (February 4 2005 14:59:29)
SensorShell started at: 03/22/2005 10:12:50
Type 'help' for a list of commands.
Host: http://HACKY_SERVER/ is available and key is valid.
Defined shell command: Dependency
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: UnitTest
Defined shell command: BuffTrans
Defined shell command: Commit
Defined shell command: Build
AutoSend not enabled.
Checking for offline data to recover.
No offline data found.
#> Commit [setTool, Subversion]
setTool OK
#> Commit [add, 1111416141824, /SixthAnalysis/build.xml, todd, http://REPOSITORYURL, NA, 32, 0, 0, 0, New build file to be used as part of main build]
Commit add OK (1 total)

26.30.4.4. 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 Subversion.0.log file.

  • A description of the problem you are having.

26.30.5. Uninstallation

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

26.30.6. Credits

This sensor includes software developed by TMate Software (http://www.tmatesoft.com/). The JavaSVN library is distributed under the TMate JavaSVN library agreement (http://tmate.org/svn/license.html). Copyright (c) 2004-2005 TMate Software. All Rights Reserved.