FindBugs的问题排除过滤器 [英] Problems with FindBugs exclude filter

查看:241
本文介绍了FindBugs的问题排除过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在评估FindBugs,并且正在尝试使用excludeFilter,以便该工具不处理测试包或生成的ejb存根.

I am in the process of evaluating FindBugs and am trying to make use of the excludeFilter so that the tool does not process the test packages or the generated ejb stubs.

我尝试了以下操作:

<FindBugsFilter>
<!-- Match any test packages -->
<Match>
    <Package name="~.*\.test"/>
</Match>
<Match>
    <Or>
        <Class name="~.*\.^_*"/>
        <Class name="~.*EJS*"/>
    </Or>
    <Bug pattern="MALICIOUS_CODE"/>
</Match>

仍在查看生成的EJB.有人可以为此提供更好的指导吗.

The generated EJB's are still being looked at. Can someone provide some better direction on this.

我想排除所有以"_"开头的类

I want to exclude out all classes that start with "_"

示例:

com/mycompany/business/admin/ejb/_AdminRemoteHome_Stub.java

com/mycompany/business/admin/ejb/_AdminRemoteHome_Stub.java

com/mycompany/business/admin/ejb/_EJSRemoteStatelessAdminHome_054d51b9_Tie.java

com/mycompany/business/admin/ejb/_EJSRemoteStatelessAdminHome_054d51b9_Tie.java

更新的过滤器文件.

我使用建议的regx更改将过滤器文件更改为以下结构,现在一切正常:

I change the filter file to the following structure using the suggested regx changes and now things are working as expected:

<FindBugsFilter>
<!-- Match any test packages -->
<Match>
    <Package name="~.*\.test"/>
</Match>
<Match>
    <Class name="~.*\._.*"/>
</Match>
<Match>
    <Class name="~.*?EJS.*"/>       
</Match>

好像我需要回去重新刷一下regx.

Looks like I need to go back and brush up on my regx.

推荐答案

关于 FindBugFilter

(请确定),您确定要考虑的是已编译的类文件目录,而不是sourcePath吗? (如 SO答案中所述).

(just to be sure) are you sure you are considering the compiled class files directories, and not the sourcePath? (as mentioned in this SO answer).

Java元素名称匹配部分:

如果Class,Method或Field的name属性以〜字符开头,则其余的属性内容将解释为与所讨论的Java元素的名称匹配的 Java正则表达式.

以下正则表达式会更准确吗?

Would the following regex be more accurate?

    <Class name="~.*\._.*"/>
    <Class name="~.*?EJS.*"/>

  • ".*\._.*"而不是".*\.^_*",因为 anchor 应该在应用正则表达式模式的字符串的开头匹配.

    • ".*\._.*" instead of ".*\.^_*" because the anchor is supposed to match at the start of the string the regex pattern is applied to.

      ".*?EJS.*"而不是".*EJS*",因为? quantifier 使匹配变得很懒,避免吃掉" EJS. (加号"S*"表示"0或n S",此处无济于事)

      ".*?EJS.*" instead of ".*EJS*" because the ? quantifier makes the matching lazy, avoiding to 'eat' EJS. (Plus "S*" means "0 or n S", which does not help here)

      这篇关于FindBugs的问题排除过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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