Skip to end of metadata
Go to start of metadata

Description / Features

This plugin adds basic support of C++ language into SonarQube.

Current feature list:

  • Basic size metrics:
    • Files (number of)
    • Lines
    • Lines of comments
    • Lines of code
    • Lines of commented out code
  • Static code checking via virtually any static analyser tool. And possibility of extension of their coding rules.
  • Dynamic checking for memory management problems via Valgrind
  • Cyclomatic (McCabe) complexity metrics including: 
    • Projects complexity
    • Average function/method complexity
    • Average file complexity
    • Complexity distributions
  • Code coverage metrics including:
    • Unit test overage (line and branch)
    • Integration test coverage (line and branch)
    • Overall branch coverage (line and branch)
  • Unit test execution metrics including:
    • Successfully executed tests
    • Failed tests
    • Skipped tests
    • Execution time
  • Recognition of code duplication
  • Basic highlighting mode for C++ in SonarQube UI

Dependencies

The Cxx-Plugin has an obligatory dependency on Java (of course... the plugin itself and all runners are Java programs).

Moreover, there are optional dependencies on:

  • Various external code analyzers:
    • Cppcheck. Detects a wide range of problems ranging from performance issues and resource leakage to undefined behaviour. Binary packets are available on/for various platforms. Using the latest release pays off in general; compile from source if in doubt.
    • RATS. Detects (potential) security problems in code, sensible for code bases with increased security requirements. Use binary packages or compile from source.
    • Vera++. Focuses on code style issues. There's a binary package for Windows, users of other platforms are likely to compile themselves.
    • Valgrind (memcheck). Detects various memory management problems at runtime. Basically Linux only; just use the packages from your distribution.
    • CppNcss. Provides cyclomatic (McCabe) complexity measures. This is a Java program distributed as a zip archive. Just unpack and make sure the "bin" directory is in PATH.
    • Pc-Lint. Static analyser from Gimpel
  • GCCgcov, gcovrBullseye and Python for coverage determination. Install Python and place the script somewhere on the PATH.  

Installation

 

  1. Install the plugin through the Update Center or download it into the SONARQUBE_HOME/extensions/plugins directory
  2. Restart the SonarQubeserver

Quick Configuration Guide

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.

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.
sonar.cxx.cppcheck.reportPathProject-widecppcheck-reports/cppcheck-result-*.xmlcppcheck-report-*.xml

Ant pattern describing the path to Cppcheck reports, relative to projects root.

sonar.cxx.cppncss.reportPathProject-widecppncss-reports/cppncss-result-*.xmlcppncss-report-*.xmlAnt pattern describing the path to CppNcss reports, relative to projects root.
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.
sonar.cxx.rats.reportPathProject-widerats-reports/rats-result-*.xmlrats-report-*.xmlAnt pattern describing the path to RATS reports, relative to projects root.
sonar.cxx.valgrind.reportPathProject-widevalgrind-reports/valgrind-result-*.xmlvalgrind-report-*.xmlAnt pattern describing the path to Valgrind reports, relative to projects root.
sonar.cxx.vera.reportPathProject-widevera++-reports/vera++-result-*.xmlvera-report-*.xmlAnt pattern describing the path to Vera++ reports, relative to projects root.
sonar.cxx.xunit.reportPathProject-widexunit-reports/xunit-result-*.xmlxunit-report-*.xmlAnt pattern describing the path to unit test execution reports, relative to projects root.
sonar.cxx.pclint.reportPathProject-widepclint-reports/pclint-result-*.xmlpclint-result-*.xmlAnt pattern describing the path to pc-lint reports, relative to projects root.
sonar.cxx.externalrules.reportPathProject-wideexternalrules-result/externalrules-result-*.xmlexternalrules-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      For transforming CppTestUnit-reports
  • cppunit-1.x-to-junit-1.0.xsl            For transforming CppUnit-reports
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.
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.
sonar.cxx.coverage.overallReportPath (>=0.2)Project-widecoverage-reports/overall-coverage-*.xmloverall-coverage-*.xmlAnt pattern describing the path of overall test coverage reports, relative to projects root.

 Note: Report paths are always relative to projects path.

