禁用特定 java 包的所有 checkstyle 检查
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4020478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disable all checkstyle checks for a specific java package
提问by Sibi JV
I have two packages namely
我有两个包
com/mydomain/abc/delegate/xyz/jaxws/managed
com/mydomain/abc/delegate/xyz/jaxws/managed
and com/mydomain/abc/xyz/jaxws/managed
和 com/mydomain/abc/xyz/jaxws/managed
I require checkstyle to be disabled only for the second package as these holds proxy classes that are autogenerated.
我需要仅对第二个包禁用 checkstyle,因为它们包含自动生成的代理类。
I use a suppression.xml as shown below
我使用如下所示的suppression.xml
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
"suppressions_1_1.dtd">
<suppressions>
<!-- Suppress JavadocPackage in the test packages -->
<suppress checks="JavadocPackage" files="[\/]test[\/]"/>
<!-- Suppress all checkstyle for autogenerated jaxws.managed package -->
<suppress checks="[a-zA-Z0-9]*" files="([^(delegate)])+([a-z]*[\/]jaxws[\/]managed[\/])+"/>
</suppressions>
Please note the first suppression for disabling JavadocPackage check works fine but the second one does not. I am afraid that my regex for selecting the package might be wrong. Any help is much appreciated.
请注意禁用 JavadocPackage 检查的第一个抑制工作正常,但第二个没有。我担心我选择包的正则表达式可能是错误的。任何帮助深表感谢。
To state my requirements with an example:
举例说明我的要求:
The criteria for selection is that the package name should end in jaxws.managed
but should not contain delegate
in package name. More over delegate
should come before jaxws.managed
in the package name:
选择的标准是包名应以包名结尾,jaxws.managed
但不应包含delegate
在包名中。更多的delegate
应该出现jaxws.managed
在包名之前:
eg: checktyle checks in package com.mycomany.delegate.service.jaxws.managed
must be enabled while that in com.mycompany.abc.service.jaxws.service
must be disabled and it is to be noted that I do not know all the pakages names upfront except for this pattern.
例如:com.mycomany.delegate.service.jaxws.managed
必须启用包中的检查类型检查,而com.mycompany.abc.service.jaxws.service
必须禁用该检查,需要注意的是,除此模式外,我不知道所有包的名称。
Thanks and Regards Sibi
感谢和问候 Sibi
回答by Oliver
Just use the suppression:
只需使用抑制:
<suppress checks="." files="com[\/]mydomain[\/]abc[\/]xyz[\/]jaxws[\/]managed[\/]"/>
Alternatively, I would recommend only passing the files you want checked to Checkstyle. For example, if you are using ANT, use a to specify the files to process, and use to specify files to ignore.
或者,我建议只将您要检查的文件传递给 Checkstyle。例如,如果您使用 ANT,请使用 a 指定要处理的文件,并使用指定要忽略的文件。
For example:
例如:
<fileset dir="src">
<include name="**/*.java"/>
<exclude name="com/mycompany/abc/service/jaxws/service/*.java"/>
</fileset>
回答by aha
(?! delegate \b) [\/][a-z]*[\/]jaxws[\/]managed[\/]
(?! 委托 \b) [\/][az]*[\/]jaxws[\/]managed[\/]