AFAIK These follow Ant style patterns. So doing this in your sonar-project.properties
file should work:
sonar.coverage.exclusions = \
**/B/B1/**,\
**/B/B2/**,\
**/B/B3/**
Or single line:
sonar.coverage.exclusions = **/B/B1/**, **/B/B2/**, **/B/B3/**
It might be possible to use a regex pattern, if sonar uses Spring under the hood, but I have zero idea if that’s actually supported.
sonar.coverage.exclusions = **/B/{subdir:B[1-3]}/**
What we do is that we actually have a wrapper before calling the sonar scanner. This wrapper sets environment variables, such as directories to exclude and these variables are then passed to the properties file.
sonar.coverage.exclusions = \
${env.SONAR_ADDITIONAL_COVERAGE_EXCLUSIONS}\
test/**,\
**/setup.py
And in your case the code in a shell script wrapper would look like:
SONAR_ADDITIONAL_COVERAGE_EXCLUSIONS=''
for dir in B/B{1,2,3}; do
SONAR_ADDITIONAL_COVERAGE_EXCLUSIONS="${SONAR_ADDITIONAL_COVERAGE_EXCLUSIONS}**/${dir}/**,"
done
export SONAR_ADDITIONAL_COVERAGE_EXCLUSIONS
SONAR_ADDITIONAL_COVERAGE_EXCLUSIONS is just a name we picked to be very unique, you can pick whatever you like.
Of course if you goal is to avoid repeating for just 3 directories, that’s not very efficient, but for larger use cases it might work for you.
Let us know if these work. I’m actually curious about the regex option. It is undocumented so it might not be future proof, even if it works today.
Update: After looking at the docs it seems that **
is only for folders, so you might need to finish your patterns with **/*
to actually exclude files.