Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Cxx plugin uses the following properties during analysis. See here for the ways how to pass them to the plugin.

 

 

Property

Scope

Default

Example

Description

sonar.cxx.suffixes.sourcesSystem- and/or project-widecxx,cpp,cc,c.C,.h

Comma separated list of file name extension to be considered as C++ source files during analysis. Leave unset to use the default ("cxx,cpp,cc,c")

sonar.cxx.suffixes.headersSystem- and/or project-widehxx,hpp,hh,h Comma separated list of file name extension to be considered as C++ source files during analysis. Leave unset to use the default ("hxx,hpp,hh,h")
sonar.cxx.cppcheck.reportPathProject-widecppcheck-reports/cppcheck-result-*.xmlcppcheck-report-*.xml

Ant pattern describing the path to Cppcheck reports, relative to projects root. Leave unset to use the default ("cppcheck-reports/cppcheck-result-*.xml").

sonar.cxx.cppncss.reportPathProject-widecppncss-reports/cppncss-result-*.xmlcppncss-report-*.xmlAnt pattern describing the path to CppNcss reports, relative to projects root. Leave unset to use the default ("cppncss-reports/cppncss-result-*.xml").
sonar.cxx.gcovr.reportPath (<0.2)Project-widegcovr-reports/gcovr-result-*.xmlgcovr-report-*.xmlAnt pattern describing the path to gcovr reports, relative to projects root. Leave unset to use the default ("gcovr-reports/gcovr-result-*.xml").
sonar.cxx.rats.reportPathProject-widerats-reports/rats-result-*.xmlrats-report-*.xmlAnt pattern describing the path to RATS reports, relative to projects root. Leave unset to use the default ("rats-reports/rats-result-*.xml").
sonar.cxx.valgrind.reportPathProject-widevalgrind-reports/valgrind-result-*.xmlvalgrind-report-*.xmlAnt pattern describing the path to Valgrind reports, relative to projects root. Leave unset to use the default ("valgrind-reports/valgrind-result-*.xml").
sonar.cxx.vera.reportPathProject-widevera++-reports/vera++-result-*.xmlvera-report-*.xmlAnt pattern describing the path to Vera++ reports, relative to projects root. Leave unset to use the default ("vera++-reports/vera++-result-*.xml").
sonar.cxx.xunit.reportPathProject-widexunit-reports/xunit-result-*.xmlxunit-report-*.xmlAnt pattern describing the path to unit test execution reports, relative to projects root. Leave unset to use the default ("xunit-reports/xunit
sonar.cxx.externalrules.reportPathProject-wideexternalrules-result/externalrules-result-*.xml").externalrules-result-*.xmlAnt pattern describing the path to unit test execution reports, relative to projects root.
sonar.cxx.xunit.xsltURLProject-wide cppunit-1.x-to-junit-1.0.xsl

A name of a built in XSLT-file or an URL to an external one. Available builtins:

  • boosttest-1.x-to-junit-1.0.xsl         For transforming Boost-reports
  • cpptestunit-1.x-to-junit-1.0.xsl      Fortransforming CppTestUnit-reports
  • cppunit-1.x-to-junit-1.0.xsl            For transforming CppUnit-reports

Leave unset if no transformation should be used.

sonar.cxx.coverage.reportPath (>=0.2)Project-widecoverage-reports/coverage-*.xmlcoverage-*.xmlAnt pattern describing the path of unit test coverage reports, relative to projects root. Leave unset to use the default ("coverage-reports/coverage-*.xml").
sonar.cxx.coverage.itReportPath (>=0.2)Project-widecoverage-reports/it-coverage-*.xmlit-coverage-*.xmlAnt pattern describing the path of integration test coverage reports, relative to projects root.Leave unset to use the default ("
sonar.cxx.coverage.itReportPath (>=0.2)Project-widecoverage-reports/itoverall-coverage-*.xml").

 

...

overall-coverage-*.xmlAnt pattern describing the path of integration test coverage reports, relative to projects root.

 Note: Report paths are always relative to projects path.

Usage

 

You can analyze your projects using the usual means (see this page for all available). All runners should work. See below for details how to do it for maven-, ant-, and all-the-other-projects.

...

Code Block
rats -w 3 --xml <sources> > report.xml

 

PC-Lint

Todo

External Rules

Import of violations

As of version 0.2, any static analysis tool can be reused with the plugin using the property sonar.cxx.externalrules.reportPath. 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
Enable the rules in Sonar server

To reuse reports from other tools the C++ quality profile in sonar needs to be inline with the reported violations in the external report.

Known limitations

    • Some analyzers (RATS, most notably) may have issues and crash occasionally.
    • Valgrind is only available on a subset of UNIX platforms.

...