Sonarcloud source inclusion and exclusion

Fairly new to sonar and have a question concerning the sonar.sources and sonar.exclusions in the sonar-project.properties file.

This is for a c++ project and this is the issue I am trying to resolve:

The directory structure is like the following: aLibName/db //which contains .cpp and .h files aLibName/cache // which contains .cpp and .h files and so on with the same structure

When the jenkins we have runs to build it places a /target directory under each of the directories above and copies the .cpp and .h files to it. So I end up with aLibName/db/target //which contains a DUPLICATE of the .cpp and .h files aLibName/cache/target // which contains a DUPLICATE of the .cpp and .h files and so on with the same structure

So what I end up with is a duplicate copy of the .cpp and .h files. Then my sonar scan runs and everything is duplicated with the results, like lines of code, vulnerabilities, …

I am currently getting around it as a test by doing: sonar.sources=mlib/cache,mlib/code sonar.exclusions=mlib/cache/target,mlib/code/target

which is not good… If it was just a couple directories then fine, but I dozens.

So, is there any way to do something like: sonar.sources=mlib sonar.exclusions=“any directory with the name of target”

Thanks for any suggestions.

Formatting was odd…

Fairly new to sonar and have a question concerning the sonar.sources and sonar.exclusions in the sonar-project.properties file.

This is for a c++ project and this is the issue I am trying to resolve:

The directory structure is like the following: aLibName/db //which contains .cpp and .h files

aLibName/cache // which contains .cpp and .h files and so on with the same structure

When the jenkins we have runs to build it places a /target directory under each of the directories above and copies the .cpp and .h files to it. So I end up with

aLibName/db/target //which contains a DUPLICATE of the .cpp and .h files

aLibName/cache/target // which contains a DUPLICATE of the .cpp and .h files

and so on with the same structure

So what I end up with is a duplicate copy of the .cpp and .h files. Then my sonar scan runs and everything is duplicated with the results, like lines of code, vulnerabilities, …

I am currently getting around it as a test by doing:
sonar.sources=mlib/cache,mlib/code sonar.exclusions=mlib/cache/target,mlib/code/target

which is not good… If it was just a couple directories then fine, but I dozens.

So, is there any way to do something like: sonar.sources=mlib sonar.exclusions=“any directory with the name of target”

Thanks for any suggestions.

Hi @bapserver

I think that something like this : sonar.exclusions=**/target/*.*

should work for you. Could you try and let us know ?

HTH,
Mickaël

I’ll give it a try. I have had some limited success with:

sonar.exclusions=mlb//DownloadTest,mlib//target

The “target” subdirectories are excluded but it appears the “DownloadTest” ones are not. I have tried reversing the order without success. Not sure if I just comma delimit them or have multiple exclusion lines or what. I don’t get the double asterisk syntax though…

Lost my asterisks on my reply…

mlib//DownloadTest,mlib//target

OK, can’t put asterisks in for some reason.

mlib/“two asterisks”/DownloadTest,mlib/“two asterisks”/target

Is the mlib folder at the same level of where your scanner is launched ? Paths are relative, if mlib is one or 2 level deeper, then you should as well put 2 asterisks before. And, to correctly match the pattern, i would suggest also to add a “/*” after each directory exclusion, like,

mlib/“double asterisk”/DownloadTest/*

It seems like the following gets me where I want to be:

sonar.exclusions=app/XXXX/tests/XXXX,mlib/XXXX/restclient-tests/XXXX,mlib/XXXX/restclient-mocks/XXXX,mlib/XXXX/DownloadTest/XXXX,mlib/XXXX/target/XXXX,app/XXXX/target/XXXX

where XXXX represents double asterisks

Great to read, does that solve your issue ?

Yes it does, thanks

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.