如何在Sonar中排除路径中带有空格的文件? [英] How to exclude files with spaces in the path in Sonar?

查看:96
本文介绍了如何在Sonar中排除路径中带有空格的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Sonars静态代码和单元测试覆盖率分析中排除一些自动生成的代码(服务参考).该项目为C#.Net,Sonar通过Jenkins在Windows服务器上运行.

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.

在我的sonar-project.properties文件中,我可以使用sonar.exclusions属性排除其他各种文件和目录,但这不适用于路径中有空格的文件.

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/*

鉴于上面的示例,解决方案中的所有项目中都排除了Global.asax.cs文件,但服务引用并未排除.

Given the above example the Global.asax.cs files are excluded in all projects within the solution, but the Service References are not.

我尝试用单引号和双引号将路径引起来. 我尝试使用反斜杠来逃避空间. 我尝试将路径设置为**/MyProject/Service */*来利用通配符(可能有风险),但这也不起作用.

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?

推荐答案

我只是遇到了同样的问题.我需要在脚本"文件夹中的我的项目"项目中排除javascript文件.我首先尝试了这个:

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

那很好,但是我意识到它也将在其他项目中排除"Scripts"文件夹.所以我将其更改为:

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

但没有一个起作用.

然后我偶然发现了这个论坛:

Then I stumbled upon this forum: sonarqube-archive.15.x6.nabble.com/Project-exclusions-for-Code-Coverage-not-working-C-td5023058.html

特别是此行提供了答案:模块(.Net项目)不是完全限定名称的一部分.您必须在模块(.Net项目)级别定义排除项.

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.

当然,这仍然存在一个问题,即另一个项目中的"Scripts"文件夹也将被排除.此处提供的信息: docs.sonarqube.org/display/SCAN/从+分析中排除+工件可能被证明是有用的.

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.

我使用的是Web界面,而不是直接使用配置文件,但这也建议如果您有多个过滤器,以逗号分隔的列表中不应包含空格(路径中的空格除外),因为它们被完全按字面解释.

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.

这篇关于如何在Sonar中排除路径中带有空格的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