日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

白盒测试工具 - sonar的安装、配置与使用入门手册,用sonar检查代码质量实战演示

發(fā)布時間:2025/4/16 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 白盒测试工具 - sonar的安装、配置与使用入门手册,用sonar检查代码质量实战演示 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

sonar 檢測代碼質(zhì)量實(shí)戰(zhàn)演示

  • 第一章:sonarqube 的安裝與啟用
  • ① sonarqube 獲取
  • ② sonarqube 配置
  • ③ sonarqube 驅(qū)動放置
  • ④ sonarqube 的啟動
  • 第二章:sonarqube 報(bào)錯解決
  • ① Unsupported JDBC driver provider: mysql. 【sonarqube8.0 以后不支持 mysql】
  • ② Directory does not contain JDBC driver: extensions/jdbc-driver/oracle. 【沒有找到驅(qū)動】
  • ③ SonarQube requires Java 11 to run. 【sonarqube8.0 需要 java11 的支持】
  • ④ 遠(yuǎn)程主機(jī)強(qiáng)迫關(guān)閉了一個現(xiàn)有的連接?!緎onarqube 數(shù)據(jù)庫驅(qū)動版本不匹配】
  • ⑤ 查看 sonarqube 的數(shù)據(jù)庫支持
  • 第三章:sonarScanner 插件的安裝與配置
  • ① sonarScanner 獲取
  • ② sonarScanner 設(shè)置環(huán)境變量
  • ③ sonarScanner 配置
  • 第四章:用 sonar 檢查代碼質(zhì)量
  • ① 配置
  • ② 運(yùn)行
  • ③ 查看掃描報(bào)告
  • ④ 分析報(bào)告問題
  • ⑤ 代碼質(zhì)量評級
  • 第五章:sonar 相關(guān)設(shè)置
  • ① sonar 管理員登錄
  • ② sonar 設(shè)置

安裝過程主要分為兩部分,一個是主程序 sonarqube,一個是 sonarScanner 插件,兩個都安裝配置好后就可以進(jìn)行代碼掃描了。sonarqube 在配置數(shù)據(jù)庫的過程中會碰到很多問題,第二章專門針對這些問題來進(jìn)行講解。

第一章:sonarqube 的安裝與啟用

① sonarqube 獲取

下載地址: 官方網(wǎng)站

② sonarqube 配置

解壓后的程序目錄下,進(jìn)入 conf 里的 sonar.properties 來進(jìn)行配置。

# 指定oracle數(shù)據(jù)庫 sonar.jdbc.url=jdbc:oracle:thin:@10.10.18.70:1521/orcl # 指定數(shù)據(jù)庫用戶名 sonar.jdbc.username=ncc_auto_sonar # 指定數(shù)據(jù)庫密碼 sonar.jdbc.password=1 # 指定端口 sonar.web.port=9000

③ sonarqube 驅(qū)動放置

不要忘了把驅(qū)動放到

④ sonarqube 的啟動

StartSonar 來啟動程序,如果閃退了,可以拖到 cmd 里運(yùn)行,可以看到報(bào)錯信息,第二章就介紹它的一些常見報(bào)錯的解決方法。

然后再訪問 localhost:9000 就進(jìn)來了。

第二章:sonarqube 報(bào)錯解決

① Unsupported JDBC driver provider: mysql. 【sonarqube8.0 以后不支持 mysql】

sonarqube8.0 以后不再支持 mysql,所以我用 oracle 來做適配。

jvm 1 | WrapperSimpleApp: Encountered an error running main: org.sonar.proces s.MessageException: Unsupported JDBC driver provider: mysql jvm 1 | org.sonar.process.MessageException: Unsupported JDBC driver provider:mysql wrapper | <-- Wrapper Stopped

② Directory does not contain JDBC driver: extensions/jdbc-driver/oracle. 【沒有找到驅(qū)動】

沒有配置數(shù)據(jù)庫驅(qū)動。extensions/jdbc-driver/oracle 下面沒有放驅(qū)動,或是驅(qū)動放的不對。

jvm 1 | WrapperSimpleApp: Encountered an error running main: org.sonar.proces s.MessageException: Directory does not contain JDBC driver: extensions/jdbc-driv er/oracle jvm 1 | org.sonar.process.MessageException: Directory does not contain JDBC d river: extensions/jdbc-driver/oracle wrapper | <-- Wrapper Stopped

③ SonarQube requires Java 11 to run. 【sonarqube8.0 需要 java11 的支持】

我原來用的版本是 java8 的。

運(yùn)行時會提示要用 java11 來運(yùn)行。

