一、安装好了SonarQube服务端后,在其它电脑的浏览器上登陆,开始安装其它编程语言检测插件
系统已经装好的语言插件:
下载了软件项目中常用的语言:Android、CSS、Web、XML
JAVA相关的:Checkstyle、Findbugs、PMD
Java 静态分析工具分析对象 |
应用技术 |
Checkstyle |
Java 源文件,缺陷模式匹配 |
FindBugs |
字节码,缺陷模式匹配;数据流分析 |
PMD |
Java 源代码,缺陷模式匹配 |
下载完分析语言规则后,重启服务
二、安装命令行分析端
sonar的命令行分析端软件有两种分别是Runner和Scanner,官网文档中写的是Scanner,但Runner和它安装、使用都基本一致。
1、在CentOS上安装sonar-runner-dist-2.4
cd /usr/local/src/
wget http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip
unzip sonar-runner-dist-2.4.zip
mv sonar-runner-2.4/ /usr/local/
配置PATH路径
vim /etc/profile
PATH=$PATH:/usr/local/sonar-runner-2.4/bin
export PATH
配置sonar-runner启动配置文件
vim /usr/local/sonar-runner-2.4/conf/sonar-runner.properties
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.host.url=http://192.168.1.190
sonar.login=admin
sonar.password=admin
安装成功后重启服务器,在命令行运行以上命令并回显,表示运行成功。
[root@sonar local]# sonar-runner -h
INFO:
INFO: usage: sonar-runner [options]
INFO:
INFO: Options:
INFO: -D,--define <arg> Define property
INFO: -e,--errors Produce execution error messages
INFO: -h,--help display help information
INFO: -v,--version display version information
INFO: -X,--debug Produce execution debug output
2、在CentOS上安装sonar-scanner2.8
cd /usr/local/src/ wget https://sonarsource.bintray.com/distribution/sonar-scanner-cli/sonar-scanner-2.8.zip unzip sonar-scanner-2.8.zip mv sonar-scanner-2.8/ /usr/local/
配置PATH路径
vim /etc/profile
PATH=$PATH:/usr/local/sonar-runner-2.4/bin:/usr/local/sonar-scanner-2.8/bin
export PATH
配置sonar-scanner启动配置文件
vim /usr/local/sonar-scanner-2.8/conf/sonar-scanner.properties
sonar.jdbc.url=jdbc:MysqL://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.host.url=http://192.168.1.190
sonar.login=admin
sonar.password=admin
安装成功后重启服务器,在命令行运行以上命令并回显,表示运行成功。
[root@sonar local]# sonar-scanner -h
INFO:
INFO: usage: sonar-scanner [options]
INFO:
INFO: Options:
INFO: -D,--define <arg> Define property
INFO: -h,--help display help information
INFO: -v,--version display version information
INFO: -X,--debug Produce execution debug output
INFO: -i,--interactive Run interactively
三、把开发程序的源代码打包成zip文件上传到安装有Runner或Scanner的服务器上
cd /usr/local/
unzip whale.zip
四、使用sonar-scanner进行代码质量分析
cd whale/
vim sonar-project.properties
# must be unique in a given SonarQube instance
sonar.projectKey=whale:scanner
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=whale-scanner
sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# Since SonarQube 4.2, this property is optional if sonar.modules is set.
# If not set, SonarQube starts looking for source code from the directory containing
# the sonar-project.properties file.
sonar.sources=.
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
3、保存并退出后运行命令进行分析(分析中不能执行Findbugs3.4.3分析,在web端卸载这个规则后可以正常分析):
sonar-scanner
4、在web中查看Scanner代码质量分析的结果。
五、使用sonar-Runner进行代码质量分析
cd /usr/local/whale/
vim sonar-project.properties
# must be unique in a given SonarQube instance
sonar.projectKey=whale:runner
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=whale-runner
sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# Since SonarQube 4.2, this property is optional if sonar.modules is set.
# If not set, SonarQube starts looking for source code from the directory containing
# the sonar-project.properties file.
sonar.sources=.
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
3、保存并退出后运行命令进行分析(分析中不能执行Findbugs3.4.3分析,在web端卸载这个规则后可以正常分析):
sonar-runner
4、在web中查看runner代码质量分析的结果。
结果一样,证明Runner和Scanner功能差不多。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。