As a simple example, we walk through customizing the default Size and Complexity reports. This example familiarizes you with the metrics.xml file, so that you can perform more complicated customizations, such as adding your own report types. It also shows you where you need to verify that your changes appear in Klocwork Static Code Analysis.
To customize the default Size and Complexity reports:
- Back up the following file:
- <projects_root>/config/metrics.xml
- Open the original metrics.xml file for editing.
- For the Size report, you can change only the label that appears in the list of report types in Static Code Analysis. To change this label, edit the value for the <name> element (Size by default).
- As an example, we change the value for the <name> element to "Lines of Code":
-
<category catid="TotalMetricValue">
- <metric>
- <name>Lines of Code</name>
- <description>Lines of Code</description>
- <!--involved kw internal metric kinds-->
- <kids>45,84</kids>
- <enable>true</enable>
- </metric>
- </category>
- For the Complexity report:
- To change the short title (the label that appears in the list of report types in Static Code Analysis), edit the value for the <name> element (Complexity by default).
- To change the default threshold (the value that appears in the editable Threshold field in Static Code Analysis), edit the value for the <default_threshold> element (20 by default).
- As an example, we change the value for the <default_threshold> element to 10:
- <category catid="EntityCountOverThreshold">
- <metric>
- <name>Complexity</name>
- <description>Method Complexity >{threshold}</description>
- <kids>135</kids>
- <entityKids></entityKids>
- <default_threshold>10</default_threshold>
- <enable>true</enable>
- </metric>
- </category>
- Save the file.
- Restart the Klocwork Server with kwservice restart or Windows Services Administration.
- The changes you have made are visible to all Static Code Analysis users when they log in, or when they refresh the Reports page. We now verify that our changes are appearing correctly.
-
Log in to Static Code Analysis.
- Click Reports for your project.
- Click Create a new report.
Note: If you were already viewing the report types, refresh your browser to pick up the changes to metrics.xml.
- The report types are displayed on the right. Scroll down and click see more.
- We see that our list now includes the Lines of Code report type (instead of Size).
- Select Complexity.
- We see that the default threshold is now set at 10 (instead of 20).