make use of sonar for your mobile developments - it's easy and useful!

32
Tél : +41 (0) 21 312 94 15 Fax : +41 (0) 21 312 94 16 www.octo.ch © OCTO 2013 Avenue du Théâtre 7 1005 Lausanne - SUISSE 1 October 26th, 2013 Make use of Sonar on your mobile developments - It’s easy and useful!

Upload: cyrilpicat

Post on 06-May-2015

11.622 views

Category:

Technology


7 download

DESCRIPTION

Presentation given at Soft-Shake 2013 conference in Geneva. Presents the status and maturity of SonarQube software quality management tool on Android and iOS platforms. First part consists of an overview of alternative quality tools and a presentation of Sonar features on these two mobile platforms. The second part of the presentation consists of a demo of SonarQube on two open-source projects.

TRANSCRIPT

Page 1: Make use of Sonar for your mobile developments - It's easy and useful!

Tél : +41 (0) 21 312 94 15Fax : +41 (0) 21 312 94 16www.octo.ch© OCTO 2013

Avenue du Théâtre 71005 Lausanne - SUISSE

1

October 26th, 2013

Make use of Sonar on your mobile developments- It’s easy and useful!

Page 2: Make use of Sonar for your mobile developments - It's easy and useful!

Romain Felden: Java / Android developer

Cyril Picat: C++, iOS, Groovy/Grails developer

OCTO Technology

2

Who We Are

Sonar Android

Lint Plugin

Android Maven Plugin

Quality Analysis Tools for Android

Jenkins Quality Dashboard

iOS

Sonar Objective-C

Plugin

Romain Felden: Java / Android developer

Cyril Picat: C++, iOS, Groovy/Grails developer

OCTO Technology

Page 3: Make use of Sonar for your mobile developments - It's easy and useful!

3

Agenda

QUALITY TOOLS ON MOBILE1

SONAR PLUGINS PRESENTATION2

3 HOW-TO & DEMO IOS

4 HOW-TO & DEMO ANDROID

5 CONCLUSION

Page 4: Make use of Sonar for your mobile developments - It's easy and useful!

Sonar For the UninitiatedManage quality of your software

Across languages/platforms (> 20)Across projectsAcross timeAcross multiple axis/depths

A web app for (re)viewing, a back-end for analysis

4

Page 5: Make use of Sonar for your mobile developments - It's easy and useful!

5

QUALITY TOOLS ON MOBILE

Agenda

1

Page 6: Make use of Sonar for your mobile developments - It's easy and useful!

Quality Tools on Mobile

19xx

sloccount/cloc

ClangOCUnit (X

code 2)

2008First iOS

SDK

2007

GTM

2009

Code coverage (X

code 3)

GHUnit

2011

OCUnit (Xcode 4)

Code coverage (L

LVM)

Xcode plugin for J

enkins

2012

OCLint (Clang)

Quality analys

is on Je

nkins

Sonar Obj-C

2013

XCUnit / Bot (X

code 5)

TESTS QUALITY

Page 7: Make use of Sonar for your mobile developments - It's easy and useful!

Quality Tools on Mobile

7

2012/06

v0.0.1- Basic

v0.2 - OCLint

2013/10

v0.3.1 -Tests

and

2013/07

Pull request

Sonar Objective-C

Plugin

coverage

metrics

Page 8: Make use of Sonar for your mobile developments - It's easy and useful!

Quality Tools on Mobile

Emma (

last re

lease)

2008First Android SDK

2005 2009

JaCoCo (E

clEmma)

2011

Android Lint

2012

Quality Tools

for Andro

id

sonar-a

ndroid-li

nt-plugin

20132004

Cobertur

a (firs

t relea

se)

2001

Checkst

yle

maven-andro

id-plugin

Page 9: Make use of Sonar for your mobile developments - It's easy and useful!

9

SONAR PLUGINS PRESENTATION

Agenda

2

Page 10: Make use of Sonar for your mobile developments - It's easy and useful!

Sonar Plugins Features

10

Android iOS

Complexity √ X (*)

Design √ XDocumentation √ √

