Skip to end of metadata
Go to start of metadata
You are viewing an old version of this page. View the current version. Compare with Current ·  View Page History

Creation of a profile for the external tool - Mandatory before running a analysis

The creation of rule set for the external tool re-uses the concept of Extending Rules in C++ Analysers therefore the only thing needed is a xml file with the definition of the rules and their respective activation in sonar. The location of the rules definitions file needs to be installed under 

  • [Server Dir]\extensions\rules\cxxexternal

Importing the violation report for the external tool

The property sonar.cxx.externalrules.reportPath needs to be used to point to the location of the report. The following table describes the format of the report

Xml Description - RNG-SchemaExample
<element name="results" xmlns="http://relaxng.org/ns/structure/1.0">
 <zeroOrMore>
   <element name="error">
     <attribute name="file"/>
     <attribute name="msg"/>
     <attribute name="id"/>
     <attribute name="line">
       <data type="integer" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes" />
     </attribute>
     <text/>
   </element>
 </zeroOrMore>
</element>

<?xml version="1.0"?>
<results>
<error file="sources/utils/code_chunks.cpp" line="1" id="cxxexternal-unusedFunction" msg="The function 'foo' is never used"/>
<error file="sources/utils/utils.cpp" line="1" id="cxxexternal-unusedFunction" msg="The function 'utils' is never used"/>
</results>

Attribute

Description

filesource file, relative to project path
lineline of the violation
idid of the rule, mapped a rule in sonar. See "Enable the rules in Sonar server" below
msgdescription of the violation

List of third party tools and their rule profiles

ToolSourceUsageRules Profile / Needed scripts
cpplint

Home Page

Download Tool

Create the rules profile and the modified cpplint python script as follow:

    • python cpplint_createrules.py cpplint.py

This will generate the following files:

    • cpplint.xml that should installed in extensions/rules/cxxexternal
    • cpplint_mod.py that should be used to check the code

After this you can run the cpplint_mod.py against any source file like this:

    • python cpplint_mod.py source.cpp 2> report.txt

The output file report.txt needs to be converted to xml format described above. For convenience a perl script is available here and can be run as follow:

    • perl cpplintReport2checkstyleReport.perl report.txt cpplint-result-0.xml
Todo

This is maintained by the community, so if you want to share additional rules profiles or tool do so by using the sonar user mailing list

The list above is provided without any warranty, therefore you may need to debug the scripts or tools in order to make them work

Labels
  • None