SonarQube和Sonar-Scanner的安装与使用

共 6943字,需浏览 14分钟

 ·

2021-12-11 16:41

一、介绍

sonar是搞代码质量测试的一款开源工具。SonarQube是sonar的Web服务端,用来发布应用和在线浏览(分析),sonar-scanner用于扫描源码, 将代码写入数据库之类的地方,便于sonarqube进行分析

二、JDK的安装使用

2.1、配置JDK环境变量

以笔者的JDK安装目录为例,

jdk目录:D:\Program Files\Java\jdk1.8.0_101

jre目录:D:\Program Files\Java\jre1.8.0_101

2.1.1、配置JAVA_HOME

2.1.2、 配置PATH

2.1.3、配置CLASSPATH

2.1.4、验证是否配置成功

三、SonarQube的安装使用

默认端口:9000

配置文件(以笔者电脑为例):sonarqube-9.2.1.49989\conf\sonar.properties

默认用户名密码:都是admin

默认访问网址:http://ip:9000

点击StartSonar.bat, 打开楼上的默认网址,输入默认密码就行了。

四、Sonar-scanner的安装使用

配置文件(以笔者电脑为例):sonar-scanner-4.6.2.2472-windows\conf\sonar-scanner.properties

4.1、Sonar-Scanner环境变量配置

4.1.1 配置SONAR_RUNNER_HOME

4.1.2、 配置PATH

4.2、 运行项目验证结果

4.2.1、配置扫描文件

