Linux下sonarqube安装使用方法(代码check工具)
来源:互联网 发布:mysql主键有什么用 编辑:程序博客网 时间:2024/06/16 18:43
背景
1、 虚拟机CentOS release 7.2
2、 sonarqube-6.2
3、 sonar-scanner-2.8
一、 sonarqube-6.2的安装
1、 sonarqube下载地址https://www.sonarqube.org/downloads/
这里下载的是sonarqube-6.2,下载完成之后解压下载的zip压缩包。会产生下图所示的文件目录。
2、 配置sonarqube
进入conf文件夹,打开sonar.properties进行配置。Sonarqube默认ip为localhost,默认端口为9000。如果想修改,可以将sonar.properties文件中
sonar.web.host=localhost
sonar.web.port=9000
的注释去掉,并修改ip和port,如果使用默认,不去掉注释也是可以的。
单纯做测试时可以直接使用sonarqube默认的Embedded Database,不需要安装其他数据库。这里使用的就是默认的Embedded Database。
3、 Sonarqube启动。
首先启动sonarqube服务,进入到bin目录下,选择相应linux系统,这里是linux-x86-64,进入到inux-x86-64目录,执行./sonar.sh start启动sonarqube。
同时可以去logs文件中查看日志,确认启动正常。
正常启动后会在inux-x86-64目录下产生一个SonarQube.pid文件。
启动完成之后,打开浏览器输入http://localhost:9000,会看到如下画面:
点击右上角的Login按钮,登陆sonarqube,默认用户名和密码为admin/admin。
登陆后画面如下:
二、 sonar-scanner-2.8的安装
如果要对代码进行检查,必须要安装sonar-scanner。
1、 到sonarqube官网下载sonar-scanner-2.8,当然可以使用其他版本,但是要注意版本支持问题,详情去https://www.sonarqube.org/官网查看。
下载完成之后解压sonar-scanner-2.8.zip,产生下图所示的文件目录:
如果sonarqube都是默认设置,这里也不需要配置,如果sonarqube有做设置,这里在conf目录下的sonar-scanner.properties文件中做对应的设置。
2、 创建sonar-project.properties。
对代码进行分析,必须要创建sonar-project.properties文件,执行sonar-scanner时,会对根据sonar-project.properties文件进行搜索,该文件要放在与项目(如下图中src)同一目录下。
例:举例创建sonar-project.properties文件。
设定参数具体意义参考:
http://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner
3、 进入到bin目下,可以看到很多可执行文件,如下图:
在linux系统下,绿色可执行,这里执行sonar-scanner就可以了。
为了方便sonar-scanner执行,可将其设置为环境变量,投入下列命令:
exportSONAR_RUNNER_HOME=/root/zfl/sonar-scanner-2.8
exportPATH=$SONAR_RUNNER_HOME/bin:$PATH
目录根据自己存放的位置进行选择。
4、 执行sonar-scanner。
进入到存放sonar-project.properties文件的目录,执行sonar-scanner,执行结果显示EXECUTION SUCCESS,则解析成功。
此时登陆http://localhost:9000,会看到解析project的信息在网页上显示。
Quality Gate:
http://docs.sonarqube.org/display/SONAR/Quality+Gates
A quality gate is the best way to enforce a qualitypolicy in your organization. It's there to answer ONE question : can I delivermy project to production today or not ?
Issues:
http://docs.sonarqube.org/display/SONAR/Issues
BLOCKER:Bug with a high probability to impact the behavior of theapplication in production: memory leak, unclosed JDBC connection, .... The codeMUST be immediately fixed.
CRITICAL:Either a bug with a low probability to impact the behavior ofthe application in production or an issue which represents a security flaw:empty catch block, SQL injection, ... The code MUST be immediatelyreviewed.
MAJOR:Quality flaw which can highly impact the developerproductivity: uncovered piece of code, duplicated blocks, unused parameters,...
MINOR:Quality flaw which can slightly impact the developerproductivity: lines should not be too long, "switch" statementsshould have at least 3 cases, ...
INFO:Neither a bug nor a quality flaw, just a finding.
总结:一般Quality Gate显示passed,则说明代码质量是OK的,如果显示Failed,进入project中,查看有哪些问题,根据显示进行修改。
Project 查看参照下列网址:
https://docs.sonarqube.org/display/SONAR/Project+Page
对于sonarqube网页显示结果的分析,具体可参照
https://docs.sonarqube.org/display/SONAR/Analyzing+Source+Code。- Linux下sonarqube安装使用方法(代码check工具)
- ubuntu下安装sonarqube(团队代码评审工具)
- 代码审查工具SonarQube
- Linux安装SonarQube
- Linux 安装SonarQube
- Android 代码检查工具SonarQube
- Android 代码检查工具SonarQube
- 代码质量管理工具SonarQube概述
- 代码质量管理工具SonarQube详解
- Android 代码检查工具SonarQube
- SonarQube安装、配置、扫描代码
- inux下SonarQube安装方法
- Windows下SonarQube的安装
- sonarQube代码质量管理工具环境筹建笔记
- Android 代码检查工具SonarQube,androidsonarqube
- SonarQube安装完后出现SonarQube is under maintenance. Please check back later.
- SonarQube之——安装完后出现SonarQube is under maintenance. Please check back later.
- Linux环境安装SonarQube,windows使用SonarQube Runner完整实例
- Android 出现错误:Error:(1, 0) Minimum supported Gradle version is 3.3. Current version is 2.14.1. If usi
- HTML+CSS+JS+Ajax技巧篇
- leetcode reorderList Given{1,2,3,4}, reorder it to{1,4,2,3}.
- 论初次修改 Android framework 代码
- Java-java中jvm原理详解
- Linux下sonarqube安装使用方法(代码check工具)
- Android自定义View--简单实现凹凸优惠券效果
- 为什么你们说好的程序在我的海思开发板上就是不行呢,难道真的是人品有问题
- 经典排序算法之冒泡、选择和插入排序
- php谷歌翻译
- 基于Python的select方式的聊天室应用实例
- Android开发学习笔记:浅谈WebView
- linux下elasticsearch 安装、配置及示例
- bootstrap select2默认选中后台传过来的值