Sonar - the ring to rule them all

3,610 views
3,418 views

Published on

With continuous integration process in place, at some point you will need to properly track the progress not only of the build itself, but also how in overall your code quality changes. You want to know whether the code complies to the rules you have set up, whether over time it gets better and at the same time you want to communicate the progress to the business. And all of that can be achieved with Sonar! This talk will fill the gap in my PHPNW10 talk "The Journey towards Continuous Integration" about Sonar and the state of PHP plugin for it.

0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,610
On SlideShare
0
From Embeds
0
Number of Embeds
136
Actions
Shares
0
Downloads
125
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Sonar - the ring to rule them all

  1. 1. Sonar - the ring to rule them all Sebastian Marek
  2. 2. CI <ul><li>Continuous Integration </li><ul><li>automated builds
  3. 3. static code analysis
  4. 4. code coverage reports </li></ul></ul>
  5. 5. CI <ul><li>Continuous Inspection </li><ul><li>code violations
  6. 6. code improvements
  7. 7. build stability </li></ul></ul>
  8. 8. Technical debt under control <ul><li>architecture & design
  9. 9. comments
  10. 10. coding rules
  11. 11. potential bugs
  12. 12. code duplications
  13. 13. unit tests
  14. 14. complexity </li></ul>
  15. 15. What is Sonar? “ Sonar is the central place to manage code quality, offering visual reporting on and across projects and enabling to replay the past to follow metrics evolution” source: http://www.sonarsource.org/
  16. 16. Sonar vs. phpUnderControl/Hudson Continuous Integration Platform vs. Reporting Platform
  17. 17. PHP support <ul><li>PHP_Codesniffer
  18. 18. PHPUnit
  19. 19. PHP Depend
  20. 20. PHP Mess Detector </li></ul>
  21. 21. Requirements JDK 1.5+ <ul><li>Maven 2.0.9+, 2.1+, 2.2+
  22. 22. DB backend of your choice </li><ul><li>MySQL
  23. 23. PostgreSQL
  24. 24. Oracle
  25. 25. MS SQL </li></ul></ul>
  26. 26. Installation <ul><li>download
  27. 27. unzip
  28. 28. run </li></ul>
  29. 29. Preparing for analysis – pom file <project xmlns =&quot; http://maven.apache.org/POM/4.0.0 &quot; xmlns:xsi =” http://www.w3.org/2001/XMLSchema-instance &quot; xsi:schemaLocation =&quot; http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd &quot;> <modelVersion> 4.0.0 </modelVersion> <groupId> org.bovigo </groupId> <artifactId> vfs </artifactId> <name> VFS_Stream </name> <version> 1.0 </version> <!-- For the moment,specify pom as packaging for php projects --> <packaging> pom </packaging> </project>
  30. 30. Preparing for analysis – pom file <build> <!-- You cannot omit this one, because maven will implicitely add src/main/java to it --> <sourceDirectory> ${basedir}/src/main/php </sourceDirectory> <testSourceDirectory> ${basedir}/src/test </testSourceDirectory> </build>
  31. 31. Preparing for analysis – pom file <!-- some properties that you may want to change --> <properties> <sonar.language> php </sonar.language> <sonar.phpPmd.shouldRun> true </sonar.phpPmd.shouldRun> <sonar.phpCodesniffer.shouldRun> true </sonar.phpCodesniffer.shouldRun> <sonar.phpDepend.shouldRun> true </sonar.phpDepend.shouldRun> <sonar.phpUnit.shouldRun> true </sonar.phpUnit.shouldRun> <sonar.phpcpd.shouldRun> true </sonar.phpcpd.shouldRun> </properties>
  32. 32. Maven configuration <profile> <id> php-profile </id> <properties> <sonar.jdbc.url> jdbc:mysql://localhost:3306/sonar?useUnicode=true&amp;characterEncoding=utf8 </sonar.jdbc.url> <sonar.jdbc.driver> com.mysql.jdbc.Driver </sonar.jdbc.driver> <sonar.jdbc.username> sonar </sonar.jdbc.username> <sonar.jdbc.password> s0n4rU53r </sonar.jdbc.password> </properties> </profile>
  33. 33. Maven configuration <activeProfiles> <activeProfile> php-profile </activeProfile> </activeProfiles>
  34. 34. Performing analysis #> mvn sonar:sonar
  35. 35. Integration <ul><li>phpUnderControl via ant
  36. 36. Hudson via dedicated plugin </li></ul>
  37. 37. ant task <target name =&quot; sonar &quot;> <exec dir =&quot; ${basedir}/Source/ &quot; executable =&quot; mvn &quot; failonerror =&quot; false &quot; > <arg line =&quot; sonar:sonar &quot; /> </exec> </target>
  38. 38. Code complexity
  39. 39. Build results
  40. 40. Code violations
  41. 41. Time machine
  42. 42. Resources <ul><li>http://www.sonarsource.org/
  43. 43. http://docs.codehaus.org/display/SONAR/PHP+Plugin
  44. 44. @SonarSource
  45. 45. http://criticallog.thornet.net/ </li></ul>
  46. 46. Q&A

×