一、安裝好了SonarQube服務(wù)端后,在其它電腦的瀏覽器上登陸,開始安裝其它編程語言檢測插件
成都創(chuàng)新互聯(lián)公司長期為數(shù)千家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為麻章企業(yè)提供專業(yè)的成都網(wǎng)站設(shè)計、網(wǎng)站建設(shè),麻章網(wǎng)站改版等技術(shù)服務(wù)。擁有十年豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。
系統(tǒng)已經(jīng)裝好的語言插件:
下載了軟件項目中常用的語言:Android、CSS、Web、XML
JAVA相關(guān)的:Checkstyle、Findbugs、PMD
Java 靜態(tài)分析工具分析對象 | 應(yīng)用技術(shù) |
Checkstyle | Java 源文件,缺陷模式匹配 |
FindBugs | 字節(jié)碼,缺陷模式匹配;數(shù)據(jù)流分析 |
PMD | Java 源代碼,缺陷模式匹配 |
下載完分析語言規(guī)則后,重啟服務(wù)
二、安裝命令行分析端
sonar的命令行分析端軟件有兩種分別是Runner和Scanner,官網(wǎng)文檔中寫的是Scanner,但Runner和它安裝、使用都基本一致。
1、在CentOS上安裝sonar-runner-dist-2.4
cd /usr/local/src/
wget http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip
unzip sonar-runner-dist-2.4.zip
mv sonar-runner-2.4/ /usr/local/
配置PATH路徑
vim /etc/profile
在文件最后加入如下內(nèi)容,保存并退出。
PATH=$PATH:/usr/local/sonar-runner-2.4/bin
export PATH
配置sonar-runner啟動配置文件
vim /usr/local/sonar-runner-2.4/conf/sonar-runner.properties
把下面內(nèi)容前#號去掉或增加后,保存并退出
sonar.jdbc.url=jdbc:MySQL://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.host.url=http://192.168.1.190
sonar.login=admin
sonar.password=admin
安裝成功后重啟服務(wù)器,在命令行運行以上命令并回顯,表示運行成功。
[root@sonar local]# sonar-runner -h
INFO:
INFO: usage: sonar-runner [options]
INFO:
INFO: Options:
INFO: -D,--define <arg> Define property
INFO: -e,--errors Produce execution error messages
INFO: -h,--help Display help information
INFO: -v,--version Display version information
INFO: -X,--debug Produce execution debug output
2、在CentOS上安裝sonar-scanner2.8
cd /usr/local/src/
wget https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-2.8.zip
unzip sonar-scanner-2.8.zip
mv sonar-scanner-2.8/ /usr/local/
配置PATH路徑
vim /etc/profile
在文件最后加入如下內(nèi)容,保存并退出。
PATH=$PATH:/usr/local/sonar-runner-2.4/bin:/usr/local/sonar-scanner-2.8/bin
export PATH
配置sonar-scanner啟動配置文件
vim /usr/local/sonar-scanner-2.8/conf/sonar-scanner.properties
把下面內(nèi)容前#號去掉或增加后,保存并退出
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.host.url=http://192.168.1.190
sonar.login=admin
sonar.password=admin
安裝成功后重啟服務(wù)器,在命令行運行以上命令并回顯,表示運行成功。
[root@sonar local]# sonar-scanner -h
INFO:
INFO: usage: sonar-scanner [options]
INFO:
INFO: Options:
INFO: -D,--define <arg> Define property
INFO: -h,--help Display help information
INFO: -v,--version Display version information
INFO: -X,--debug Produce execution debug output
INFO: -i,--interactive Run interactively
三、把開發(fā)程序的源代碼打包成zip文件上傳到安裝有Runner或Scanner的服務(wù)器上
解壓上傳的源代碼:
cd /usr/local/
unzip whale.zip
四、使用sonar-scanner進(jìn)行代碼質(zhì)量分析
1、在服務(wù)器上建立一個準(zhǔn)備用Scanner執(zhí)行的配置文件
cd whale/
vim sonar-project.properties
2、建立文件內(nèi)容如下:
# must be unique in a given SonarQube instance
sonar.projectKey=whale:scanner
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=whale-scanner
sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# Since SonarQube 4.2, this property is optional if sonar.modules is set.
# If not set, SonarQube starts looking for source code from the directory containing
# the sonar-project.properties file.
sonar.sources=.
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
3、保存并退出后運行命令進(jìn)行分析(分析中不能執(zhí)行Findbugs3.4.3分析,在web端卸載這個規(guī)則后可以正常分析):
sonar-scanner
4、在web中查看Scanner代碼質(zhì)量分析的結(jié)果。
五、使用sonar-Runner進(jìn)行代碼質(zhì)量分析
1、修改下Scanner執(zhí)行時的配置文件
cd /usr/local/whale/
vim sonar-project.properties
2、修改文件內(nèi)容如下:
# must be unique in a given SonarQube instance
sonar.projectKey=whale:runner
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=whale-runner
sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# Since SonarQube 4.2, this property is optional if sonar.modules is set.
# If not set, SonarQube starts looking for source code from the directory containing
# the sonar-project.properties file.
sonar.sources=.
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
3、保存并退出后運行命令進(jìn)行分析(分析中不能執(zhí)行Findbugs3.4.3分析,在web端卸載這個規(guī)則后可以正常分析):
sonar-runner
4、在web中查看runner代碼質(zhì)量分析的結(jié)果。
結(jié)果一樣,證明Runner和Scanner功能差不多。
當(dāng)前標(biāo)題:Sonar6.0應(yīng)用之二:SonarWeb界面配置及與Runner、Scanner集成進(jìn)行命令行代碼分析
當(dāng)前鏈接:http://aaarwkj.com/article20/ihhpco.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、小程序開發(fā)、網(wǎng)站營銷、網(wǎng)站維護(hù)、網(wǎng)站制作、微信公眾號
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)