sonarqube scanner properties file for C project

2019-03-04 07:37发布

问题:

I am using sonar qube for analysing C files. I am not able to see the complete smells listed for C/C++ after analysis. For example Divide by Zero error is not listed in the code smell.

My sonar scanner settings is reconfigured for C language using the option sonar.language=c and used C language specific tags like, sonar.c.include directories. I am getting Lexer errors for the C files.

Can anyone help me to solve this.

回答1:

You can do analysis for free with SonarOpenCommunity/sonar-cxx. However, you need an external tool such as cppcheck in your dev machine to produce its results in XML format in a file.

Here is how I was able to do it:

  1. Install sonar-c-plugin. For my version of sonarqube 5.6.1 I got this from https://github.com/SonarOpenCommunity/sonar-cxx/releases/download/cxx-0.9.8/sonar-c-plugin-0.9.8.jar
  2. Configure the sonar.c.cppcheck.reportPath property in sonarqube server at Administration / General Settings / C(Community) / Cppcheck report(s). I set it to build/cppcheck.xml
  3. Install cppcheck in dev machine
  4. Run cppcheck on your project and save results to build/cppcheck.xml
  5. Create a sonar-project.properties file at root of your project see below for my sample
  6. Install and run sonar-scanner

Here is my sonar-project.properties file:

sonar.host.url=http://mycompany.com:9000

sonar.projectKey=myprojectShortName
sonar.projectName=myprojectLongname
sonar.projectVersion=0.1

# Your relative path to source folder may be different 
sonar.sources=src/main/c

sonar.language=c

# The build-wrapper output dir
sonar.cfamily.build-wrapper-output=bw-outputs

# Encoding of the source files
sonar.sourceEncoding=UTF-8


回答2:

C an C++ are supported in SonarQube only with the paid Developer Edition or more expensive editions from SonarSource. If you are running SonarQube Community Edition this may be why you are getting these lexer errors or otherwise unable to scan C files.



标签: sonarqube