Sonar - the ring to rule them all

23
Sonar - the ring to rule them all Sebastian Marek

Transcript of Sonar - the ring to rule them all

Page 1: Sonar - the ring to rule them all

Sonar - the ring to rule them all

Sebastian Marek

Page 2: Sonar - the ring to rule them all

CI

Continuous Integration

automated builds

static code analysis

code coverage reports

Page 3: Sonar - the ring to rule them all

CI

Continuous Inspection

code violations

code improvements

build stability

Page 4: Sonar - the ring to rule them all

Technical debt under control

architecture & design

comments

coding rules

potential bugs

code duplications

unit tests

complexity

Page 5: Sonar - the ring to rule them all

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/

Page 6: Sonar - the ring to rule them all

Sonar vs. phpUnderControl/Hudson

Continuous Integration Platform

vs.

Reporting Platform

Page 7: Sonar - the ring to rule them all

PHP support

PHP_Codesniffer

PHPUnit

PHP Depend

PHP Mess Detector

Page 8: Sonar - the ring to rule them all

Requirements

JDK 1.5+

Maven 2.0.9+, 2.1+, 2.2+

DB backend of your choice

MySQL

PostgreSQL

Oracle

MS SQL

Page 9: Sonar - the ring to rule them all

Installation

download

unzip

run

Page 10: Sonar - the ring to rule them all

Preparing for analysis – pom file

<project xmlns="http://maven.apache.org/POM/4.0.0"

xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<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>

Page 11: Sonar - the ring to rule them all

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>

Page 12: Sonar - the ring to rule them all

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>

Page 13: Sonar - the ring to rule them all

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>

Page 14: Sonar - the ring to rule them all

Maven configuration

<activeProfiles>

<activeProfile>php-profile</activeProfile>

</activeProfiles>

Page 15: Sonar - the ring to rule them all

Performing analysis

#> mvn sonar:sonar

Page 16: Sonar - the ring to rule them all

Integration

phpUnderControl via ant

Hudson via dedicated plugin

Page 17: Sonar - the ring to rule them all

ant task

<target name="sonar">

<exec dir="${basedir}/Source/" executable="mvn" failonerror="false" > <arg line="sonar:sonar" /> </exec>

</target>

Page 18: Sonar - the ring to rule them all

Code complexity

Page 19: Sonar - the ring to rule them all

Build results

Page 20: Sonar - the ring to rule them all

Code violations

Page 21: Sonar - the ring to rule them all

Time machine

Page 22: Sonar - the ring to rule them all

Resources

http://www.sonarsource.org/

http://docs.codehaus.org/display/SONAR/PHP+Plugin

@SonarSource

http://criticallog.thornet.net/

Page 23: Sonar - the ring to rule them all

Q&A