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

查看:32
本文介绍了如何在 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?

推荐答案

我也遇到了同样的问题.我需要在文件夹 Scripts 中排除项目我的项目"中的 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

效果很好,但我意识到它也会在其他项目中排除脚本"文件夹.所以我把它改成了这样:

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

但没有任何效果.

然后我偶然发现了这个论坛:sonarqube-archive.15.x6.nabble.com/Project-exclusions-for-Code-Coverage-not-working-C-td5023058.html

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.

当然,这仍然会留下另一个项目中的脚本"文件夹也会被排除在外的问题.此处提供的信息:docs.sonarqube.org/display/SCAN/排除+Artifacts+from+the+Analysis可能对此有用.

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天全站免登陆