sonar安装及使用篇

来源:互联网 发布:贪心算法举例 编辑:程序博客网 时间:2024/05/16 18:09

安装步骤:

sonar 下载地址:http://www.sonarsource.org/

下载好以后解压,需要修改配置文件(conf/sonar.properties)

#sonar.web.host:                           0.0.0.0#sonar.web.port:                           9000将前面的“#”删掉,端口改成指定的端口。
sonar.jdbc.username:                       sonarsonar.jdbc.password:                       sonar这里是指定mysql账号,注意密码需要和mysql中的sonar用户一致

sonar.jdbc.url: jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=truesonar.jdbc.driverClassName:  com.mysql.jdbc.Drivermysql链接地址。启动之前需要在mysql中创建sonar账号和sonar数据库。

mysql [localhost] {root} ((none)) > CREATE DATABASE IF NOT EXISTS sonar CHARACTER SET utf8 COLLATE utf8_general_ci;Query OK, 1 row affected (0.01 sec)mysql [localhost] {root} ((none)) > grant all privileges on sonar.* to 'sonar'@'localhost' identified by 'sonar';Query OK, 0 rows affected (0.00 sec)mysql [localhost] {root} ((none)) > flush privileges;Query OK, 0 rows affected (0.00 sec)

到bin目录相应的平台目录下运行sonar.sh脚本

sh sonar.sh start

启动后,可以访问http://localhost:9000见识下sonar的界面哈。


用户登陆密码是admin/admin

登陆后,需要配置一些东西。



比方说php,中文语言包。

使用步骤:

sonar简单一点,可以使用sonar-runner,复杂点的就是maven了。这里给大家讲下sonar-runner。

sonar-runner:下载地址:http://docs.codehaus.org/display/SONAR/Installing+and+Configuring+Sonar+Runner

解压后,修改conf/sonar-runner.properties

#----- Default Sonar serversonar.host.url=http://localhost:9000#----- PostgreSQL#sonar.jdbc.url=jdbc:postgresql://localhost/sonar#sonar.jdbc.driver=org.postgresql.Driver#----- MySQLsonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8sonar.jdbc.driver=com.mysql.jdbc.Driver#----- Oracle#sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE#sonar.jdbc.driver=oracle.jdbc.driver.OracleDriver#----- Global database settingssonar.jdbc.username=sonarsonar.jdbc.password=sonar#----- Default directory layout#sonar.sources=src/main/java#sonar.tests=src/test/java#sonar.binaries=target/classes#----- Default source code encodingsonar.sourceEncoding=UTF-8

使用sonar-runner前需要安装几个php扩展:

pear channel-discover pear.pdepend.orgpear install pdepend/PHP_Depend-betapear channel-discover pear.phpmd.orgpear install --alldeps phpmd/PHP_PMD-alphapear install PHP_CodeSniffer

在安装扩展时,出现错误的话,可能是pear的temp_dir没有写权限,可使用以下命令解决:

pear config-set temp_dir ~/tmppear config-set cache_dir ~/tmp/cache/

在项目目录下面,创建sonar-project.properties文件,内容如下:

# Required metadatasonar.projectKey=org.codehaus.sonar:php-sonar-runnersonar.projectName=testsonar.projectVersion=1.0# Comma-separated paths to directories with sources (required)sonar.sources=src,src2 #源码文件夹# Languagesonar.language=php  #指定语言# To deactivate features related to unit tests execution and coveragesonar.dynamicAnalysis=false# Encoding of the source filessonar.sourceEncoding=UTF-8

配置好以后,运行sonar-runner,没错误的情况下,进入http://localhost:9000便可以看到代码检查的结果了。




转载请注明来源url:http://blog.csdn.net/icoler/article/details/8286262

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

原创粉丝点击