Duplications √ √Issues √ (140) √ (58)

Size √ √ (*)

Tests √ √

(*) integrated as issues

(*) only LOC and files

Page 11: Make use of Sonar for your mobile developments - It's easy and useful!

Sonar Plugin Architecture

11

Sonar Core

xctool

Build

Measures/Issues integration

Quality management

Measures/Issues computation

Squ

id p

lugi

n

Sur

efire

se

nsor

Cob

ertu

ra

sens

or

OC

Lint

se

nsor

gcovr oclint

xcodebuild / xctool

run-

sona

r.sh

sona

r-ru

nner

Sonar

Sonar ObjC

Platform

Sonar Objective-C plugin

Page 12: Make use of Sonar for your mobile developments - It's easy and useful!

Sonar Plugin Architecture

12

Sonar Core

Build

Measures/Issues integration

Quality management

Measures/Issues computation

Squ

id p

lugi

n

Sur

efire

pl

ugin

Son

ar A

ndro

id p

lugi

n

Sonar

Android Plugin

Platform

Find

bugs

pl

ugin

Che

ckst

yle

plug

in

JaC

oCo

plug

in

PM

Dpl

ugin

mavenant gradle

Page 13: Make use of Sonar for your mobile developments - It's easy and useful!

Testing / Quality Tools Integration

13

Quality Unit TestingUnit TestingUnit Testing BDD UI TestingUI TestingUI TestingUI Testing

...

√ √ X X X X X X X

OC

Lint

OC

Uni

t /

XC

Uni

t

GH

Uni

t

GTM Kiw

i

UI

Aut

omat

ion

KIF

Fran

k /

UIS

pec

* * ** = in roadmap

Page 14: Make use of Sonar for your mobile developments - It's easy and useful!

Testing / Quality Tools Integration

14

Unit and Integration Testing

Unit and Integration Testing

Unit and Integration Testing UI Quality checksQuality checksQuality checksQuality checks

√ √ √ √ √ √ √ √

JUni

t

Rob

otiu

m

Rob

olec

tric

UIA

utom

ator

Che

ckst

yle

PM

D

Find

bugs

Lint

Page 15: Make use of Sonar for your mobile developments - It's easy and useful!

15

HOW-TO & DEMO

Agenda

3

Page 16: Make use of Sonar for your mobile developments - It's easy and useful!

How-to

16

Install Sonar, Sonar Runner and Sonar Objective-C plugin

Install prerequisites (xctool, gcovr, oclint)

Configure your project

Run analysis

Page 17: Make use of Sonar for your mobile developments - It's easy and useful!

Configure your project

17

Copy run-sonar.sh in your Xcode project root folder and make it executable

Copy sonar-project.properties in your Xcode project root folder

Edit the sonar-project.properties file to match your Xcode iOS/MacOS project

Page 19: Make use of Sonar for your mobile developments - It's easy and useful!

sonar-project.properties

X

#  Project  descriptionsonar.projectKey=my-­‐projectsonar.projectName=My  projectsonar.projectVersion=1.0sonar.projectDescription=Fake  description  #  Path  to  source  directories  sonar.sources=srcDir1,srcDir2  #  Xcode  project  configuration  (.xcodeproj  or  .xcworkspace)sonar.objectivec.project=myApplication.xcodeproj  sonar.objectivec.appScheme=myApplicationsonar.objectivec.testScheme=myApplicationTests

Page 20: Make use of Sonar for your mobile developments - It's easy and useful!

Run it!

X

>  ./run-­‐sonar.sh

Page 21: Make use of Sonar for your mobile developments - It's easy and useful!

Jenkins Quality Dashboard

19

Almost feature complete

No code checks

Time-consuming, error prone and intrusive

Weak reporting and configuration

Page 22: Make use of Sonar for your mobile developments - It's easy and useful!

How-to using maven

20

Install Sonar and Sonar Android plugin

Run analysis

Connect ADB in root mode

Add maven profile(s) to your module(s)

Page 23: Make use of Sonar for your mobile developments - It's easy and useful!

Maven structure

21

Parent module

Application module

Library module

Integration testing module

