SonarQube代碼質量管理平臺安裝與使用
#mysql -u root -p mysql> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci; mysql> CREATE USER 'sonar' IDENTIFIED BY 'sonar'; mysql> GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar'; mysql> GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar'; mysql> FLUSH PRIVILEGES; |
字體: 小 中 大 | 上一篇 下一篇 | 打印 | 我要投稿
#vi sonar.properties sonar.jdbc.username: sonar sonar.jdbc.password: sonar sonar.jdbc.url: jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true # Optional properties sonar.jdbc.driverClassName: com.mysql.jdbc.Driver |
修改sonar-runner的配置文件
切換至sonar-runner的安裝目錄下,修改sonar-runner.properties
根據實際使用數據庫情況取消相應注釋
#Configure here general information about the environment, such as SonarQube DB details for example #No information about specific project should appear here #----- Default SonarQube server sonar.host.url=http://localhost:9000 #----- PostgreSQL #sonar.jdbc.url=jdbc:postgresql://localhost/sonar #----- MySQL sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8 #----- Oracle #sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE #----- Microsoft SQLServer #sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor #----- Global database settings sonar.jdbc.username=sonar sonar.jdbc.password=sonar #----- Default source code encoding sonar.sourceEncoding=UTF-8 #----- Security (when 'sonar.forceAuthentication' is set to 'true') sonar.login=admin sonar.password=admin |
3.添加數據庫驅動
除了Oracle數據庫外,其它數據庫驅動都默認已經提供了,且這些已添加的驅動是sonar唯一支持的,因此不需要修改
如果是Oracle數據庫,需要復制JDBC驅動至<install_directory>/extensions/jdbc-driver/oracle目錄
4.啟動服務
目錄切換至sonar的<install_directory>/bin/linux-x86-64/目錄,啟動服務
#./sonar.sh start 啟動服務
#./sonar.sh stop 停止服務
#./sonar.sh restart 重啟服務
至此,sonar就安裝好了
訪問http:\\localhost:9000即可
5.sonar中文補丁包安裝
中文包安裝
安裝中文補丁包可以通過訪問http:\\localhost:9000,打開sonar后,進入更新中心安裝
或者下載中文補丁包后,放到SONARQUBE_HOME/extensions/plugins目錄,然后重啟SonarQube服務 sonar作為Linux服務并開機自啟動
新建文件/etc/init.d/sonar,輸入如下內容:
#!/bin/sh # # rc file for SonarQube # # chkconfig: 345 96 10 # description: SonarQube system (www.sonarsource.org) # ### BEGIN INIT INFO # Provides: sonar # Required-Start: $network # Required-Stop: $network # Default-Start: 3 4 5 # Default-Stop: 0 1 2 6 # Short-Description: SonarQube system (www.sonarsource.org) # Description: SonarQube system (www.sonarsource.org) ### END INIT INFO /usr/bin/sonar $* |
SonarQube開機自啟動(Ubuntu, 32位):
sudo ln -s $SONAR_HOME/bin/linux-x86-32/sonar.sh /usr/bin/sonar
sudo chmod 755 /etc/init.d/sonar
sudo update-rc.d sonar defaults
SonarQube開機自啟動(RedHat, CentOS, 64位):
sudo ln -s $SONAR_HOME/bin/linux-x86-64/sonar.sh /usr/bin/sonar
sudo chmod 755 /etc/init.d/sonar
sudo chkconfig --add sonar
使用SonarQube Runner分析源碼
預置條件
已安裝SonarQube Runner且環境變量已配置,即sonar-runner命令可在任意目錄下執行
1.在項目源碼的根目錄下創建sonar-project.properties配置文件
以android項目為例:
sonar.projectKey=android-sonarqube-runner |
注:要使用Android Lint
規則分析需要先訪問http:\\localhost:9000更新中心添加Android Lint插件,使其可以分析Android Lint規則
2.執行分析
切換到項目源碼根目錄,執行命令
# sonar-runner
分析成功后訪問http:\\localhost:9000即可查看分析結果
不同參數的意思:
http://docs.codehaus.org/display/SONAR/Analysis+Parameters
不同項目的源碼分析示例下載:
https://github.com/SonarSource/sonar-examples/zipball/master
posted on 2013-09-25 11:09 順其自然EVO 閱讀(3011) 評論(0) 編輯 收藏 所屬分類: 測試學習專欄