sonar.projectKey=agentsonar.projectName=agentsonar.projectVersion=4.3.0sonar.sources=.sonar.exclusions=**/public/**,**/src/locales/**sonar.sourceEncoding=UTF-8sonar.language=javascriptsonar.login=adminsonar.password=admin

4.2.2、扫它

在项目根目录运行命令sonar-scanner等结果即可

PS D:\ataola\gitlab\20211207\sany-web\agent> sonar-scannerINFO: Scanner configuration file: D:\ataola\document\2021\12\sonar-scanner-4.6.2.2472-windows\bin\..\conf\sonar-scanner.propertiesINFO: Project root configuration file: D:\ataola\gitlab\20211207\sany-web\agent\sonar-project.propertiesINFO: SonarScanner 4.6.2.2472INFO: Java 11.0.11 AdoptOpenJDK (64-bit)INFO: Windows 10 10.0 amd64INFO: User cache: C:\Users\14457\.sonar\cacheINFO: Scanner configuration file: D:\ataola\document\2021\12\sonar-scanner-4.6.2.2472-windows\bin\..\conf\sonar-scanner.propertiesINFO: Project root configuration file: D:\ataola\gitlab\20211207\sany-web\agent\sonar-project.propertiesINFO: Analyzing on SonarQube server 9.2.1INFO: Default locale: "en_US", source code encoding: "UTF-8"INFO: Load global settingsINFO: Load global settings (done) | time=350msINFO: Server id: BF41A1F2-AX2PesCwEVbfPSmwmCVAINFO: User cache: C:\Users\14457\.sonar\cacheINFO: Load/download pluginsINFO: Load plugins indexINFO: Load plugins index (done) | time=275msINFO: Load/download plugins (done) | time=873msINFO: Process project propertiesINFO: Process project properties (done) | time=22msINFO: Execute project buildersINFO: Execute project builders (done) | time=2msINFO: Project key: agentINFO: Base dir: D:\ataola\gitlab\20211207\sany-web\agentINFO: Working dir: D:\ataola\gitlab\20211207\sany-web\agent\.scannerworkINFO: Load project settings for component key: 'agent'INFO: Load project settings for component key: 'agent' (done) | time=284msINFO: Load quality profilesINFO: Load quality profiles (done) | time=586msINFO: Load active rulesINFO: Load active rules (done) | time=8301msINFO: Indexing files...INFO: Project configuration:INFO:   Excluded sources: **/public/**, **/src/locales/**INFO: 327 files indexedINFO: 46 files ignored because of inclusion/exclusion patternsINFO: 4 files ignored because of scm ignore settingsINFO: Quality profile for css: Sonar wayINFO: Quality profile for js: Sonar wayINFO: Quality profile for json: Sonar wayINFO: ------------- Run sensors on module agentINFO: Load metrics repositoryINFO: Load metrics repository (done) | time=306msINFO: Sensor JaCoCo XML Report Importer [jacoco]INFO: 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xmlINFO: No report imported, no coverage information will be imported by JaCoCo XML Report ImporterINFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=38msINFO: Sensor IaC CloudFormation Sensor [iac]INFO: Load project repositoriesINFO: Load project repositories (done) | time=361msINFO: 0 source files to be analyzedINFO: 0/0 source files have been analyzedINFO: Sensor IaC CloudFormation Sensor [iac] (done) | time=481msINFO: Sensor JavaScript analysis [javascript]INFO: 269 source files to be analyzedINFO: 2/269 files analyzed, current file: src/pages/reportManagement/product/model.jsINFO: 70/269 files analyzed, current file: config/validator.jsINFO: 124/269 files analyzed, current file: src/pages/financingAccess/model.jsINFO: 206/269 files analyzed, current file: src/pages/financingAccess/addApply/components/Step4/index.jsxINFO: 269/269 source files have been analyzedINFO: Sensor JavaScript analysis [javascript] (done) | time=118667msINFO: Sensor TypeScript analysis [javascript]INFO: No input files found for analysisINFO: Sensor TypeScript analysis [javascript] (done) | time=12msINFO: Sensor CSS Metrics [javascript]INFO: Sensor CSS Metrics [javascript] (done) | time=1086msINFO: Sensor CSS Rules [javascript]INFO: 45 source files to be analyzedINFO: 45/45 source files have been analyzedINFO: Sensor CSS Rules [javascript] (done) | time=4514msINFO: Sensor C# Project Type Information [csharp]INFO: Sensor C# Project Type Information [csharp] (done) | time=1msINFO: Sensor C# Analysis Log [csharp]INFO: Sensor C# Analysis Log [csharp] (done) | time=38msINFO: Sensor C# Properties [csharp]INFO: Sensor C# Properties [csharp] (done) | time=0msINFO: Sensor JavaXmlSensor [java]INFO: Sensor JavaXmlSensor [java] (done) | time=4msINFO: Sensor HTML [web]INFO: Sensor HTML [web] (done) | time=7msINFO: Sensor VB.NET Project Type Information [vbnet]INFO: Sensor VB.NET Project Type Information [vbnet] (done) | time=2msINFO: Sensor VB.NET Analysis Log [vbnet]INFO: Sensor VB.NET Analysis Log [vbnet] (done) | time=40msINFO: Sensor VB.NET Properties [vbnet]INFO: Sensor VB.NET Properties [vbnet] (done) | time=0msINFO: ------------- Run sensors on projectINFO: Sensor Zero Coverage SensorINFO: Sensor Zero Coverage Sensor (done) | time=217msINFO: CPD Executor 36 files had no CPD blocksINFO: CPD Executor Calculating CPD for 233 filesWARN: Too many duplication groups on file src/utils/addressCascader/industry.js. Keep only the first 100 groups.INFO: CPD Executor CPD calculation finished (done) | time=938msINFO: Analysis report generated in 711ms, dir size=5.0 MBINFO: Analysis report compressed in 17935ms, zip size=1.7 MBINFO: Analysis report uploaded in 562msINFO: ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard?id=agentINFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis reportINFO: More about the report processing at http://localhost:9000/api/ce/task?id=AX2enXM0eAsfd-3jKFcfINFO: Analysis total time: 2:59.463 sINFO: ------------------------------------------------------------------------INFO: EXECUTION SUCCESSINFO: ------------------------------------------------------------------------INFO: Total time: 3:02.946sINFO: Final Memory: 14M/54MINFO: ------------------------------------------------------------------------PS D:\ataola\gitlab\20211207\sany-web\agent>
 

4.2.3、看它

写在最后

这是一篇水文,我其实不太喜欢这么搞,我认为如果团队Ok的话,从最开始编码规范就定义好,加上code review,加上mocha或者jest做测试,比较有感觉一点。这种东西,有人喜欢搞,也有人不喜欢搞,具体的还是根据需求来,比如甲方需要那就搞呗,搞得时候也要注意安全问题啊, 头像已经高斯模糊, 逃。。。。。。



浏览 65
点赞
评论
收藏
分享

手机扫一扫分享

分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

分享
举报