Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make sonar analysis for C++ work?

Tags:

sonarqube

I'm trying to use sonar for static analysis on a c++ code. I've installed sonar and configured my project (it appears on the localhost sonar page, but i do not see any code violation for the respective code). I have the C++ community plugin installed.

My sonar-project.properties looks like this:

# required metadata
sonar.projectKey=DiceInvaders
sonar.projectName=Dice Invaders
sonar.projectVersion=1.0

# optional description
sonar.projectDescription=DiceInvaders by CS

# path to source directories (required)
sonar.sources=D:\\DiceInvaders\\Code

# path to test source directories (optional)
#sonar.tests=D:\\DiceInvaders\\Code

# path to project binaries (optional), for example directory of Java bytecode
#sonar.binaries=binDir

# optional comma-separated list of paths to libraries. Only path to JAR file is supported.
#sonar.libraries=path/to/library/*.jar,path/to/specific/library/myLibrary.jar,parent/*/*.jar

# The value of the property must be the key of the language.
sonar.language=c++
sonar.exclusions=**/*.ipch, **/**/*.rc
sonar.cxx.cppcheck.path = "C:\Program Files (x86)\Cppcheck\cppcheck.exe"
sonar.cxx.cppcheck.reportPath="D:\DiceInvaders\Code\cppcheck-reports\cppcheck.xml". 

# Additional parameters
#sonar.my.property=value

I do not get any error when running sonar-runner from cmd.

If i run manually the cppcheck.exe tool on my project I can find violations. Why don't the violations appear on sonar's page? Is there something else I should configure, am I doing something wrong?

like image 413
Catalin STAICU Avatar asked Jun 06 '13 13:06

Catalin STAICU


2 Answers

I was able to make it work by running the cppcheck tool independently before sonnar-runner, and placing the generated xml report in the bin folder of sonnar-runner.

In the sonar-project.properties file I've specified the xml directly: sonar.cxx.cppcheck.reportPath=cppcheck-result-1.xml

like image 108
Catalin STAICU Avatar answered Oct 13 '22 10:10

Catalin STAICU


I had a similar problem, which was caused by a whitespace after 'sonar.language=cs'. Be sure that there is a linebreak immediately after 'cxx'. Hope it works.

like image 29
Anders Finn Jørgensen Avatar answered Oct 13 '22 09:10

Anders Finn Jørgensen