-
Notifications
You must be signed in to change notification settings - Fork 365
Running the analysis
This description is only valid for cxx plugin version 1.x
cxx plugin won't execute neither test runners nor coverage tracers nor static checkers itself. All this data has to be provided in form of reports. See Running tools._
You can analyze your projects using the usual means (see Analyzing Source Code). All scanners should work. See below for details.
Analysis of a C++ project involves usually three steps:
-
Run the tools (see Running tools) which are of interest for you and store the results in a file somewhere underneath the root directory of your project. Its usually convenient to put this into the build system; a shell script may be a good choice, too.
-
Provide a configuration using the file "sonar-project.properties". Set following properties, besides the standard ones:
- sonar.language to "c++". This is required for SonarQube's < 4.2. For SonarQube's >= 4.2, leaving this property unset enables the multi-language feature.
- Optional: sonar.cxx.includeDirectories and sonar.cxx.defines (see Supported configuration properties)
- Optional: paths to the generated reports (see Supported configuration properties)
-
Make sure the SonarQube Server is running
-
Use the SonarQube Scanner to start the analysis and feed the data into SonarQube. This usually boils down to calling the scanner in the root directory of your project:
$ cd <project root>
$ sonar-scanner
There may be a Step '0' too: "use your build system to make a build suitable for running the Step 1". This may be the case for collecting coverage statistics when using gcc+gcov, for example.
For details how to invoke the tools and tie it all together see the sample project.
There is a maven plugin which automates running of a sonar analysis on a C++ project but requires a maven setup. Running a SonarQube analysis on maven projects is quite simple and usually a matter of:
-
Getting and installing the cxx-maven-plugin (usage). If you use multiple source directories and depend on cxx:addsource goal, you shall use -Dsonar.phase=cxx:addsource option (see Sonar Maven Plugin Project Configuration )
-
Setting the language property and the source directory in your pom:
<properties>
...
<sonar.language>c++</sonar.language>
...
</properties>
<build>
...
<sourceDirectory> path </sourceDirectory>
...
</build>
-
Make sure your SonarQube Server is running.
-
Start the analysis with
$ mvn sonar:sonar
or
$ mvn sonar:sonar -Dsonar.phase=cxx:addsource
For details see the sample maven project.