I am trying to use SonarScanner to scan a C language program and send it over to SonarQube but I am being shown "The main branch has no lines of code." while the SonarScanner says "Analysis Success" and "Execution Success".
OS VERSION : Windows 10
STEPS FOLLOWED:
-
I created a project manually and chose "Other (for JS, TS, Go, Python, PHP) as the build of the code instead of .NET, Maven or Gradle.
-
In the conf folder, I added the last 3 lines to the content of the Sonar-Scanner properties source file:
#Configure here general information about the environment, such as SonarQube server connection details for example
#No information about specific project should appear here
#----- Default SonarQube server
#sonar.host.url=http://localhost:9000
#----- Default source code encoding
#sonar.sourceEncoding=UTF-8
sonar.host.url=http://localhost:9000
sonar.projectKey=CarbonFootprintCalculator
sonar.sources=D:New folder
- I ran the following command in the same folder as my code (New Folder in D Drive) to send it to Localhost:9000 using SonarScanner:
sonar-scanner.bat -D"sonar.projectKey=CarbonFootprintCalculator" -D"sonar.sources=D:New folder." -D"sonar.host.url=http://localhost:9000" -D"sonar.token=sqp_5e9cdc0c9da90779005ed42275dfa52e2a2fc08c"
- The output of the above command was as follow:
INFO: Scanner configuration file: C:sonarscannersonar-scanner-4.8.0.2856bin..confsonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.8.0.2856
INFO: Java 17.0.7 Oracle Corporation (64-bit)
INFO: Windows 10 10.0 amd64
INFO: User cache: C:UsersYash Anand.sonarcache
INFO: Analyzing on SonarQube server 10.0.0.68432
INFO: Default locale: "en_US", source code encoding: "windows-1252" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=189ms
INFO: Server id: 147B411E-AYfbfneOwzIRF7Nr5PrQ
INFO: User cache: C:UsersYash Anand.sonarcache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=109ms
INFO: Load/download plugins (done) | time=423ms
INFO: Process project properties
INFO: Process project properties (done) | time=37ms
INFO: Execute project builders
INFO: Execute project builders (done) | time=5ms
INFO: Project key: CarbonFootprintCalculator
INFO: Base dir: D:New folder
INFO: Working dir: D:New folder.scannerwork
INFO: Load project settings for component key: 'CarbonFootprintCalculator'
INFO: Load project settings for component key: 'CarbonFootprintCalculator' (done) | time=47ms
WARN: SCM provider autodetection failed. Please use "sonar.scm.provider" to define SCM of your project, or disable the SCM Sensor in the project settings.
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=139ms
INFO: Load active rules
INFO: Load active rules (done) | time=4544ms
INFO: Load analysis cache
INFO: Load analysis cache (404) | time=22ms
INFO: Load project repositories
INFO: Load project repositories (done) | time=73ms
INFO: Indexing files...
INFO: Project configuration:
INFO: 1 file indexed
INFO: ------------- Run sensors on module CarbonFootprintCalculator
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=81ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=18ms
INFO: Sensor CSS Rules [javascript]
INFO: No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
INFO: Sensor CSS Rules [javascript] (done) | time=5ms
INFO: Sensor C# Project Type Information [csharp]
INFO: Sensor C# Project Type Information [csharp] (done) | time=9ms
INFO: Sensor C# Analysis Log [csharp]
INFO: Sensor C# Analysis Log [csharp] (done) | time=54ms
INFO: Sensor C# Properties [csharp]
INFO: Sensor C# Properties [csharp] (done) | time=2ms
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=11ms
INFO: Sensor TextAndSecretsSensor [text]
INFO: Sensor TextAndSecretsSensor [text] (done) | time=33ms
INFO: Sensor VB.NET Project Type Information [vbnet]
INFO: Sensor VB.NET Project Type Information [vbnet] (done) | time=5ms
INFO: Sensor VB.NET Analysis Log [vbnet]
INFO: Sensor VB.NET Analysis Log [vbnet] (done) | time=56ms
INFO: Sensor VB.NET Properties [vbnet]
INFO: Sensor VB.NET Properties [vbnet] (done) | time=3ms
INFO: Sensor IaC Docker Sensor [iac]
INFO: 0 source files to be analyzed
INFO: 0/0 source files have been analyzed
INFO: Sensor IaC Docker Sensor [iac] (done) | time=367ms
INFO: ------------- Run sensors on project
INFO: Sensor Analysis Warnings import [csharp]
INFO: Sensor Analysis Warnings import [csharp] (done) | time=6ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=20ms
INFO: SCM Publisher No SCM system was detected. You can use the 'sonar.scm.provider' property to explicitly specify it.
INFO: CPD Executor Calculating CPD for 0 files
INFO: CPD Executor CPD calculation finished (done) | time=0ms
INFO: Analysis report generated in 326ms, dir size=124.7 kB
INFO: Analysis report compressed in 242ms, zip size=14.8 kB
INFO: Analysis report uploaded in 104ms
INFO: ANALYSIS SUCCESSFUL, you can find the results at: http://localhost:9000/dashboard?id=CarbonFootprintCalculator
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://localhost:9000/api/ce/task?id=AYfhim_X6pznqzcwOF0s
INFO: Analysis total time: 16.530 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 20.808s
INFO: Final Memory: 16M/57M
INFO: ------------------------------------------------------------------------
Additionally, I would like to add that opening “INFO: More about the report processing at http://localhost:9000/api/ce/task?id=AYfhim_X6pznqzcwOF0s” from the above output would lead to the following message being shown:
{"task":{"id":"AYfhim_X6pznqzcwOF0s","type":"REPORT","componentId":"AYfhY8l46pznqzcwOF0c","componentKey":"CarbonFootprintCalculator","componentName":"CarbonFootprintCalculator","componentQualifier":"TRK","analysisId":"AYfhinbEwzRX02DmXAyy","status":"SUCCESS","submittedAt":"2023-05-03T17:45:58+0530","submitterLogin":"admin","startedAt":"2023-05-03T17:46:00+0530","executedAt":"2023-05-03T17:46:05+0530","executionTimeMs":4695,"hasScannerContext":true,"warningCount":2,"warnings":[]}}
I am attaching the screenshot of the SonarQube dashboard as well as the Solar-Scanner properties source file below. Kindly please help me fix this issue:
https://phpout.com/wp-content/uploads/2023/07/EAKzi-jpg.webp
I tried to ensure that the Sonar-Scanner properties source file in the conf folder had been edited properly by me. Additionally, I ensured there wasn’t any internet connection related issue. I also made sure SonarQube was running throughout the process.
2
Answers
The reason due to which I was unable to see find the code report was that SonarCube's community version does not support C language. In order to work with C Language, you will be needing to upgrade to SonarCube's enterprise or developer's edition.
You can learn more about the supported languages of various SonarCube editions by clicking the link provided below:
https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/languages/overview/
To scan a C, C++, or Objective-C project, you need to use the build-wrapper. You can’t scan a C/C++/Objective-C project directly. You have to run the build-wrapper (which wraps your clean build command) and then you run the sonar-scanner.
Questions to consider:
Examples:
See more here: https://docs.sonarqube.org/latest/analyzing-source-code/languages/c-family/
In the future, you should go to https://community.sonarsource.com and create a thread there for help. Sonar devs/managers operate in their own forum, not StackOverflow.