jvm 1 | WrapperSimpleApp: Encountered an error running main: java.lang.Illega lStateException: SonarQube requires Java 11 to run jvm 1 | java.lang.IllegalStateException: SonarQube requires Java 11 to run


java11 官網(wǎng)下載

安裝完后配置環(huán)境變量后就可以了。

④ 遠(yuǎn)程主機(jī)強(qiáng)迫關(guān)閉了一個現(xiàn)有的連接?!緎onarqube 數(shù)據(jù)庫驅(qū)動版本不匹配】

報(bào)這個錯感覺我的數(shù)據(jù)庫驅(qū)動版本不對,然后換了個驅(qū)動就好了。

jvm 1 | 2020.05.22 17:25:35 WARN app[][o.e.t.TcpTransport] exception caught on transport layer [Netty4TcpChannel{localAddress=/127.0.0.1:62245, remoteAddres s=/127.0.0.1:9001}], closing connection jvm 1 | java.io.IOException: 遠(yuǎn)程主機(jī)強(qiáng)迫關(guān)閉了一個現(xiàn)有的連接。


然后再訪問 localhost:9000 就進(jìn)來了。

⑤ 查看 sonarqube 的數(shù)據(jù)庫支持

配置文檔里有很多的幫助,我直接搜 oracle 就能查看 oracle 的支持了,還有下面說的驅(qū)動放置方法,以及更下面的官方支持網(wǎng)站,如果還有其它的問題,興許就能在里面找到問題的解決方法。

第三章:sonarScanner 插件的安裝與配置

① sonarScanner 獲取

獲取地址:官網(wǎng)下載
下載完后解壓即可。

② sonarScanner 設(shè)置環(huán)境變量

我們把它根目錄下面的 bin 文件夾加入環(huán)境變量。


cmd 里輸入 sonar-scanner -h 可以看有沒有配置對。

③ sonarScanner 配置

在這個配置文件夾里的配置文件進(jìn)行配置。

還是跟前面 sonarqube 的數(shù)據(jù)庫配置一樣。

# 指定oracle數(shù)據(jù)庫 sonar.jdbc.url=jdbc:oracle:thin:@10.10.18.70:1521/orcl # 指定數(shù)據(jù)庫用戶名 sonar.jdbc.username=ncc_auto_sonar # 指定數(shù)據(jù)庫密碼 sonar.jdbc.password=1

第四章:用 sonar 檢查代碼質(zhì)量

① 配置

在要檢查代碼的地方建個這個配置文件 sonar-project.properties。

sonarScanner 官網(wǎng) 給的配置方法。

# must be unique in a given SonarQube instance sonar.projectKey=my:project# --- optional properties ---# defaults to project key #sonar.projectName=My project # defaults to 'not provided' #sonar.projectVersion=1.0# Path is relative to the sonar-project.properties file. Defaults to . #sonar.sources=.# Encoding of the source code. Default is default system encoding #sonar.sourceEncoding=UTF-8

② 運(yùn)行

在放好配置文件的目錄下輸入 sonar-scanner 命令就可以掃描了。

掃描成功標(biāo)志。

掃描過程詳細(xì)信息。

