findbug、p3c、checkstyle、sonar安装使用

时间:2021-04-27 16:47:38

idea插件安装方式:

Preferences—>Plugins—>查找插件—>Install

Preferences—>Plugins—>Install plug from disk —>选择下载好的插件—>安装

p3c:

官方安装使用手册:

https://github.com/alibaba/p3c/blob/master/idea-plugin/README_cn.md

便捷使用:

实时检测+手动选择编码规约扫描(使用快捷键ctrl+shift+alt+j或者鼠标右键弹出菜单)

错误提示(ctrl+f1)

快速修改(alt+enter)

缺陷级别:

1.Blocker, 2.Critical, 3.Major;

FindBugs-IDEA:

离线安装包下载地址:

https://plugins.jetbrains.com/plugin/download?rel=true&updateId=29582

安装使用参考文档:

http://blog.csdn.net/qq_27093465/article/details/64923239

便捷使用:

选择文件或项目后鼠标右键选择FindBugs

缺陷级别:

1.Bad pratice编程的坏习惯

2.Malicious code vulnerability 恶意代码漏洞

3.Dodgy code 糟糕的代码

4.performance 性能

5.correctness 代码的正确性 这一项应该算是最重要的

checkstyle:

安装使用参考文档:

https://www.jianshu.com/p/25d2a197a59a

便捷使用:

文件内右键选择check current file

sonar:

安装使用可参考文档:

https://my.oschina.net/zzuqiang/blog/843406

http://blog.csdn.net/hunterno4/article/details/11687269

http://developer.51cto.com/art/201311/418198.htm

https://www.linuxidc.com/Linux/2016-08/133877p2.htm

sonar使用实例:

1.sonar安装配置和启动

解压缩sonar安装包

修改sonar配置:

cd sonar/conf

vi sonar.properties

sonar.jdbc.username=**

sonar.jdbc.password=**

sonar.jdbc.url=jdbc:mysql://**:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance

sonar.sorceEncoding=UTF-8

sonar.jdbc.driverClassName=com.mysql.jdbc.Driver

运行:

/usr/local/sonarqube/bin/linux-x86-64/sonar.sh start

2.maven配置和启动sonar分析

项目配置:

maven->setting.xml修改配置(不需要添加数据库信息):

<profile>

<id>sonar</id>

<activation>

<activeByDefault>true</activeByDefault>

</activation>

<properties>

<sonar.host.url>http://**:9000</sonar.host.url>

</properties>

</profile>

运行:

mvn clean install

mvn sonar:sonar

问题1及解决:

问题:

Property 'sonar.jdbc.url' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.

Property 'sonar.jdbc.username' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.

Property 'sonar.jdbc.password' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.

https://*.com/questions/35230453/sonar-jdbc-properties-are-not-supported-anymore-in-sonarqube-5-3-version

不用配置数据库信息,只需要配置url,数据会直接渲染在网页上。

问题2及解决:

问题:

使用sonar的时候报错svn: E175002: Connection has been shutdown: javax.net.ssl.SSLProtocolException: handshake alert:  unrecognized_name

解决:

https://support.xebialabs.com/hc/en-us/community/posts/203291975-SOLVED-javax-net-ssl-SSLProtocolException-handshake-alert-unrecognized-name

运行时加参数:

mvn sonar:sonar -Djsse.enableSNIExtension=false

(Sometimes, when Java 1.7 communicates via HTTPS with webservers, that configured with multiple hostnames, it can throw the following error: javax.net.ssl.SSLProtocolException: handshake alert: unrecognized_name.

In this case, the solution can be either to fix the configuration of web server, or set jsse.enableSNIExtension into false by adding

to following line to the start options of the server.

-Djsse.enableSNIExtension=false)