DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

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.



Published

Jun 6, 2013

Last Updated

Jun 6, 2013

Category

Tech

Tags

  • checkstyle 4
  • etree 1
  • Python 136
  • sonar 17
  • xml 4

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor