SonarQube系列 目錄
- SonarQube (1) 基本環境搭建
- SonarQube (2) sonar runner安裝配置
- SonarQube (3) C++插件安裝與規則配置
- SonarQube (4) 運行一個Sample
- SonarQube (5) 集成至Jenkins
- SonarQube (終) Gitlab提交代碼自動化測試
拉取sonar-cxx插件源代碼
$ git clone https://github.com/SonarOpenCommunity/sonar-cxx.git
其中,sample代碼位于/sonar-cxx/sonar-cxx-plugin/src/samples/SampleProject2
$ cd /sonar-cxx/sonar-cxx-plugin/src/samples/SampleProject2
運行sonar-runner
$ sonar-runner
得到結果EXECUTION SUCCESS,運行成功
SonarQube Runner 2.4
Java 1.8.0_121 Oracle Corporation (64-bit)
Linux 3.10.0-514.6.2.el7.x86_64 amd64
INFO: Runner configuration file: /etc/sonar-runner-2.4/conf/sonar-runner.properties
INFO: Project configuration file: /root/sonar-sample/sonar-cxx/sonar-cxx-plugin/src/samples/SampleProject2/sonar-project.properties
INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Work directory: /root/sonar-sample/sonar-cxx/sonar-cxx-plugin/src/samples/SampleProject2/./.sonar
INFO: SonarQube Server 5.6.7
04:45:31.997 INFO - Load global repositories
...
...
04:45:34.852 INFO - Analysis report uploaded in 41ms
04:45:34.852 INFO - ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard/index/CxxPlugin:Sample
04:45:34.852 INFO - Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
04:45:34.853 INFO - More about the report processing at http://localhost:9000/api/ce/task?id=AV69XOLms3rpTnB5rfdL
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
Total time: 3.441s
Final Memory: 9M/220M
INFO: ------------------------------------------------------------------------
登錄頁面查看分析結果
復制根據分析結果中的url
04:45:34.852 INFO - ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard/index/CxxPlugin:Sample
在瀏覽器中打開
http://localhost:9000/dashboard/index/CxxPlugin:Sample
代碼分析結果展示
Sonar result
代碼問題列表
Code smell
參考
https://github.com/SonarOpenCommunity/sonar-cxx/wiki/Running-the-analysis