自做网站代码是多少,网站门户怎么建设,盐城网页优化公司,北京怎样在社保网站上做减员SpotBugs介绍
SpotBugs和FindBugs的关系
SpotBugs是FindBugs的继任者#xff0c;从SpotBugs停止的地方继续。 备注#xff1a;FindBugs项目已经停止了#xff0c;从2015年发布3.0.1版本以后再没有新的版本。
SpotBugs通过静态分析寻找java代码中的bug#xff0c;通过发现…SpotBugs介绍
SpotBugs和FindBugs的关系
SpotBugs是FindBugs的继任者从SpotBugs停止的地方继续。 备注FindBugs项目已经停止了从2015年发布3.0.1版本以后再没有新的版本。
SpotBugs通过静态分析寻找java代码中的bug通过发现bug模式来发现疑似问题。 它是一款免费软件是FindBugs的一个分支。
SpotBugs参考资源
文档资源
https://spotbugs.readthedocs.io/en/latest/index.html
https://spotbugs.github.io/
代码库
https://github.com/spotbugs/spotbugs SpotBugs对JRE (或 JDK) 版本的要求
SpotBugs是用JDK8版本构建的所以运行需要JRE (或 JDK) 1.8.0及以后的版本。 SpotBugs可以扫描JDK8及更新的版本编译生成的字节码即class文件。
SpotBugs报告的标准bug模式
SpotBugs 可以检查400多种bug模式分了10个大的类别 https://spotbugs.readthedocs.io/en/latest/bugDescriptions.html SpotBugs检测器Detectors
https://spotbugs.readthedocs.io/en/latest/detectors.html#
Standard detectors默认是打开的而Disabled detectors默认是关闭的。
安装SpotBugs Eclipse插件、用SpotBugs Eclipse插件运行SpotBugs
安装SpotBugs Eclipse插件
要在Eclipse中安装SpotBugs Plugin需要 Eclipse Neon (4.6) 及以后版本。 我们用Eclipse Marketplace来安装下面是安装步骤
点击Restart Now重新进入Eclipse。
从菜单Window-Preferences进入在Java下面出现SpotBugs项说明安装成功了
SpotBugs配置
从菜单Window-Preferences进入在Java下面找到SpotBugs项
Reporter Configuraton
选择报告的类别
在Reporter Configuraton页面可以选择报告的bug类别
选择analysis effort
https://spotbugs.readthedocs.io/en/latest/effort.html effort的值是调节了SpotBugs的内部flag通过降低预测来降低计算成本。 Filter files
在Filter files页面可以配置包含filter文件、不包含filter文件。其中filter文件的介绍请参见 https://spotbugs.readthedocs.io/en/latest/filter.html
Detector configuration
在Detector configuration页面可以勾选或者不勾选某个/某些检测器
在上面选中某一个检测器下面会显示该检测器的详细信息
检测器的信息跟SpotBugs官网中的detector对应
启用项目特有的SpotBugs配置
在项目上右击在弹出菜单中选择Properties
找到SpotBugs
如果要启用项目特有的配置就在Enable project specific settings复选框打钩
在java项目上设置自动运行SpotBugs
在项目上右击在弹出菜单中选择Properties。在属性设置界面选中左侧的SpotBugs。 如果要自动运行就在Run automatically复选框打钩这样每次修改了项目中的类SpotBug就会自动运行
在java项目上立即运行SpotBugs
右击java项目在弹出菜单中选择SpotBugs-Find Bugs就会立即扫描
在下面的Problems页出现扫描结果
双击击某个违反项就会跳到代码处
将SpotBugs扫描结果保存为XML文件
右击java项目在弹出菜单中选择SpotBugs-Save XML:
选择要导出的路径、输入文件名
文件导出成功
打开该文件看看内容片段文件内容远比在Eclipse Problems窗口中显示的信息丰富
安装SpotBugs Maven插件、用SpotBugs Maven插件运行SpotBugs
安装SpotBugs Maven插件
https://spotbugs.readthedocs.io/en/latest/maven.html
在maven工程的pom.xml文件中build小节、reporting小节增加关于SpotBugs Maven插件的配置信息 buildpluginManagementplugingroupIdcom.github.spotbugs/groupIdartifactIdspotbugs-maven-plugin/artifactIdversion4.7.3.5/version/plugin/plugins/pluginManagementpluginsplugingroupIdcom.github.spotbugs/groupIdartifactIdspotbugs-maven-plugin/artifactIdconfigurationhtmlOutputtrue/htmlOutput/configuration/plugin/plugins/buildreportingpluginsplugingroupIdcom.github.spotbugs/groupIdartifactIdspotbugs-maven-plugin/artifactIdconfigurationhtmlOutputtrue/htmlOutput/configuration/plugin/plugins/reporting等待一会儿插件及其依赖的SpotBugs版本下载到maven本地仓库了
goals
spotbugs:spotbugs
https://spotbugs.github.io/spotbugs-maven-plugin/spotbugs-mojo.html
用SpotBugs分析目标工程其中很多参数可以调节、控制分析。 备注该goal本身没有将java文件编译为class文件的动作。
示例 先调用mvn compile进行编译然后调用mvn spotbugs:spotbugs进行分析 到maven工程的target目录下查看输出内容 打开spotbugs.html查看输出结果
spotbugs:check
https://spotbugs.github.io/spotbugs-maven-plugin/check-mojo.html
用SpotBugs分析目标工程如果发现问题就停止构建。
示例 先调用mvn compile进行编译然后调用mvn spotbugs:check
到maven工程的target目录下查看输出内容
spotbugs:gui
https://spotbugs.github.io/spotbugs-maven-plugin/gui-mojo.html
调用 SpotBugs GUI图形用户界面显示分析结果。 备注要先用其它的goal生成分析结果再调用此goal显示分析结果。
示例 先调用mvn compile进行编译然后调用mvn spotbugs:spotbugs进行扫描分析、最后调用mvn spotbugs:gui拉起SpotBugs的图形用户界面显示分析结果
在图形用户界面选中某一个bug会显示详细信息
spotbugs:help
显示帮助信息。
示例 执行spotbugs:help