ソナーテストコードの品質の実用的なデモ
- 第1章:sonarqubeのインストールとアクティブ化
- ①ソナーク取得
- ②ソナルク構成
- ③Sonarqubeドライブの配置
- ④ソナルクベの始まり
- 第2章:Sonarqubeのエラー解決
- ①サポートされていないJDBCドライバープロバイダー:mysql [mysqlはsonarqube8.0以降はサポートされません]
- ②ディレクトリにJDBCドライバーが含まれていない:extensions / jdbc-driver / oracle [ドライバーが見つかりません]
- ③SonarQubeを実行するにはJava 11が必要です[sonarqube8.0にはjava11のサポートが必要です]
- ④リモートホストが既存の接続を強制的に閉じました。[Sonarqubeデータベースドライバーのバージョンが一致しません]
- so sonarqubeのデータベースサポートを表示する
- 第3章:SonarScannerプラグインのインストールと構成
- ①sonarScannerで取得
- ②SonarScannerが環境変数を設定する
- ③SonarScannerの設定
- 第4章:ソナーを使用してコード品質を確認する
- ①設定
- ②運用
- ③スキャンレポートを見る
- ④問題の分析と報告
- ⑤コード品質評価
- 第5章:ソナー関連の設定
- ①ソナー管理者ログイン
- ②ソナー設定
インストールプロセスは主に、メインプログラム sonarqube と sonarScanner プラグインの2つの部分に分かれており、 両方をインストールして構成すると、コードスキャンを実行できます。 Sonarqubeでは 、データベースの構成プロセスで多くの問題が発生しますが、第2章ではこれらの問題について説明します。
第1章:sonarqubeのインストールとアクティブ化
①ソナーク取得
②ソナルク構成
プログラムディレクトリを抽出した後、構成するsonar.propertiesにconfを入力します。
# 指定oracle数据库
sonar.jdbc.url=jdbc:oracle:thin:@10.10.18.70:1521/orcl
# 指定数据库用户名
sonar.jdbc.username=ncc_auto_sonar
# 指定数据库密码
sonar.jdbc.password=1
# 指定端口
sonar.web.port=9000
③Sonarqubeドライブの配置
ドライバーを乗せることを忘れないでください
④ソナルクベの始まり
StartSonarを使用してプログラムを起動し、クラッシュした場合は、それをcmdにドラッグして実行し、エラーメッセージを表示できます。第2章では、一般的なエラーソリューションのいくつかを紹介します。
次にlocalhost:9000にアクセスしてください。
第2章:Sonarqubeのエラー解決
①サポートされていないJDBCドライバープロバイダー:mysql [mysqlはsonarqube8.0以降はサポートされません]
Sonarqube 8.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
②ディレクトリにJDBCドライバーが含まれていない:extensions / jdbc-driver / oracle [ドライバーが見つかりません]
データベースドライバーが構成されていません。extensions / jdbc-driver / oracleの下にドライバーがないか、ドライバーが正しくありません。
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を実行するにはJava 11が必要です[sonarqube8.0にはjava11のサポートが必要です]
私が使用した元のバージョンはjava8でした。
実行中は、java11を使用して実行するように求められます。
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の公式サイトからダウンロード
インストール後、環境変数を設定できます。
④リモートホストが既存の接続を強制的に閉じました。[Sonarqubeデータベースドライバーのバージョンが一致しません]
このエラーを報告すると、データベースドライバーのバージョンが間違っているように感じられ、ドライバーを変更するだけです。
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: 远程主机强迫关闭了一个现有的连接。
次にlocalhost:9000にアクセスしてください。
so sonarqubeのデータベースサポートを表示する
設定文書のヘルプがたくさんある。私が検索できるオラクルを直接確認するためのサポートのOracleを下記のと同様に、ドライバの配置方法、および下記の公式サポートサイト。他の質問がある場合、あなたはそれでそれを見つけることができるかもしれません。問題の解決策。
第3章:SonarScannerプラグインのインストールと構成
①sonarScannerで取得
アドレスを取得:公式Webサイトからダウンロードし、
ダウンロード後に解凍します。
②SonarScannerが環境変数を設定する
ルートディレクトリの下のbinフォルダーを環境変数に追加します。
cmdにsonar-scanner -hと入力して、構成が正しいかどうかを確認します。
③SonarScannerの設定
この構成フォルダーの構成ファイルで構成します。
以前のsonarqubeデータベース構成と同じです。
# 指定oracle数据库
sonar.jdbc.url=jdbc:oracle:thin:@10.10.18.70:1521/orcl
# 指定数据库用户名
sonar.jdbc.username=ncc_auto_sonar
# 指定数据库密码
sonar.jdbc.password=1
第4章:ソナーを使用してコード品質を確認する
①設定
コードを確認する場所に、この構成ファイルsonar-project.propertiesを作成します。
sonarScanner公式ウェブサイトが提供する設定方法。
# 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
②運用
スキャンする構成ファイルが置かれているディレクトリーにsonar-scannerコマンドを入力します。
成功のサインをスキャンしています。
スキャンプロセスの詳細。
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 platform
dependent)
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 server
has 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: ------------------------------------------------------------------------
③スキャンレポートを見る
更新後、スキャン後に結果を確認できます!
④問題の分析と報告
バグをクリックして、多くの問題を確認します。
クリックしてこの問題であるのはなぜ?問題の原因を確認し、コードをトレースするために全体のピンクの部分をクリックします。
⑤コード品質評価
品質ゲートをクリックして、コード品質の包括的なスコアを表示します。
第5章:ソナー関連の設定
①ソナー管理者ログイン
ソナー管理者がログインします。
管理者アカウントとパスワードはどちらも管理者です
②ソナー設定
管理者は、ログインして初めて設定タブを表示できます。
気に入ったら気に入ってください❤!