Eclipse FindBugs插件的安装与使用

来源:互联网 发布:ee域名续费 编辑:程序博客网 时间:2024/05/01 23:09
1 什么是FindBugs
FindBugs 是一个静态分析工具,它检查类或者 JAR 文件,将字节码与一组缺陷模式进行对比以发现可能的问题。有了静态分析工具,就可以在不实际运行程序的情况对软件进行分析。不是通过分析类文件的形式或结构来确定程序的意图,而是通常使用 Visitor 模式来鉴别代码是否符合一些固定的规范。
2 如何安装FindBugs?
作为Eclipse的一个插件,可以将Findbugs集成到Eclipse中使用。
第一种是在线安装:在Eclipse的插件安装地址中输入http://findbugs.cs.umd.edu/eclipse并一路“next”就可安装成功。
第二种方式是下载Findbugs插件,将它放入Eclipse下的plusin文件夹,然后重启Eclipse即可。
3如何使用FindBugs
安装了Findbugs插件后。右击点击你要检查的项目选择【Find Bugs】->【Find Bugs】进行检查。要查看Findbugs检查出了哪些Bug,可以选择Windows菜单->Show View->Bug Explorer,打开Bug Explorer面板。如果想要查看某个Bug详细的信息,则可以选择Windows菜单->Open Perspective,然后选择FindBugs就可以打开FindBugs的Properties面板,在这个面板里面可以看到最详尽的Bugs信息。
4 FindBugs能发现的所有Bug类型
FindBugs 网站http://findbugs.sourceforge.net/bugDescriptions.html提供了完整的类型清单。
To install the FindBugs plugin:
  1. In Eclipse, click on Help -> Software Update -> Find and Install...
  2. Choose the Search for new features to install option, and click Next.
  3. Click New Remote Site.
  4. Enter the following:
    • Name: FindBugs update site
    • URL: one of the following (note: no final slash on the url)
      • http://findbugs.cs.umd.edu/eclipse for official releases
      • http://findbugs.cs.umd.edu/eclipse-candidate for candidate releases and official releases
      • http://findbugs.cs.umd.edu/eclipse-daily for all releases, including developmental ones
    and click OK.
  5. "FindBugs update site" should appear under Sites to include in search
    Click the checkbox next to it to select it, and click Finish.
  6. You should see FindBugs Feature under Select features to install
    (You may have to click on one or two triangles to make it visible in the tree.)
    Select the checkbox next to it and click next.
  7. Select the I accept option to accept the license and click Next.
  8. Make sure the location is correct where you're installing it. The default (your workspace) should be fine. Click Finish.
  9. The plugin is not digitally signed. Go ahead and install it anyway.
  10. Click Yes to make Eclipse restart itself.

它是干嘛的?

findbugs是一个开源的eclipse 代码检查工具;它可以简单高效全面地帮助我们发现程序代码中存在的bug,bad smell,以及潜在隐患。针对各种问题,它并且提供了简单的修改意见供我们重构时进行参考; 通过使用它,可以一定程度上降低我们code review的工作量,并且会提高review效率。 通过findbugs找到bug,再由我们自己重构代码,可以培养我们的编码意识及水平,形成好的习惯提高开发编码能力。


基本用法:

findbugs 简单易用,按照下图操作即可;
1, 在eclipse package Explorer 右键选择目标工程-> build project


2, 选择指定的包或者类进行findbug


此时findbugs会遍历指定的包或者类,进行分析,找出代码bug,然后集中显示在 find bugs的bugs explorer 中,下面我们添加bugs explorer。
3,添加findbugs explorer 
(eclipse 左下角)








3, bugs explorer 添加完毕后,我们就可以查看刚刚找到的bugs了,如图:



找出的bug有3中颜色, 黑色的臭虫标志是分类, 红色的臭虫表示严重bug发现后必须修改代码,橘黄色的臭虫表示潜在警告性bug 尽量修改。(附录是各种bug的解释及修改方案,请大家按附表参考修改)
双击bug项目就可以在右边编辑窗口自动打开相关代码文件并连接到代码片段。 点击行号旁边的小臭虫图标后再eclipse下方输出区将提供详细的bug描述,以及修改建议等信息。我们可以根据此信息进行修改。


官方的文档 :http://findbugs.sourceforge.net/manual

0 0
原创粉丝点击