Known Limitations

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

Roadmap

Following items are in the queue (more or less...):

  • Use SSLR technology
  • Integrate compiler warnings
  • Implement the dependency analysis (package tangle index metric)

Change Log

Version 0.2 (17 issues)
Type Key Summary Priority
New Feature SONARPLUGINS-2676 Allow extension of rules for supported code checkers by reusing extensions/rules folder in Sonar Major
New Feature SONARPLUGINS-2671 Generic sensor for importing violations Major
New Feature SONARPLUGINS-2670 Provide support for the overall test coverage metric Major
New Feature SONARPLUGINS-2669 Provide support for Common Rules Major
Task SONARPLUGINS-2668 Update plugin to be compatible with Sonar 3.0 API Major
Improvement SONARPLUGINS-2415 Support cppcheck 1.56 and 1.57 Major
Task SONARPLUGINS-2170 Rename Cxx Plugin to 'C++ (Community)' Major
Improvement SONARPLUGINS-2104 Provide support for RATS 2.3 Trivial
Improvement SONARPLUGINS-2103 Provide support for cppcheck 1.55 Trivial
Improvement SONARPLUGINS-2039 Provide support for cppcheck 1.54 Major
New Feature SONARPLUGINS-1994 Provide support for PC-lint Major
Bug SONARPLUGINS-1991 CPPNCSS fails to parse some reports with message: "Cannot find the CNN-label" Major
Bug SONARPLUGINS-1944 Vera++ to checkstyle perl script doesn't manage errors Minor
Improvement SONARPLUGINS-1942 Extended RATS rules Minor
Bug SONARPLUGINS-1877 Support Windows and Unix style reports in CPPNCSS Critical
Bug SONARPLUGINS-1833 Vera++ fails to parse reports with "name=error" Minor
New Feature SONARPLUGINS-1756 Provide support for BullseyeCoverage Major

 

Version 0.1 (18 issues)
Type Key Summary Priority
Bug SONARPLUGINS-2278 Code Coverage for C++ with CXX plugin Critical
New Feature SONARPLUGINS-1800 Integration of cppcheck 1.54 Trivial
Bug SONARPLUGINS-1767 CXXRatsSensor crashes due to RATS bug Minor
Bug SONARPLUGINS-1754 Sonar - Cxx plugin - CxxXunitSensor parser only allows one Testsuite Blocker
Bug SONARPLUGINS-1751 Sonar CXX Plugin does not work with Sonar 3.0 Major
Bug SONARPLUGINS-1726 CxxLineCounter leaks file descriptors Major
Improvement SONARPLUGINS-1717 CxxXunitSensor, 3 default xslt embedded Major
Bug SONARPLUGINS-1690 GPL header licence mismatch Major
Improvement SONARPLUGINS-1688 Cleanup rules, rule profiles and rule repositories Major
Improvement SONARPLUGINS-1687 SCM Activity Plugin compatibility Major
Improvement SONARPLUGINS-1686 Remove unnecessary Maven dependency Major
New Feature SONARPLUGINS-1611 Update c++ file extensions supported Major
Improvement SONARPLUGINS-1599 Fix for paths management in Windows environment and drilling Major
Improvement SONARPLUGINS-1576 Internal XSLT transformer for XunitSensor Major
New Feature SONARPLUGINS-1211 Update rats-profile.xml and rats.xml for rats 2.3 Major
Bug SONARPLUGINS-967 sonar-cxx-plugin does not recognize uninitVar cppcheck violation Minor
Bug SONARPLUGINS-954 coverage parsing error when line referenced twice Major
Task SONARPLUGINS-792 Complete RATS integration Major