简体   繁体   English

Eclipse + FindBugs - 排除过滤器文件不起作用

[英]Eclipse+FindBugs - exclude filter files doesn't work

I'm using Windows and Eclipse 3.7 Classic with ADT plugin for Android development. 我正在使用Windows和Eclipse 3.7 Classic和ADT插件进行Android开发。

I've just installed FindBugs and it have found a bug in auto-generated R.java class. 我刚刚安装了FindBugs,它在自动生成的R.java类中发现了一个错误。

I want to exclude this class from FindBugs checks. 我想从FindBugs检查中排除这个类。

I've found that I can define exclude filters for FindBugs in xml file, so I've created a file D:\\Projects\\eclipse\\FindBugsExculde.xml with text 我发现我可以在xml文件中为FindBugs定义排除过滤器,所以我创建了一个带文本的文件D:\\ Projects \\ eclipse \\ FindBugsExculde.xml

<FindBugsFilter>
  <Match>
    <Class name="com.android.demo.notepad3.R$attr" />
  </Match>
</FindBugsFilter>

I've added this file to Eclipse -> Window -> Preferences -> Java -> FindBugs -> Filter files -> "Add..." button near the "Exclude filter files" section. 我已将此文件添加到Eclipse - > Window - > Preferences - > Java - > FindBugs - > Filter files - >“Add ...”按钮附近的“Exclude filter files”部分。

But when I right-click on my project and select "Find Bugs" -> "Find Bugs" I still see the error 但是当我右键单击我的项目并选择“Find Bugs” - >“Find Bugs”时,我仍然会看到错误

The class name com.android.demo.notepad3.R$attr doesn't start with an upper case letter

I have even tried to replace 我甚至试图更换

<Class name="com.android.demo.notepad3.R$attr" />

with

<Class name="~.*" />

but still the error is there. 但仍然存在错误。

I tried to restart Eclipse - no luck. 我试图重启Eclipse - 没有运气。 I even thought that maybe there is a Bug in FindBugs so it doesn't use the file specified but Procmon.exe from SysinternalsSuite shows that it do use it each time I execute FindBugs: 我甚至认为可能在FindBugs中有一个Bug,所以它不使用指定的文件,但SysinternalsSuite的Procmon.exe显示它每次执行FindBugs时都会使用它:

ProcessName Operation   Path                                    Result
javaw.exe   QueryOpen   D:\Projects\eclipse\FindBugsExculde.xml SUCCESS
javaw.exe   QueryOpen   D:\Projects\eclipse\FindBugsExculde.xml SUCCESS
javaw.exe   CreateFile  D:\Projects\eclipse\FindBugsExculde.xml SUCCESS
javaw.exe   CreateFile  D:\Projects\eclipse\FindBugsExculde.xml SUCCESS
javaw.exe   QueryFileInternalInformationFile D:\Projects\eclipse\FindBugsExculde.xml SUCCESS
javaw.exe   CloseFile   D:\Projects\eclipse\FindBugsExculde.xml SUCCESS
javaw.exe   ReadFile    D:\Projects\eclipse\FindBugsExculde.xml SUCCESS
javaw.exe   CloseFile   D:\Projects\eclipse\FindBugsExculde.xml SUCCESS

What am I doing wrong? 我究竟做错了什么? Please help me! 请帮我!

Following the directives from Jenkins I created a findbugs-exclude.xml in my android workspace and added it via Eclipse -> Window -> Preferences -> Java -> FindBugs -> Filter files -> "Add..." button near the "Exclude filter files" section to findbugs. 遵循Jenkins的指令,我在我的android工作区创建了一个findbugs-exclude.xml ,并通过Eclipse - > Window - > Preferences - > Java - > FindBugs - > Filter files - >“Add ...”按钮附近添加了它排除过滤器文件“部分到findbugs。 My first error was that I ticked the first checkbox (the include filter :-) section). 我的第一个错误是我勾选了第一个复选框(包含过滤器:-)部分)。

Then I started manually findbugs and everything was ok. 然后我开始手动findbugs,一切都很好。 The content of my file is: 我的文件内容是:

<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
    <Match>
        <Class name="~.*\.R\$.*"/>
    </Match>
    <Match>
    <Class name="~.*\.Manifest\$.*"/>
    </Match>
</FindBugsFilter>

I am using eclipse 3.7.1 and findbugs 1.3.9. 我正在使用eclipse 3.7.1和findbugs 1.3.9。 Hope that helps. 希望有所帮助。

I just want to remind newbie that "Default Settings" is apply on new project , so you can't just exclude your filter in "Default Settings" if you want to apply it in current project: 我只想提醒新手“默认设置” 适用于新项目 ,因此如果要在当前项目中应用它,则不能只在“默认设置”中排除过滤器:

在此输入图像描述

instead you should exclude your filter in "Settings": 相反,您应该在“设置”中排除您的过滤器:

在此输入图像描述

btw, once plugin installed and restart, Android Studio may pop up dialog on right bottom, you just have to click that link Add R.class File Filter , it will automatically generate the correct xml code for you. 顺便说一句,一旦插件安装并重新启动,Android Studio可能会弹出右下角的对话框,你只需要点击该链接添加R.class文件过滤器 ,它就会自动为你生成正确的xml代码。

在此输入图像描述

在此输入图像描述

Filter file may be ignored silently when path to file is incorrect or when XML file is not valid. 当文件路径不正确或XML文件无效时,可以静默忽略过滤器文件。 Try to validate filter using XSD from https://raw.githubusercontent.com/findbugsproject/findbugs/master/findbugs/etc/findbugsfilter.xsd . 尝试使用来自https://raw.githubusercontent.com/findbugsproject/findbugs/master/findbugs/etc/findbugsfilter.xsd的 XSD验证过滤器。

Had this problem on Eclipse 4.4.2. 在Eclipse 4.4.2上有这个问题。

Please delete the error manually. 请手动删除错误。 Select the error and right click, select Delete. 选择错误并右键单击,选择“删除”。 Then rebuild your project. 然后重建您的项目。

It could be that findbugs is ignoring the file correctly, but that doesn't mean that the errors it has previously raised on the file get deleted, they still exist, and you have to delete them manually. 可能是findbugs正确地忽略了文件,但这并不意味着先前在文件中引发的错误被删除,它们仍然存在,您必须手动删除它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM