beyond the basics of sonarqube: improve your java(script) code even further

95
Beyond the basics of SonarQube Improve your Java(Script) even further Johan Janssen (Info Support) @johanjanssen42

Upload: johan-janssen

Post on 21-Apr-2017

26 views

Category:

Internet


1 download

TRANSCRIPT

Page 1: Beyond the basics of SonarQube: improve your Java(Script) code even further

Beyond the basics of SonarQube

Improve your Java(Script) even

furtherJohan Janssen (Info Support) @johanjanssen42

Page 2: Beyond the basics of SonarQube: improve your Java(Script) code even further

Agenda Basic features Analyzing data Code review Hunting bad design

and architecture Testing

Other languages Leftovers Using SonarQube on

existing projects Tips / summary Questions

Page 3: Beyond the basics of SonarQube: improve your Java(Script) code even further

Quality for thousands of years

Page 4: Beyond the basics of SonarQube: improve your Java(Script) code even further

Quality after years of improvements

Page 5: Beyond the basics of SonarQube: improve your Java(Script) code even further

Quality for 39 days

Page 6: Beyond the basics of SonarQube: improve your Java(Script) code even further

Bugs Microsoft Applications: "about 10 - 20

defects per 1000 lines of code during in-house testing, and 0.5 defect per 1000 lines of code in released product (Dave Moore 1992).“

Page 7: Beyond the basics of SonarQube: improve your Java(Script) code even further

Bugs NASA's Spirit rover became unresponsive

on January 21, 2004, a few weeks after landing on Mars. (Wikipedia)

In January 2009, Google's search engine erroneously notified users that every web site world wide was potentially malicious, including its own. (Wikipedia)

Page 8: Beyond the basics of SonarQube: improve your Java(Script) code even further

Find them as fast as possible

Page 9: Beyond the basics of SonarQube: improve your Java(Script) code even further

Why should I use SonarQube? I’m told to use it. We need to achieve certain results (SIG…) I want to improve my coding standards

Page 10: Beyond the basics of SonarQube: improve your Java(Script) code even further

SonarQube Platform to manage code quality Open source, possible to pay for support

and some plugins Since 2006; now they have 200 customers

and SonarQube is used in 15.000 organizations

Active community: support, plugins, books

Page 11: Beyond the basics of SonarQube: improve your Java(Script) code even further

SonarQube2013: 5 releases of SonarQube platform 130 releases of ecosystem products 75,000 downloads of SonarQube 13,000+ messages on mailing lists

Page 12: Beyond the basics of SonarQube: improve your Java(Script) code even further

SonarQube architecture

Page 13: Beyond the basics of SonarQube: improve your Java(Script) code even further

SonarQube basic features

Page 14: Beyond the basics of SonarQube: improve your Java(Script) code even further
Page 15: Beyond the basics of SonarQube: improve your Java(Script) code even further
Page 16: Beyond the basics of SonarQube: improve your Java(Script) code even further
Page 17: Beyond the basics of SonarQube: improve your Java(Script) code even further
Page 18: Beyond the basics of SonarQube: improve your Java(Script) code even further
Page 19: Beyond the basics of SonarQube: improve your Java(Script) code even further
Page 20: Beyond the basics of SonarQube: improve your Java(Script) code even further
Page 21: Beyond the basics of SonarQube: improve your Java(Script) code even further

Differential views Leak Period

Page 22: Beyond the basics of SonarQube: improve your Java(Script) code even further

Differential views

Page 23: Beyond the basics of SonarQube: improve your Java(Script) code even further

Configure dashboards

Page 24: Beyond the basics of SonarQube: improve your Java(Script) code even further

Configure dashboards

Page 25: Beyond the basics of SonarQube: improve your Java(Script) code even further

Overview

Profile

Rules

Projects

Page 26: Beyond the basics of SonarQube: improve your Java(Script) code even further
Page 27: Beyond the basics of SonarQube: improve your Java(Script) code even further
Page 28: Beyond the basics of SonarQube: improve your Java(Script) code even further

Overview

ProjectsQuality Gates

Page 29: Beyond the basics of SonarQube: improve your Java(Script) code even further

Quality Gates

Page 30: Beyond the basics of SonarQube: improve your Java(Script) code even further

Notifications

Page 31: Beyond the basics of SonarQube: improve your Java(Script) code even further

Analysing data

Page 32: Beyond the basics of SonarQube: improve your Java(Script) code even further

Compare

Page 33: Beyond the basics of SonarQube: improve your Java(Script) code even further

Measures

Page 34: Beyond the basics of SonarQube: improve your Java(Script) code even further

Measure Filter as Bubble Chart

Page 35: Beyond the basics of SonarQube: improve your Java(Script) code even further

Filter Motion Chart

Page 36: Beyond the basics of SonarQube: improve your Java(Script) code even further

What is good code?

Page 37: Beyond the basics of SonarQube: improve your Java(Script) code even further

Code review

Page 38: Beyond the basics of SonarQube: improve your Java(Script) code even further

Roles

Page 39: Beyond the basics of SonarQube: improve your Java(Script) code even further
Page 40: Beyond the basics of SonarQube: improve your Java(Script) code even further
Page 41: Beyond the basics of SonarQube: improve your Java(Script) code even further

Why code reviews?

“We all need people who will give us feedback. That's how we improve.”

- Bill Gates

Page 42: Beyond the basics of SonarQube: improve your Java(Script) code even further

Hunting bad design and architecture

Page 43: Beyond the basics of SonarQube: improve your Java(Script) code even further

Hunting bad design and architecture

Page 44: Beyond the basics of SonarQube: improve your Java(Script) code even further

Architectural constraints

Page 45: Beyond the basics of SonarQube: improve your Java(Script) code even further

Architectural constraints

Page 46: Beyond the basics of SonarQube: improve your Java(Script) code even further

Testing

Page 47: Beyond the basics of SonarQube: improve your Java(Script) code even further

Now manual execution of unit tests

mvn clean installmvn sonar:sonar

mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install

-Dmaven.test.failure.ignore=truemvn sonar:sonar

Page 48: Beyond the basics of SonarQube: improve your Java(Script) code even further

Coverage per test Configure the POM (see next slide) Activate profile to get coverage per test

informationmvn org.jacoco:jacoco-maven-

plugin:prepare-agent clean install -Pcoverage-per-test

Analyze the projectmvn sonar:sonar

Page 49: Beyond the basics of SonarQube: improve your Java(Script) code even further
Page 50: Beyond the basics of SonarQube: improve your Java(Script) code even further
Page 51: Beyond the basics of SonarQube: improve your Java(Script) code even further

Integration testing

Page 52: Beyond the basics of SonarQube: improve your Java(Script) code even further

Integration testing ! Unit testing

Page 53: Beyond the basics of SonarQube: improve your Java(Script) code even further

Integration testing

Page 54: Beyond the basics of SonarQube: improve your Java(Script) code even further

Integration testing

Page 55: Beyond the basics of SonarQube: improve your Java(Script) code even further
Page 56: Beyond the basics of SonarQube: improve your Java(Script) code even further

Integration testing Add integration test coverage widget to

SonarQube Download Jacoco agent Configuration for Tomcat’s catalina.bat:set JACOCO=-javaagent:$path$\lib\jacocoagent.jar,destfile=$resultpath$\jacoco.exec,append=false,includes=com.dockerpi.*set JAVA_OPTS=%JAVA_OPTS% %JACOCO%

Page 57: Beyond the basics of SonarQube: improve your Java(Script) code even further

Integration testing Start Tomcat Execute tests (manual, integration,

performance…) Stop Tomcat and execute SonarQube

analysismvn clean install sonar:sonar

-Dsonar.dynamicAnalysis=reuseReports

-Dsonar.jacoco.itReportPath=$resultpath$\jacoco.exec

Page 58: Beyond the basics of SonarQube: improve your Java(Script) code even further

Unit and integration testing combined

Page 59: Beyond the basics of SonarQube: improve your Java(Script) code even further

PMD rules for unit testing

Page 60: Beyond the basics of SonarQube: improve your Java(Script) code even further
Page 61: Beyond the basics of SonarQube: improve your Java(Script) code even further

Pitest plugin

Page 62: Beyond the basics of SonarQube: improve your Java(Script) code even further

Pitest plugin Enable ‘Survived mutant’ rule in

SonarQube Quality Profile Configure Pitest for instance with Maven

(see next slides)

Page 63: Beyond the basics of SonarQube: improve your Java(Script) code even further

Pitest plugin Execute tests and send results to

SonarQubemvn org.pitest:pitest-maven:mutationCoveragemvn sonar:sonar

-Dsonar.pitest.mode=reuseReport

Page 64: Beyond the basics of SonarQube: improve your Java(Script) code even further

