简介
转自oschina的介绍(http://www.oschina.net/p/sonar/)
Sonar (SonarQube)是一个开源平台,用于管理源代码的质量。Sonar 不只是一个质量数据报告工具,更是代码质量管理平台。支持的语言包括:Java、PHP、C#、C、Cobol、PL/SQL、Flex 等。
主要特点:
· 代码覆盖:通过单元测试,将会显示哪行代码被选中
· 改善编码规则
· 搜寻编码规则:按照名字,插件,**级别和类别进行查询
· 项目搜寻:按照项目的名字进行查询
· 对比数据:比较同一张表中的任何测量的趋势
架构图:
下载与安装
下载地址:http://www.sonarqube.org/downloads/
我下载的是:sonar-3.7.3.zip
解压(D:\install\sonar-3.7.3)
进入解压缩目录,修改conf/sonar.properties文件,配置数据库连接
|
1
2
3
4
5
6
7
8
9
10
11
12
|
......# Permissions to create tables and indexes must be granted to JDBC user.# The schema must be created first.#sonar.jdbc.username: sonar#sonar.jdbc.password: sonar.......#----- MySQL 5.x# Comment the embedded database and uncomment the following line to use MySQLsonar.jdbc.url:jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=truesonar.jdbc.username: rootsonar.jdbc.password: 123...... |
红色标注的是默认打开的,为了统一管理,我把它给注释掉了,
灰色背景的是新添加的,因为我使用的数据库是mysql
在bin(D:\install\sonar-3.7.3\bin)目录下有各种操作系统的可执行文件,我本地的操作系统是XP,所以进入D:\install\sonar-3.7.3\bin\windows-x86-32执行StartSonar.bat即可完成启动。
如果能访问说明成功了
配置maven
修改maven的配置文件E:\maven\apache-maven-3.1.1\conf\settings.xml,在profiles下添加以下代码
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.jdbc.url>jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8</sonar.jdbc.url>
<sonar.jdbc.driver>com.mysql.jdbc.Driver</sonar.jdbc.driver>
<sonar.jdbc.username>root</sonar.jdbc.username>
<sonar.jdbc.password>123</sonar.jdbc.password>
</properties>
</profile>
|
注:如果不配置,会出现连接不了数据库的异常
在项目里加下以下插件:
|
1
2
3
4
5
|
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
|
运行sonar测试
|
E:\git\656463>cd 656463-cms
E:\git\656463\656463-cms>mvn sonar:sonar |
好了,直接访问http://localhost:9000/即可看到测试结果了