Page 24: Make use of Sonar for your mobile developments - It's easy and useful!

Demo

22

Morse Flash

https://github.com/jayway/maven-android-plugin-samples

Page 25: Make use of Sonar for your mobile developments - It's easy and useful!

Maven profilesparent module

X

<profile> <id>sonar</id> <modules> <module>morse-lib</module> <module>morseflash-app</module> <module>morseflash-instrumentation</module> </modules>

<properties> <sonar.profile>Android Lint</sonar.profile> <sonar.jacoco.excludes>*test*</sonar.jacoco.excludes> <sonar.jacoco.itReportPath>target/jacoco-it.exec</sonar.jacoco.itReportPath> <sonar.jacoco.reportPath>jacoco.exec</sonar.jacoco.reportPath> <sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin> <sonar.skippedModules>morseflash-instrumentation</sonar.skippedModules> <sonar.exclusions>**/org/jacoco/**</sonar.exclusions> <jacoco.version>0.6.2.201302030002</jacoco.version> </properties>

<dependencyManagement> <dependencies> <dependency> <groupId>org.jacoco</groupId> <artifactId>org.jacoco.agent</artifactId> <version>${jacoco.version}</version> <classifier>runtime</classifier> </dependency> </dependencies> </dependencyManagement> <build> <pluginManagement> <plugins> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>${jacoco.version}</version> </plugin> </plugins> </pluginManagement> </build></profile>

Page 26: Make use of Sonar for your mobile developments - It's easy and useful!

Maven profilesapplication module (includes unit testing)

X

<profile> <id>sonar</id> <dependencies> <dependency> <groupId>org.jacoco</groupId> <artifactId>org.jacoco.agent</artifactId> <classifier>runtime</classifier> <scope>compile</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <executions> <execution> <id>instrument-classes</id> <goals> <goal>instrument</goal> </goals> <configuration> <excludes> <exclude>*test*</exclude> <exclude>*/test/*</exclude> </excludes> </configuration> </execution> <execution> <id>restore-instrumented-classes</id> <phase>package</phase> <goals> <goal>restore-instrumented-classes</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>com.jayway.maven.plugins.android.generation2</groupId> <artifactId>android-maven-plugin</artifactId> <configuration> <test> <coverage>true</coverage> <createReport>true</createReport> </test> </configuration> <extensions>true</extensions> </plugin> </plugins> </build></profile>

Page 27: Make use of Sonar for your mobile developments - It's easy and useful!

Maven profilesintegration testing module

X

<profiles> <profile> <id>sonar</id> <build> <plugins> <plugin> <groupId>com.jayway.maven.plugins.android.generation2</groupId> <artifactId>android-maven-plugin</artifactId> <configuration> <dex> <!-- Required for EMMA --> <noLocals>true</noLocals> </dex> <test> <coverage>true</coverage> <createReport>true</createReport> </test> </configuration> <executions> <execution> <id>pull-coverage</id> <phase>post-integration-test</phase> <goals> <goal>pull</goal> </goals> <configuration> <pullSource>/data/data/com.simpligility.android.morseflash/files/coverage.ec</pullSource> <pullDestination>${project.basedir}/../morseflash-app/target/jacoco-it.exec</pullDestination> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile></profiles>

Page 28: Make use of Sonar for your mobile developments - It's easy and useful!

Run it!

X

>  mvn  -­‐P  sonar  clean  install

>  mvn  -­‐P  sonar  sonar:sonar

Page 29: Make use of Sonar for your mobile developments - It's easy and useful!

23

CONCLUSION

Agenda

5

Page 30: Make use of Sonar for your mobile developments - It's easy and useful!

Why Use Sonar?

24

Mobile projects are small and short, is it applicable?

Three typical uses cases:

Small and short projects

Assessments

Bigger projects (there are!)

Page 32: Make use of Sonar for your mobile developments - It's easy and useful!

Tél : +41 (0) 21 312 94 15Fax : +41 (0) 21 312 94 16www.octo.ch© OCTO 2013

Avenue du Théâtre 71005 Lausanne - SUISSE

26

Questions/Answers