Cannot scan a simple CMake or Make based C project

Must-share information (formatted with Markdown):

  • which versions are you using: SonarQube Developer Edition Version 7.9 (build 26994) on Ubuntu 18.04 Linux - your version 7.9.0.26994. I have SonarCFamily installed in version 6.3 (build 11371)
  • I am trying to scan a simple C based project using Jenkins
  • I get internal errors

I scan using
sonar-scanner
-Dsonar.projectKey=test01
-Dsonar.sources=.
-Dsonar.host.url=http://localhost:8082/sonarqube/
-Dsonar.login=57722a09234d5c3dc3c1d11e9d23bbc0d7507af0

I get
INFO: Quality profile for c: Sonar way
INFO: Quality profile for py: Sonar way
INFO: ------------- Run sensors on module test01
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=57ms
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by net.sf.cglib.core.ReflectUtils$1 (file:/var/lib/jenkins/.sonar/cache/a89f1943fc75b65becd9fb4ecab8d913/sonar-tsql-plugin.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte,int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of net.sf.cglib.core.ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
INFO: Sensor JavaXmlSensor [java]
INFO: Sensor JavaXmlSensor [java] (done) | time=2ms
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=12ms
INFO: Sensor Python Squid Sensor [python]
INFO: Load project repositories
INFO: Load project repositories (done) | time=12ms
INFO: Sensor Python Squid Sensor [python] (done) | time=231ms
INFO: Sensor Cobertura Sensor for Python coverage [python]
INFO: Sensor Cobertura Sensor for Python coverage [python] (done) | time=10ms
INFO: Sensor PythonXUnitSensor [python]
INFO: Sensor PythonXUnitSensor [python] (done) | time=1ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=3ms
INFO: Sensor CFamily [cpp]
ERROR:

The only way to get an accurate analysis of C/C++/Objective-C files is by using the SonarSource build-wrapper
and setting the property “sonar.cfamily.build-wrapper-output”, but it was not specified.

If you don’t want to analyze C/C++/Objective-C files, then prevent them from being analyzed by setting the following properties:

sonar.c.file.suffixes=-
sonar.cpp.file.suffixes=-
sonar.objc.file.suffixes=-

INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 9.496s
INFO: Final Memory: 21M/77M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
java.lang.UnsupportedOperationException:

The only way to get an accurate analysis of C/C++/Objective-C files is by using the SonarSource build-wrapper
and setting the property “sonar.cfamily.build-wrapper-output”, but it was not specified.

If you don’t want to analyze C/C++/Objective-C files, then prevent them from being analyzed by setting the following properties:

sonar.c.file.suffixes=-
sonar.cpp.file.suffixes=-
sonar.objc.file.suffixes=-

I then try to follow the hints ->
sonar-scanner -Dsonar.projectKey=test01 -Dsonar.sources=.
-Dsonar.host.url=http://localhost:8082/sonarqube/
-Dsonar.login=57722a09234d5c3dc3c1d11e9d23bbc0d7507af0
-Dsonar.cpp.file.suffixes=-
-Dsonar.objc.file.suffixes=-
-Dsonar.cfamily.build-wrapper-output=bla

INFO: Scanner configuration file: /usr/local/src/sonar-scanner-4.0.0.1744-linux/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarQube Scanner 4.0.0.1744
INFO: Java 11.0.3 AdoptOpenJDK (64-bit)
INFO: Linux 4.15.0-1043-aws amd64
INFO: User cache: /var/lib/jenkins/.sonar/cache
INFO: SonarQube server 7.9.0
INFO: Default locale: “en”, source code encoding: “UTF-8” (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=104ms
INFO: Server id: BF41A1F2-AWvA4nUDPMYzph8vLIYs
INFO: User cache: /var/lib/jenkins/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=45ms
INFO: Load/download plugins (done) | time=159ms
INFO: Loaded core extensions: developer-scanner
INFO: Process project properties
INFO: Execute project builders
INFO: Execute project builders (done) | time=3ms
INFO: Project key: test01
INFO: Base dir: /var/lib/jenkins/workspace/test01_sonarqube
INFO: Working dir: /var/lib/jenkins/workspace/test01_sonarqube/.scannerwork
INFO: Load project settings for component key: ‘test01’
INFO: Load project settings for component key: ‘test01’ (done) | time=105ms
INFO: Load project branches
INFO: Load project branches (done) | time=13ms
INFO: Load project pull requests
INFO: Load project pull requests (done) | time=9ms
INFO: Load branch configuration
INFO: Load branch configuration (done) | time=1ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=81ms
INFO: Detected Jenkins
INFO: Load active rules
INFO: Load active rules (done) | time=4791ms
INFO: Indexing files…
INFO: Project configuration:
INFO: 16 files indexed
INFO: 0 files ignored because of scm ignore settings
INFO: Quality profile for c: Sonar way
INFO: Quality profile for py: Sonar way
INFO: ------------- Run sensors on module test01
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=58ms
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by net.sf.cglib.core.ReflectUtils$1 (file:/var/lib/jenkins/.sonar/cache/a89f1943fc75b65becd9fb4ecab8d913/sonar-tsql-plugin.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte,int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of net.sf.cglib.core.ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
INFO: Sensor JavaXmlSensor [java]
INFO: Sensor JavaXmlSensor [java] (done) | time=1ms
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=13ms
INFO: Sensor Python Squid Sensor [python]
INFO: Load project repositories
INFO: Load project repositories (done) | time=11ms
INFO: Sensor Python Squid Sensor [python] (done) | time=242ms
INFO: Sensor Cobertura Sensor for Python coverage [python]
INFO: Sensor Cobertura Sensor for Python coverage [python] (done) | time=9ms
INFO: Sensor PythonXUnitSensor [python]
INFO: Sensor PythonXUnitSensor [python] (done) | time=1ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=3ms
INFO: Sensor CFamily [cpp]
INFO: Using build-wrapper output: /var/lib/jenkins/workspace/test01_sonarqube/bla/build-wrapper-dump.json
INFO: Available processors: 4
INFO: Using 1 thread for analysis according to value of “sonar.cfamily.threads” property.
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 11.243s
INFO: Final Memory: 21M/77M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
java.lang.IllegalStateException: java.nio.file.NoSuchFileException: /var/lib/jenkins/workspace/test01_sonarqube/bla/build-wrapper-dump.json
at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:290)
at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:205)
at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:62)
at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:400)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:395)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:358)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:141)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:73)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
at com.sun.proxy.$Proxy0.execute(Unknown Source)
at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:185)
at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:137)
at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.nio.file.NoSuchFileException: /var/lib/jenkins/workspace/

The project can essentially be
Makefile
bla.c

Progress: the GUI gives wrong hints :frowning:

This procedure seems to work https://stackoverflow.com/questions/40746933/running-sonarqube-analysis-scan-sonarsource-build-wrapper

Hello @peter.toft,

just follow the documentation https://docs.sonarqube.org/latest/analysis/languages/cfamily/ properly using build-wrapper to wrap you build and passing build-wrapper-output property to sonar-scanner.

build-wrapper-output or sonar.cfamily.build-wrapper-output?

as documented on https://docs.sonarqube.org/latest/analysis/languages/cfamily/.

Thanx!! I managed to get it working, however the problem is that the SonarQube GUI does not give a good hint.

For C/C++ I would have loved to see a link to https://docs.sonarqube.org/latest/analysis/languages/cfamily
It would have been nice to understand also that the scanner I should use can/should be downloaded from my server http://sonarqubehost/static/cpp/build-wrapper-linux-x86.zip