Date post: | 29-Jan-2018 |
Category: |
Documents |
Upload: | sebastian-marek |
View: | 3,787 times |
Download: | 0 times |
Sonar - the ring to rule them all
Sebastian Marek
CI
Continuous Integration
automated builds
static code analysis
code coverage reports
CI
Continuous Inspection
code violations
code improvements
build stability
Technical debt under control
architecture & design
comments
coding rules
potential bugs
code duplications
unit tests
complexity
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/
Sonar vs. phpUnderControl/Hudson
Continuous Integration Platform
vs.
Reporting Platform
PHP support
PHP_Codesniffer
PHPUnit
PHP Depend
PHP Mess Detector
Requirements
JDK 1.5+
Maven 2.0.9+, 2.1+, 2.2+
DB backend of your choice
MySQL
PostgreSQL
Oracle
MS SQL
Installation
download
unzip
run
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>
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>
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>
Maven configuration
<profile> <id>php-profile</id> <properties> <sonar.jdbc.url> jdbc:mysql://localhost:3306/sonar?useUnicode=true&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>
Maven configuration
<activeProfiles>
<activeProfile>php-profile</activeProfile>
</activeProfiles>
Performing analysis
#> mvn sonar:sonar
Integration
phpUnderControl via ant
Hudson via dedicated plugin
ant task
<target name="sonar">
<exec dir="${basedir}/Source/" executable="mvn" failonerror="false" > <arg line="sonar:sonar" /> </exec>
</target>
Code complexity
Build results
Code violations
Time machine
Resources
http://www.sonarsource.org/
http://docs.codehaus.org/display/SONAR/PHP+Plugin
@SonarSource
http://criticallog.thornet.net/
Q&A