How to exclude files with spaces in the path in Sonar?
I am trying to exclude some auto generated code (Service References) from Sonars static code and unit test coverage analysis. The project is C# .Net and Sonar is running via Jenkins on a Windows server.
Within my sonar-project.properties file I am able to exclude various other files and directories by using the sonar.exclusions property, but this is not working for files that have a space in the path.
sonar.exclusions=**/Global.asax.cs, **/MyProject/Service References/*
Given the above example the Global.asax.cs files are excluded in all projects within the solution, but the Service References are not.
I have tried enclosing the path in single and double quotes.
I have tried using a backslash to escape the space.
I have tried putting the path as **/MyProject/Service*/* to take advantage of the wildcard (could be risky) but that didn’t work either.
Does anyone have a solution for this?
One Solution collect form web for “How to exclude files with spaces in the path in Sonar?”
And that worked fine, but I realized it would exclude a “Scripts” folder in other projects too. So I changed it to this:
And it stopped working. My first instinct was that the space in the project name was to blame. So i tried the same things you did:
"**/My Project/Scripts/**/*.js" '**/My Project/Scripts/**/*.js' **/My\ Project/Scripts/**/*.js
but none of it worked.
Then I stumbled upon this forum: sonarqube-archive.15.x6.nabble.com/Project-exclusions-for-Code-Coverage-not-working-C-td5023058.html
Particularly this line provided the answer: Modules (.Net projects) are not part of the fully qualified name. You must define exclusions at module (.Net project) level.
It means that my mistake wasn’t having a space in the project name, but including the project name at all! I changed the filter to this:
and voila, the files were correctly excluded. No quotes or escaping necessary.
Of course, this still leaves the problem that a “Scripts” folder in another project wil also be excluded. The information provided here: docs.sonarqube.org/display/SCAN/Excluding+Artifacts+from+the+Analysis may prove useful for that.
I use the web interface, and not the configuration file directly, but this would also suggest that if you have multiple filters, that the comma-separated list should not contain spaces (other than the ones actually in the path) because they are interpreted quite literally.