Pitest plugin Maven configuration inside the build/plugins

section<plugin>  <groupId>org.pitest</groupId>  <artifactId>pitest-maven</artifactId>  <version>LATEST</version>  <configuration>    <inScopeClasses>      <param>com.example*</param>    </inScopeClasses>    <targetClasses>      <param>com.example*</param>    </targetClasses>    <outputFormats>      <outputFormat>XML</outputFormat>     </outputFormats>  </configuration></plugin>

Page 65: Beyond the basics of SonarQube: improve your Java(Script) code even further

Pitest plugin

Page 66: Beyond the basics of SonarQube: improve your Java(Script) code even further

Other languages

Page 67: Beyond the basics of SonarQube: improve your Java(Script) code even further

JavaScript

Page 68: Beyond the basics of SonarQube: improve your Java(Script) code even further

CSS

Page 69: Beyond the basics of SonarQube: improve your Java(Script) code even further

Web plugin

Page 70: Beyond the basics of SonarQube: improve your Java(Script) code even further

Import unknown files

Page 71: Beyond the basics of SonarQube: improve your Java(Script) code even further

Import unknown files

Page 72: Beyond the basics of SonarQube: improve your Java(Script) code even further

Leftovers

Page 73: Beyond the basics of SonarQube: improve your Java(Script) code even further

Branches mvn sonar:sonar -Dsonar.branch=4.4

Page 74: Beyond the basics of SonarQube: improve your Java(Script) code even further

Exclusions Ignore files Ignore issues Ignore duplications Ignore code coverage Example:mvn sonar:sonar -Dsonar.exclusions=

src/main/webapp/lib/*.js

Page 75: Beyond the basics of SonarQube: improve your Java(Script) code even further

Tab metrics plugin

Page 76: Beyond the basics of SonarQube: improve your Java(Script) code even further
Page 77: Beyond the basics of SonarQube: improve your Java(Script) code even further

Duplications across projects

Page 78: Beyond the basics of SonarQube: improve your Java(Script) code even further

Duplications across projects

Page 79: Beyond the basics of SonarQube: improve your Java(Script) code even further

Technical debt pyramid

Page 80: Beyond the basics of SonarQube: improve your Java(Script) code even further

SCM Activity

Page 81: Beyond the basics of SonarQube: improve your Java(Script) code even further

Web Service API

Page 82: Beyond the basics of SonarQube: improve your Java(Script) code even further

Background Tasks

Page 83: Beyond the basics of SonarQube: improve your Java(Script) code even further

Update center

Page 84: Beyond the basics of SonarQube: improve your Java(Script) code even further

Using SonarQube on existing projects

Page 85: Beyond the basics of SonarQube: improve your Java(Script) code even further

Using SonarQube on existing projects

Page 86: Beyond the basics of SonarQube: improve your Java(Script) code even further

Using SonarQube on existing projects

Identity hotspots Use action plans Maybe use a less strict quality profile Add tasks/stories in the sprint to improve

quality Monitor quality of new code

Page 87: Beyond the basics of SonarQube: improve your Java(Script) code even further

Hotspots

Page 88: Beyond the basics of SonarQube: improve your Java(Script) code even further

Planning issues

Page 89: Beyond the basics of SonarQube: improve your Java(Script) code even further

Planning issues

Page 90: Beyond the basics of SonarQube: improve your Java(Script) code even further

Issues

Page 91: Beyond the basics of SonarQube: improve your Java(Script) code even further

Tips for using SonarQube in a project

Create stories/tasks to improve the quality Perform manual code reviews Agree on a standard for items SonarQube

cannot check Fix items or mark them as false positive Use separate logins Settings/reviews are project specific

Page 92: Beyond the basics of SonarQube: improve your Java(Script) code even further

Tips for using SonarQube in a project

Options to use SonarQubeo Central server (commit AND nightly)o IDE plugino Local in your development environment

Check code quality before ‘To verify’ stepo First merge your code so it is up to date

Verifier should also verify the quality

Page 93: Beyond the basics of SonarQube: improve your Java(Script) code even further
Page 94: Beyond the basics of SonarQube: improve your Java(Script) code even further

Accept failure, but improve continuously

“Once we accept our limits, we go beyond them.”

- Albert Einstein

Page 95: Beyond the basics of SonarQube: improve your Java(Script) code even further

Questions Ask me! Sonarqube.org Nemo example dashboard SonarQube books

[email protected]@johanjanssen42