CppDepend SonarQube Light Integration


SonarQube community edition Integration



IMPORTANT:
  • To run CppDepend on a machine you need first to activate your pro BuildMachine licensing or your evaluation period.

    To do so, once CppDepend files unzipped on the machine, just run once VisualCppDepend.exe. You'll go through a few seconds activation procedure if the machine is connected to internet.

    If the machine is not connected to internet, an offline activation procedure will be proposed instead, and must be fulfilled in order to run the SonarQube CppDepend plugin.
  • The CppDepend SonarQube plugin supports SonarQube version 5.6 and higher.

Plugin Prerequisites

Install the CppDepend Plugin

    Copy the sonar-cxx-cppdepend-lightplugin-VERSION.jar

    • from the $CppDependInstallDir$\SonarPlugin directory
    • to the $SonarQubeInstallDir$\extensions\plugins directory
    • Restart the SonarQube server for it to take account of the CppDepend plugin.


Configure the CppDepend plugin
  • In the SonarQube user interface, go to Administration. You need to be logged with the appropriate administrator privileges for that.

  • MANDATORY Specify the full path of CppDepend.SonarQube.RuleRunner.exe. This file is in $CppDependInstallPath$\SonarPlugin\CppDepend.SonarQube.RuleRunner.exe. Don't prefix the path with an environnement variable path, write the entire absolute path (follow this advice for all paths writing you'll find in this documentation).
  • OPTIONAL Specify the CppDepend project file path (.cdproj extension) to fetch the rules from. If it's not specified the default CppDepend rule set will be used.
    If you specify the CppDepend project file path, the rules taken account are activated rules defined in:
    • The CppDepend project file,
    • Rules defined in the CppDepend Rules Files referenced by the CppDepend project file

Activate the CppDepend Rules in the Sonar server

The CppDepend rules are now loaded in the SonarQube repository but not activated yet.
To activate them, you have to:

  • Log as admin in the SonarQube UI:
  • Go to the Quality Profiles tab
  • Create a custom Quality Profile. If you already have a custom Quality Profile you can skip this step.
  • Make sure that you choose the Sonar way profile as parent of your new Quality Profile:


  • After the creation of the custom Quality Profile, you have to add the CppDepend rules. For that click on the Activate More button:


  • Choose the CppDepend repository, and click on the Bulk Change button and activate all the CppDepend rules in your new Quality Profile:


  • Finally go back to the Quality Profile tab and set the new Quality Profile as Default:



Activate the CppDepend Rules in the Sonar server (before SonarQube v6.X)
  • Log as admin in the SonarQube UI:
  • Go to the Rules tab:
  • Choose Language C++ and Repository: CppDepend

  • Activate these rules in the profile you want by clicking on Bulk Change - Activate In:

IMPORTANT:
  • Notice that the handle of a rule is the rule name with also the parent group(s) names and the rule source code. This remark is important in this situation when:
    - The NDepend project used for analysis contains a custom rule-set
    - The NDepend project specified in the SonarQube configuration to define the rules in the SonarQube system (parameter CppDepend rules from cdproj, see the previous section) is different from the NDepend project used for analysis.

    In such situation if the two rules-set don't correspond exactly, the rules won't be resolved in the SonarQube system and the issues won't be computed.
  • If some rules have been added or removed in your custom rule-set:
    1) Restart the SonarQube server to let it parse the NDepend project specified in the SonarQube configuration to define the rules
    2) go again in the Rules tab logged as administrator, to activate/deactivate these new/removed rules through eventually a Bulk Change action.

Run Sonar-Scanner

Here is the SonarQube documentation concerning runnig Sonar-Scanner from the command line argument.

To let the SonarQube Scanner also runs CppDepend analysis and rules, you need to append the mandatory parameter -D sonar.cpp.cppdepend.projectPath={the path of cdproj}.

Command without the CppDepend analysis from the plugin, In this case we will use an existing analyzed result:
>sonar-scanner  -D sonar.cpp.cppdepend.projectPath={the path of cdproj}

Don't use any environment variable in paths and if the path contains a space character, surround it with double quotes -D sonar.cpp.cppdepend.projectPath="C:\work with space\project.cdproj"


Browse CppDepend Rules Issues in the SonarQube UI

    CppDepend Rules Issues are now reported as any issues in the SonarQube UI.

    You can browse it, go to source code declaration (in the UI), assign it, change its status...

NOTES:
  • If some issues are missing in the SonarQube UI:
    - Check that you followed all rules activation steps explained in this document.
    - Then double check that the concerned rule is indeed activated by checking if it emits at least one issue.
    - In such case, if some issues are missing, this is because the source file declaration of their parent types hasen't been found. Typically this happens with types and their members generated by the compiler.


CppDepend offers a wide range of features. It is often described as a Swiss Army Knife for C and C++ developers.

Start Free Trial
.