johan janssen (info support) @johanjanssen42 · 2019-09-11 · options to use sonarqube o central...

95
Johan Janssen (Info Support) @johanjanssen42

Upload: others

Post on 14-Aug-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment

Johan Janssen (Info Support) @johanjanssen42

Page 2: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment

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: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 4: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 5: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 6: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment

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: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment

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: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 9: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment

I’m told to use it.

We need to achieve certain results (SIG…)

I want to improve my coding standards

Page 10: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment

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: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment

2013:

5 releases of SonarQube platform

130 releases of ecosystem products

75,000 downloads of SonarQube

13,000+ messages on mailing lists

Page 12: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 13: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 14: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 15: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 16: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 17: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 18: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 19: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 20: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 21: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 22: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 23: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 24: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 25: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment

Profile

Rules

Projects

Page 26: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 27: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 28: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment

Projects

Quality Gates

Page 29: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 30: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 31: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 32: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 33: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 34: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 35: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 36: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 37: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 38: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 39: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 40: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 41: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment

“We all need people who will give us feedback.

That's how we improve.”

- Bill Gates

Page 42: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 43: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 44: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 45: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 46: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 47: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment

mvn clean install mvn sonar:sonar

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

-Dmaven.test.failure.ignore=true mvn sonar:sonar

Page 48: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment

Configure the POM (see next slide)

Activate profile to get coverage per test

information

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

install -Pcoverage-per-test

Analyze the project

mvn sonar:sonar

Page 49: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 50: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 51: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 52: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment

! Unit testing

Page 53: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 54: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 55: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 56: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment

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: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment

Start Tomcat

Execute tests (manual, integration,

performance…)

Stop Tomcat and execute SonarQube analysis

mvn clean install sonar:sonar

-Dsonar.dynamicAnalysis=reuseReports

-Dsonar.jacoco.itReportPath=

$resultpath$\jacoco.exec

Page 58: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 59: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 60: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 61: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 62: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment

Enable ‘Survived mutant’ rule in SonarQube

Quality Profile

Configure Pitest for instance with Maven (see

next slides)

Page 63: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment

Execute tests and send results to SonarQube

mvn org.pitest:pitest- maven:mutationCoverage

mvn sonar:sonar

-Dsonar.pitest.mode=reuseReport

Page 64: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment

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>

Page 65: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 66: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 67: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 68: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 69: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 70: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 71: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 72: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 73: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment

mvn sonar:sonar -Dsonar.branch=4.4

Page 74: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment

Ignore files

Ignore issues

Ignore duplications

Ignore code coverage

Example:

mvn sonar:sonar -Dsonar.exclusions=

src/main/webapp/lib/*.js

Page 75: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 76: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 77: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 78: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 79: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 80: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 81: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 82: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 83: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 84: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 85: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 86: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment

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: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 88: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 89: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 90: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 91: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment

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: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment

Options to use SonarQube

o Central server (commit AND nightly)

o IDE plugin

o Local in your development environment

Check code quality before ‘To verify’ step

o First merge your code so it is up to date

Verifier should also verify the quality

Page 93: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment
Page 94: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment

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

- Albert Einstein

Page 95: Johan Janssen (Info Support) @johanjanssen42 · 2019-09-11 · Options to use SonarQube o Central server (commit AND nightly) o IDE plugin o Local in your development environment

Ask me!

Sonarqube.org

Nemo example dashboard

SonarQube books

[email protected]

@johanjanssen42