Skip to content
springside edited this page May 5, 2012 · 41 revisions

##Overview Sonar -- an open platform to manage code quality. 是SCM, CI, Issue Tracker和Wiki外,另一个必不可少的项目管理软件.

什么maven site, 什么Jenkins插件,和它比都弱爆了。

Configuration

每次升级Sonar版本,总要做的几样配置,Sonar backup只能备份所有profile的rule和alert,以及Global Settings。

  • DashBoard: 在首页点击edit filter, 删除Versions,Links,BuildDates,加入Major violations,Minor violations,Coverage,Skip UnitTest。还有如JavaDoc,Duplication可以根据需要添加。
    另外,对于Multi-Module的项目,可以选显示subproject,而不是project。
  • Widgets: 在任一项目页点击Configure widgets, 删除LCOM4,Complexity和Descritpion。再把Events移到右边。
  • 调整分值: 直接加大2倍:在General Settings->General中,INFO=0;MINOR=3;MAJOR=9;CRITICAL=15;BLOCKER=30

SpringSide Profile

SpringSide的Profile在Soanr 3.0 的Sonar way with Findbugs规则上进行修改。 规则已导出到support/sonar目录里。

###Checkstyle changes

  • Enable "JavaNCSS", classMaximum from 1500 to 500, fileMaximum from 2000 to 600-- 排除注释后的每个方法/类的最大代码行数。methodMaximum保持50的默认值。
  • Enable "Nested For Depth", max from 1 to 3 -- if/else/for/while等嵌入代码的层数。
  • Enalbe "Parameter Number", max from 7 to 5
  • Change "Magic Number" from Minor to Info
  • Change "Redundant Throws" allow uncheked=true
  • Disable "Final Class"
  • Disable "Hide Utility Class Constructor"
  • Disable "Visibility Modifier"

可选修改:

  • Enable "Declaration Order", from Info to Minor (Optional)
  • Enalbe "One Statement Per Line" (Optional)

###PMD changes

  • Disable "Avoid Throwing Raw Exception Types"
  • Disable "Signature Declare Throws Exception"

可选修改:

  • Enable "Add Empty String" (Optional)
  • Enalbe "Assignment In Operand"(Optional)
  • Enable "Avoid Multiple Unary Operators" (Optional)
  • Enable "Boolean Get Method Name"(Optional)
  • Enable "Misplaced Null Check"(Optional)
  • Enalbe "Package case"(Optional)
  • Enable "Use Proper Class Loader" (Optional)

###FindBugs changes

  • Disable "Bad practice - Method invoked that should be only be invoked inside a doPrivileged block"
  • Disable "Correctness - Field not initialized in constructor"

可选修改:

  • Disable "Malicious code vulnerability - May expose internal representation by incorporating reference to mutable object"(Optional)
  • Disable "Malicious code vulnerability - May expose internal representation by returning reference to mutable object"(Optional)

###Sonar Rules changes

  • Enable "Avoid commented-out lines of code"

###告警阀值

  • Rules compliance : 95% warning, 90% error
  • Coverage : 70% warning, 50% error
  • Blocker violations/Critical violations : 1 warning, 2 error

返回参考手册