如何从检查操作中排除某些文件

问题描述 投票:0回答:2
java formatting code-formatting checkstyle
2个回答
3
投票

经过长时间的尝试,我找到了解决方案。我给出路径的格式是错误的。正确的格式应该是这样的:

    <module name="BeforeExecutionExclusionFileFilter">
    <property name="fileNamePattern" value="[/\\]src[/\\]main[/\\]java[/\\]package1"/>
    </module>

    <module name="BeforeExecutionExclusionFileFilter">
        <property name="fileNamePattern" value="[/\\]src[/\\]main[/\\]java[/\\]package2"/>
    </module>

如果我们想忽略多个包,这就是我们应该做的。给予两个同名的财产是行不通的。希望这对其他人有帮助。


0
投票

您的问题是

fileNamePattern
被视为正则表达式,因此
package1/*.java
中的通配符不会匹配类名字母,但将是
/
的量词。

另外,让我们考虑一下 checkstyle 中的排除逻辑代码(截至 2023 年 9 月 10 日):

public boolean accept(String uri) {
    return fileNamePattern == null || !fileNamePattern.matcher(uri).find();
}

由于它使用

find
,而不是
match
,公共路径可以省略,并且您可以使用正则表达式
or
表达式,因此您的xml可能会被剥离为

<module name="BeforeExecutionExclusionFileFilter">
    <property name="fileNamePattern" value="package1|package2"/>
</module>
© www.soinside.com 2019 - 2024. All rights reserved.