Changes between Version 1 and Version 2 of sonar


Ignore:
Timestamp:
08/23/2012 09:26:44 AM (14 years ago)
Author:
chenchongqi
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • sonar

    v1 v2  
    33* Sonar是代码质量管理的开放平台,结合测试工具、代码分析工具。 
    44* 主要作用是通过各种量化的分析数据,不仅仅是静态bug分析,更多是代码整体结构和设计方面,长期对项目进行分析和监控,方便大家更加直观去评估和持续改善代码质量。 
     5 
     6== Install == 
     71. 下载及安装 [http://docs.codehaus.org/display/SONAR/Install+Sonar] 
     82. 修改/conf/sonar.properties: 
     9{{{ 
     10sonar.jdbc.username:                       sonar 
     11sonar.jdbc.password:                       sonar 
     12sonar.jdbc.url:                            jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8 
     13sonar.jdbc.driverClassName:                com.mysql.jdbc.Driver 
     14}}} 
     153. 修改maven配置settings.xml 
     16{{{ 
     17        <profile> 
     18            <id>sonar</id> 
     19            <activation> 
     20                <activeByDefault>true</activeByDefault> 
     21            </activation> 
     22            <properties> 
     23                <!-- EXAMPLE FOR MYSQL --> 
     24                <sonar.jdbc.url> 
     25                  jdbc:mysql://localhost:3306/sonar?useUnicode=true&amp;characterEncoding=utf8 
     26                </sonar.jdbc.url> 
     27                <sonar.jdbc.driverClassName>com.mysql.jdbc.Driver</sonar.jdbc.driverClassName> 
     28                <sonar.jdbc.username>sonar</sonar.jdbc.username> 
     29                <sonar.jdbc.password>sonar</sonar.jdbc.password> 
     30 
     31                <!-- optional URL to server. Default value is http://localhost:9000 --> 
     32                <sonar.host.url> 
     33                  http://localhost:9000 
     34                </sonar.host.url> 
     35            </properties> 
     36        </profile> 
     37}}} 
     384. 添加项目到sonar:  
     39{{{ 
     40mvn sonar:sonar 
     41}}} 
     42 
     43== Install Plugin == 
     441. 下载插件jar包并复制到 /extensions/plugins/ 目录 
     452. 重启sonar 
     46 
     47== Upgrade Sonar == 
     48[http://docs.codehaus.org/display/SONAR/Upgrade+guide] 
     49 
     501. 下载新版本,解压到新目录 
     512. 停止sonar服务 
     523. 复制原配置文件去新目录  sonar.properties and wrapper.conf 
     534. 复制插件和自定义规则去新目录  extensions/plugins and extensions/rules 
     545. 如果用了自己的jdbc驱动,也复制去新目录  /extensions/jdbc-driver/ 
     556. 启动新版本,打开http://localhost:9000/setup 完成剩余步骤 
     56 
     57== Review == 
     581. 建议安装2.14版本,因为从此版本开始可以在任意代码段发起review,之前版本只支持在扫描出问题的代码段review。 
     592. 如果在general settings中配置了邮箱,并且其他用户也配置自己的邮箱,在分发review的时候可以发邮件通知对方。 
     603. review必须指定一个原因,可以自定义。 
     614. 毕竟不是代码审核不是sonar的重点功能,使用起来不顺手,特别是没法针对具体的svn提交来审核,推荐别的代码审核工具例如电脑组正在使用的:[http://192.168.21.234:8080/r/ ReviewBoard]。 
     62 
     63== JPA Related == 
     64JPA单元测试手动执行mvn test都是成功的,但是集成在sonar中总是会报错 
     65{{{ 
     66Caused by: org.springframework.beans.factory.BeanCreationException: 
     67Could not autowire field: cn.com.pconline.enterprise.kuaisou.ProductSearcher 
     68cn.com.pconline.enterprise.service.BuildIndexService.productSearcher; 
     69nested exception is java.lang.IllegalArgumentException: 
     70Can not set cn.com.pconline.enterprise.kuaisou.ProductSearcher field 
     71cn.com.pconline.enterprise.service.BuildIndexService.productSearcher to $Proxy22 
     72}}} 
     73经过查证发现是cobertura-maven-plugin插件的影响,spring的@Autowire是按类型注入的,而cobertura 在Instrumentation步骤中会对类型有修改,导致spring的注入有问题,对于商城这样复杂的注入情况来说暂时没有好的办法,只能先去掉代 码覆盖率的检测步骤。 
     74http://blog.anorakgirl.co.uk/2010/01/maven-junit-cobertura-and-beancreationexception/ 
     75 
     76具体处理: 
     771. pom.xml里不要指定build阶段的cobertura-maven-plugin插件。 
     782. sonar的具体JPA项目settings中,sonar.core.codeCoveragePlugin设为false,缺省用是cobertura 
     79 
     80== LCOM4 == 
     811. Lack of Cohesion Among Method of Class  
     822. 帮助分析类的职责,数值越大表示该类可拆分的部分越多。 
     83 
     84== Design == 
     851. 包的依赖关系图 
     862. 目标是单向依赖 
     873. 避免依赖循环 
     88 
     89== Violations == 
     901. 代码质量分析 
     912. findbug、pmd等可配置插件 
     923. 自定义rule 
     934. 严重等级 
     945. 发起review 
     95 
     96== Unit Test == 
     971. 自动运行unit test 
     982. 自动分析测试覆盖率 
     993. 可以手动指定测试报告 
     100 
     101== SCM Plugin == 
     1021. 需要scm插件 
     1032. 配置scm 
     1043. 按时间统计提交数 
     1054. 浏览代码时显示提交人和时间