Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 665
John Meyer Avatar asked Jun 09 '16 16:06

John Meyer


People also ask

How do I exclude files in Sonar properties?

To use exclusions to analyze only the specified subset(s) of files in sonar. sources , go to Project Settings > General Settings > Analysis Scope > Files. You can set these properties at both the project and global levels.

How do I exclude files in Sonarcloud?

Exclusions and inclusions can be set either in the UI or by key. In the UI the settings are under: Your Organization > Your Project > Administration > General Settings > Analysis Scope > Files.

How do you ignore Sonar rules?

In Java, we can exclude Sonar checks using the built-in @SuppressWarnings annotation. This works exactly the same way as suppressing compiler warnings. All we have to do is specify the rule identifier, in this case java:S106.


1 Answers

I just ran into the same problem. I needed to exclude javascript files in a Project, "My Project", in a folder Scripts. I tried this first:

**/Scripts/**/*.js

And that worked fine, but I realized it would exclude a "Scripts" folder in other projects too. So I changed it to this:

**/My Project/Scripts/**/*.js

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:

Scripts/**/*.js

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.

like image 130
PeterH Avatar answered Oct 09 '22 22:10

PeterH