The last section showed how to measure system size with LOCC. In this section, we will show the same process, this time using the SCLC tool.
To install SCLC for use in StackyHack, download the .zip file containing the latest release from the SCLC home page into a directory such as "java-lib", and unzip it. Then, define an environment variable called SCLC_HOME to point to the distribution directory. For example, "c:\java-lib\sclc-2.4.302". (Note that the file path should have no embedded spaces in it.)
Example 4.7, “sclc.build.xml” shows the sclc.build.xml file, which defines the Ant targets used to invoke the SLCL tool and the SCLC sensor.
Example 4.7. sclc.build.xml
<project name="stackyhack.sclc" default="sclc">
<description>
Provides the SLCL tool and the Hackystat SCLC sensor.
</description>
<import file="build.xml"/>
<property environment="env"/>
<property name="sclc.dir" location="${build.dir}/sclc" />
<target name="sclc" depends="sclc.tool, sclc.sensor" description="Runs SCLC, followed by the SCLC sensor."/>
<target name="sclc.tool" depends="compile" description="Compute size data on the source code using SCLC.">
<!-- Check for the SCLC_HOME environment variable, failing the build if it can't be found. -->
<available file="env.SCLC_HOME/src/sclc" property="sclc.available"/>
<fail unless="sclc.available" message="Error: SCLC_HOME not set or file 'sclc' not found, indicating SCLC is not installed."/>
<mkdir dir="${sclc.dir}" />
<!-- Run size data using SCLC. Invoke Perl via the exec task to run SCLC. -->
<exec executable="perl" dir="${build.dir}">
<arg line="${env.SCLC_HOME}/src/sclc -default_exclude -ignore -xml_output ${sclc.dir}/size.xml -recurse ${src.dir}" />
</exec>
</target>
<target name="sclc.sensor" description="Sends SCLC size data to Hackystat using the XmlData sensor.">
<!-- Define the XmlData sensor taskdef, failing the build if the sensor is not installed. -->
<available classname="org.hackystat.sensor.xmldata.XmlDataSensor" property="xmldata.sensor.available"/>
<fail unless="xmldata.sensor.available" message="Error: XmlData Sensor not installed."/>
<taskdef name="hacky-xmldata" classname="org.hackystat.sensor.xmldata.XmlDataSensor" />
<!-- Send SCLC size data to hackystat using the XmlData sensor-->
<hacky-xmldata verbose="${hackystat.verbose.mode}">
<fileset file="${sclc.dir}/size.xml"/>
</hacky-xmldata>
</target>
</project>
The sclc.build.xml defines the <sclc.tool> target to invoke SCLC and produce size data in XML format in the build/sclc/size.xml file. The <sclc.sensor> target uses the generic XmlData sensor to read in the size.xml file and send the output to Hackystat. The <sclc> target simply invokes both of these targets in sequence.
Example 4.8, “Invoking the sclc.tool target” shows the output from running the <sclc.tool> target to obtain size data.
Example 4.8. Invoking the sclc.tool target
C:\svn-csdl\StackyHack>ant -f sclc.build.xml sclc.tool
Buildfile: sclc.build.xml
compile:
sclc.tool:
[exec] Lines Blank Cmnts NCSL TPtoks
[exec] ====== ====== ====== ====== ====== ============================================
[exec] 37 5 21 11 62 C:\svn-csdl\StackyHack\src\edu\hawaii\stack\ClearStack.java (Java)
[exec] 18 2 10 6 31 C:\svn-csdl\StackyHack\src\edu\hawaii\stack\EmptyStackException.java (Java)
[exec] 6 1 0 5 37 C:\svn-csdl\StackyHack\src\edu\hawaii\stack\overview.html (HTML)
[exec] 7 3 0 4 26 C:\svn-csdl\StackyHack\src\edu\hawaii\stack\package.html (HTML)
[exec] 114 13 53 48 293 C:\svn-csdl\StackyHack\src\edu\hawaii\stack\Stack.java (Java)
[exec] 41 4 14 23 190 C:\svn-csdl\StackyHack\src\edu\hawaii\stack\TestClearStack.java (Java)
[exec] 52 7 17 28 198 C:\svn-csdl\StackyHack\src\edu\hawaii\stack\TestStack.java (Java)
[exec] 13 4 0 9 63 ----- HTML ----- (2 files)
[exec] 262 31 115 116 774 ----- Java ----- (5 files)
[exec] 275 35 115 125 837 ***** TOTAL ***** (7 files)
BUILD SUCCESSFUL
Total time: 1 second
This target produces a file called size.xml in the build/sclc directory containing size data. Here's a sample of the contents of that file, which is conveniently in a format compatible with the XmlData sensor.
<?xml version="1.0"?>
<sclc>
<file tool="SCLC"
sdt="FileMetric"
fileType="Java"
fileName="C:/svn-csdl/StackyHack/src/edu/hawaii/stack/ClearStack.java"
blankLines="5"
commentLines="21"
sourceLines="11"
tptoks="62"
totalLines="32"/>
<file tool="SCLC"
sdt="FileMetric"
fileType="HTML"
fileName="C:/svn-csdl/StackyHack/src/edu/hawaii/stack/overview.html"
blankLines="1"
sourceLines="5"
tptoks="37"
totalLines="5"/>
</sclc>
While SCLC cannot provide the detailed size data provided by LOCC (such as the number of lines of code per method), it can provide less detailed size data about a broader variety of file types. As this example shows, SCLC provides size data about HTML as well as Java files, which is not possible with LOCC.
After SCLC has been invoked to generate size data, the SCLC sensor can be invoked to read in the size.xml file produced by SCLC and send the resulting data to Hackystat as FileMetric sensor data.
To accomplish this, you must first install the generic XmlData sensor, which can process the size.xml files output by SCLC. 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 XmlData configuration window should look something like the screen image in Figure 4.4, “ HackyInstaller configuration screen for XmlData sensor ”.
Example 4.9, “sclc.sensor invocation” illustrates the invocation of the SCLC sensor.
Example 4.9. sclc.sensor invocation
C:\svn-csdl\StackyHack>ant -f sclc.build.xml sclc.sensor Buildfile: sclc.build.xml sclc.sensor: [hacky-xmldata] Verbose mode on: true [hacky-xmldata] Sensor enabled: true [hacky-xmldata] Processing file: C:\svn-csdl\StackyHack\build\sclc\size.xml [hacky-xmldata] Hackystat data from 7 entries sent to http://hackystat.ics.hawaii.edu/ BUILD SUCCESSFUL Total time: 4 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.5, “ List Sensor Data with StackyHack data ” illustrates what this page might look like after receiving the StackyHack data.
The SCLC sensor sends a separate FileMetric entry for each file whose type it understands in the src/ directory of the StackyHack system. In this case, both Java and HTML files are processed.