Hello,
I’m trying to setup scans for our C++ project. The configuration is completed and analysis is happening too. However facing difficulties in setting the exclusion correctly. Below is my code snippet
if [[ ${Project,,} == "app1" ]]; then
source_dir="/src/app1"
sonar_exclusion="usr/*,*/build/src/ndd/*,cache/*,entity/*,messages/*,*/src/main/*,*/src/app1/tools/file.hpp,*/src/scheduler/*,*conan/*,boost/*,6.3.1/*,/opt/*,*app1/tz.cpp,*app1/date/*"
elif [[ ${Project,,} == "app2" ]]; then
source_dir="/src/app2"
sonar_exclusion="**/app2/src/base/date/*,**/app2/src/base/ndd/*,**/app2/src/base/tz.cpp,**/app2/src/base/boost/**,**/app2/src/base/oidc*"
fi
sonar-scanner-4.6.2.2472-linux/bin/sonar-scanner -X \
-Dsonar.cfamily.build-wrapper-output=$SONAR_DIR/output \
-Dsonar.projectKey="${Sonar_key}" \
-Dsonar.host.url="${SONAR_HOST_URL}" \
-Dsonar.token="${Sonar_token}" \
-Dsonar.branch.name="${Coverage_branch}" \
-Dsonar.projectBaseDir="${source_dir}/src" \
-Dsonar.cfamily.gcov.reportsPath="${coverage_dir}" \
-Dsonar.exclusions="${sonar_exclusion}"
The exclusions are not working for all the directories. Below is the log for app2 -
INFO: Scanner configuration file: /root/sonar/sonar-scanner-4.6.2.2472-linux/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.6.2.2472
INFO: Java 11.0.11 AdoptOpenJDK (64-bit)
INFO: Linux 5.10.43-flatcar amd64
INFO: User cache: /root/.sonar/cache
INFO: Scanner configuration file: /root/sonar/sonar-scanner-4.6.2.2472-linux/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: Analyzing on SonarQube server 10.2.1.78527
INFO: Default locale: "en_US", source code encoding: "US-ASCII" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=777ms
INFO: Server id: xxxxxxxxxxxxxxxxxx
INFO: User cache: /root/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=184ms
INFO: Load/download plugins (done) | time=64502ms
INFO: Loaded core extensions: developer-scanner
WARN: SonarScanner will require Java 17 to run, starting in SonarQube 10.3
INFO: Process project properties
INFO: Process project properties (done) | time=1ms
INFO: Execute project builders
INFO: Execute project builders (done) | time=2ms
INFO: Project key: xxxxxxxxxxxxxxxxx
INFO: Base dir: /src/app2/src
INFO: Working dir: /src/app2/src/.scannerwork
INFO: Load project settings for component key: 'xxxxxxxxxxxxxxxxx'
INFO: Load project settings for component key: 'xxxxxxxxxxxxxxxxx' (done) | time=134ms
INFO: Load project branches
INFO: Load project branches (done) | time=127ms
INFO: Load branch configuration
INFO: Found manual configuration of branch/PR analysis. Skipping automatic configuration.
INFO: Load branch configuration (done) | time=2ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=181ms
INFO: Load active rules
INFO: Load active rules (done) | time=6750ms
INFO: Load analysis cache
INFO: Load analysis cache | time=240ms
INFO: Branch name: develop
INFO: Load project repositories
INFO: Load project repositories (done) | time=140ms
INFO: Indexing files...
INFO: Project configuration:
INFO: Excluded sources: **/app2/src/base/ndd/*, **/app2/src/base/date/*, **/app2/src/base/abc.cpp, **/app2/src/base/boost/**, **/app2/src/base/oidc*
INFO: 92 files indexed
INFO: 0 files ignored because of inclusion/exclusion patterns
INFO: 1 file ignored because of scm ignore settings
INFO: Quality profile for c: Sonar way
INFO: Quality profile for cpp: Nasdaq Sonar way
INFO: Quality profile for py: Sonar way
INFO: ------------- Run sensors on module xxxxxxxxxxxxxxxxx
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=142ms
INFO: Sensor C# Project Type Information [csharp]
INFO: Sensor C# Project Type Information [csharp] (done) | time=1ms
INFO: Sensor C# Analysis Log [csharp]
INFO: Sensor C# Analysis Log [csharp] (done) | time=18ms
INFO: Sensor C# Properties [csharp]
INFO: Sensor C# Properties [csharp] (done) | time=0ms
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=4ms
INFO: Sensor TextAndSecretsSensor [text]
INFO: 69 source files to be analyzed
INFO: 69/69 source files have been analyzed
INFO: Sensor TextAndSecretsSensor [text] (done) | time=1774ms
INFO: Sensor VB.NET Project Type Information [vbnet]
INFO: Sensor VB.NET Project Type Information [vbnet] (done) | time=3ms
INFO: Sensor VB.NET Analysis Log [vbnet]
INFO: Sensor VB.NET Analysis Log [vbnet] (done) | time=19ms
INFO: Sensor VB.NET Properties [vbnet]
INFO: Sensor VB.NET Properties [vbnet] (done) | time=0ms
INFO: Sensor gcov [cpp]
Below files and directories never gets excluded -
-
**/app2/src/base/date/
-
**/app2/src/base/tz.cpp
Tried with /src/base/date too nothing is working.
Some of the directories is getting excluded for ex., **/app2/src/base/ndd/*, but how its working for some dir, i’m not understanding.
On enabling debug found below 2 line for **/app2/src/base/tz.cpp and **/app2/src/base/date/
12:30:02.150 INFO: Cache hit for: /src/app2/src/base/tz.cpp
12:30:04.745 DEBUG: Detection of duplications for /src/app2/src/base/tz.cpp
However the same was not found for /ndd.