Reuse Sonar Checkstyle Violation Report for Custom Data Analysis

  1. Write a violation rules file;

  2. Import it into Sonar as a Quality Profile named as "MyRules";

  3. Add the following properties to ant script:

  4. Run Ant script, and you can get the report at $PROJECT_HOME/.sonar/checkstyle-result.xml;

  5. Use the following python script to extract data from the report:

    from xml.etree import ElementTree as ET tree = ET.parse('/path/to/checkstyle-result.xml') root = tree.getroot() cycleCnt = 0 nestCnt = 0 for error in root.iter('error'): msg = error.get('message') if msg.startswith('Cyclomatic'): cycleCnt += 1 if msg.startswith('Nested'): nestCnt += 1 print "Cyclomatic:",cycleCnt,"Nested:",nestCnt

See "Section 19.7: xml.etree.ElementTree" of documentation of Python 2.7.5 for details.

posted on 2014-03-18 08:05  leechau  阅读(207)  评论(0编辑  收藏  举报

导航