C:\Users\Administrator\Desktop\XpathRobot>sonar-scanner INFO: Scanner configuration file: D:\server\sonar\sonar-scanner-4.3.0.2102-windo ws\bin\..\conf\sonar-scanner.properties INFO: Project root configuration file: C:\Users\Administrator\Desktop\XpathRobot \sonar-project.properties INFO: SonarScanner 4.3.0.2102 INFO: Java 11.0.3 AdoptOpenJDK (64-bit) INFO: Windows 7 6.1 amd64 INFO: User cache: C:\Users\Administrator\.sonar\cache INFO: Scanner configuration file: D:\server\sonar\sonar-scanner-4.3.0.2102-windo ws\bin\..\conf\sonar-scanner.properties INFO: Project root configuration file: C:\Users\Administrator\Desktop\XpathRobot \sonar-project.properties INFO: Analyzing on SonarQube server 8.2.0 INFO: Default locale: "zh_CN", source code encoding: "GBK" (analysis is platformdependent) INFO: Load global settings INFO: Load global settings (done) | time=205ms INFO: Server id: 02A721FB-AXJaPgmVryaM9Bas_OmF INFO: User cache: C:\Users\Administrator\.sonar\cache INFO: Load/download plugins INFO: Load plugins index INFO: Load plugins index (done) | time=161ms INFO: Load/download plugins (done) | time=3743ms INFO: Process project properties INFO: Process project properties (done) | time=1ms INFO: Execute project builders INFO: Execute project builders (done) | time=5ms INFO: Project key: my:project INFO: Base dir: C:\Users\Administrator\Desktop\XpathRobot INFO: Working dir: C:\Users\Administrator\Desktop\XpathRobot\.scannerwork INFO: Load project settings for component key: 'my:project' INFO: Load quality profiles INFO: Load quality profiles (done) | time=305ms INFO: Load active rules INFO: Load active rules (done) | time=3550ms WARN: SCM provider autodetection failed. Please use "sonar.scm.provider" to defi ne SCM of your project, or disable the SCM Sensor in the project settings. INFO: Indexing files... INFO: Project configuration: INFO: 21 files indexed INFO: Quality profile for py: Sonar way INFO: Quality profile for web: Sonar way INFO: ------------- Run sensors on module my:project INFO: Load metrics repository INFO: Load metrics repository (done) | time=116ms WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by net.sf.cglib.core.ReflectUtils$1 (file:/C: /Users/Administrator/.sonar/cache/54f6535c111cefad0fb6a09ba3e61922/sonar-javascr ipt-plugin.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byt e[],int,int,java.security.ProtectionDomain) WARNING: Please consider reporting this to the maintainers of net.sf.cglib.core. ReflectUtils$1 WARNING: Use --illegal-access=warn to enable warnings of further illegal reflect ive access operations WARNING: All illegal access operations will be denied in a future release INFO: Sensor Python Sensor [python] INFO: Starting global symbols computation INFO: 3 source files to be analyzed INFO: Load project repositories INFO: Load project repositories (done) | time=14ms INFO: Starting rules execution INFO: 3 source files to be analyzed INFO: 3/3 source files have been analyzed INFO: Sensor Python Sensor [python] (done) | time=1481ms INFO: Sensor Cobertura Sensor for Python coverage [python] INFO: 3/3 source files have been analyzed INFO: Sensor Cobertura Sensor for Python coverage [python] (done) | time=23ms INFO: Sensor PythonXUnitSensor [python] INFO: Sensor PythonXUnitSensor [python] (done) | time=11ms INFO: Sensor SonarCSS Rules [cssfamily] INFO: 1 source files to be analyzed INFO: 1/1 source files have been analyzed INFO: Sensor SonarCSS Rules [cssfamily] (done) | time=14364ms INFO: Sensor JaCoCo XML Report Importer [jacoco] INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=4ms INFO: Sensor JavaXmlSensor [java] INFO: Sensor JavaXmlSensor [java] (done) | time=2ms INFO: Sensor HTML [web] INFO: Sensor HTML [web] (done) | time=150ms INFO: ------------- Run sensors on project INFO: Sensor Zero Coverage Sensor INFO: Sensor Zero Coverage Sensor (done) | time=48ms INFO: SCM Publisher No SCM system was detected. You can use the 'sonar.scm.provi der' property to explicitly specify it. INFO: CPD Executor 1 file had no CPD blocks INFO: CPD Executor Calculating CPD for 3 files INFO: CPD Executor CPD calculation finished (done) | time=15ms INFO: Analysis report generated in 106ms, dir size=214 KB INFO: Analysis report compressed in 99ms, zip size=52 KB INFO: Analysis report uploaded in 1527ms INFO: ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard?id=my% 3Aproject INFO: Note that you will be able to access the updated dashboard once the serverhas processed the submitted analysis report INFO: More about the report processing at http://localhost:9000/api/ce/task?id=A XJeUNiUryaM9Bas_RCa INFO: Analysis total time: 25.030 s INFO: ------------------------------------------------------------------------ INFO: EXECUTION SUCCESS INFO: ------------------------------------------------------------------------ INFO: Total time: 32.540s INFO: Final Memory: 13M/50M INFO: ------------------------------------------------------------------------

③ 查看掃描報(bào)告

刷新后就能看到掃描后的結(jié)果了!

④ 分析報(bào)告問題

點(diǎn)進(jìn) bug 里可以看到很多問題。

點(diǎn)擊 Why is this an issue? 可以查看問題原因,點(diǎn)擊整個粉色的部分可以追蹤到代碼。

⑤ 代碼質(zhì)量評級

點(diǎn)擊 quality gates 可以查看代碼質(zhì)量的綜合評分。

第五章:sonar 相關(guān)設(shè)置

① sonar 管理員登錄

sonar 管理員登錄。

管理員的賬號和密碼都是 admin

② sonar 設(shè)置

管理員登錄后才能看到設(shè)置頁簽。

喜歡的點(diǎn)個贊?吧!

《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

總結(jié)

以上是生活随笔為你收集整理的白盒测试工具 - sonar的安装、配置与使用入门手册,用sonar检查代码质量实战演示的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。