/sonarqube-gradle-plugin

This Gradle plugin analyzes Intershop components with SonarQube™

Primary LanguageGroovy

Gradle SonarQube Plugin for Intershop Components

Summary

This plugin applies the code analysis with SonarQube to an Intershop multi project. An Intershop cartridge is from the SonarQube perspective a multi module project, because it contains java files, css files, javascript files and other code artifacts. Each kind of these artifacts can be analyzed by SonarQube. In the future Intershop wants deliver additional SonarQube plugins for special code artifacts. Currently SonarQube supports java, css and javascript.

Different from the standard Gradle SonarQube-Runner each Intershop component is analyzed in a separate project. The Intershop plugin uses the base configuration like the standard Gradle SonarQube-Runner (see sonarProperties).

Usage

Important
This plugin needs always a connection to the SonarQube-Server and is not working without this. It is possible to disable the code analysis for all projects with the setting of the project property skipSonar.

To apply the Intershop SonarQube plugin to your Intershop projects, add the following in your build script:

plugins {
   id 'com.intershop.gradle.sonarQube' version '2.0.0'
}

sonarqube {

    verbose = true

    sonarProperties {
        property 'sonar.host.url', 'http://sonarhost:9000'
        //optional
        //property 'sonar.login', ''
        //property 'sonar.password', ''
    }

}

Optionally, coverage data from integration tests can be uploaded with using the sonarPropery 'java.sonar.jacoco.itReportPath'.

The following snippet of a build.gradle shows the definition of a task for collecting related jacoco data files and an example for the configuration of the sonarqube task for related sub projects.

// required for the JacocoMerge Task
apply plugin: 'jacoco'

// JacocoMerge task for merging all related jacoco data files
Task collectIntegCoverageDataTask = tasks.create('collectIntegCoverageData', JacocoMerge, {
    destinationFile(new File(buildDir, 'jacoco/integTest.exec'))

    executionData rootProject.fileTree('.', {
        include '**/jacoco/ishUnitTest.exec'
    })
})

subprojects {

    // supposed, the name of your asemblies are stored within a collection
    if (!assemblies.contains(name)) {
        apply plugin: 'com.intershop.gradle.sonarQube'

        tasks.sonarqube.dependsOn collectIntegCoverageDataTask

        sonarqube {
            sonarProperties {
                property 'java.sonar.jacoco.itReportPath',
                new File(rootProject.buildDir, 'jacoco/integTest.exec').absolutePath
            }
        }
    }
}

Tasks

The Intershop SonarQube plugin adds the task sonarqube to all projects. The task will be only executed for sub projects.

Note
If the property branchVersion is not specified, the SonarQube property sonar.branch will be empty and the project version is used for sonar.version.

Project Extension 'sonarqube'

This plugin adds an extension sonarqube to the project.

Properties

Property Type Default value Description

modules

List

['java','js','css']

This is a list of possible configurations. Remove 'js' or' css, if only Java should to be analyzed.

runOnCI

boolean

false

If this value ist true, the result and sources are written to the SonarQube server, otherwise the analysis will run in a preview mode. So it should be true on the CI server.
This can be overwritten by the system or environment variable RUNONCI or project property runOnCI.

toolVersion

String

'2.5.1'

The version of the SonarQube Runner. (See http://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner)

skipProject

boolean

false

If this value is true, the project will be not analyzed.

verbose

boolean

false

The output of the SonarQube Runner will be extended, if this value is true.

Methods

|Method | Values | Description

sonarProperties

SonarProperties

Addtional Sonar configuration properties

forkOptions

JavaForkOptions

The SonarQube Runner is executed in a forkde process. This allows fine grained control over memory settings and system properties for the SonarQube Runner process.

Object 'sonarProperties' - Additional SonarQube analysis configuration

Method Parameter Description

property

String, Object

Adds an additional SonarQube configuration property. It is also possible to add an own module configuration.

Object 'forkOptions' - Controlling the SonarQube Runner process

For a complete reference about the available options, see JavaForkOptions.

Setting SonarQube Properties from the Command Line

SonarQube properties can also set from the command line. The properties must be configured as system properties named exactly like the SonarQube property. This can be usefull for dealing with sensitive information, like password and internal host names.

gradle sonarqube -Dsonar.host.url=http://sonarhost.mycompany.com -Dsonar.jdbc.password=myPassword

It also possible to specify this values in a special gradle.properties file

gradle.properties
systemProp.sonar.host.url = http://sonarhost:9000
#optional
#systemProp.sonar.login=<name>
#systemProp.sonar.password=<password>

Defaults for SonarQube properties

This is always for sub projects of a multi project build. Information about the multi-project will not be stored on the server sonarqube.

Property Default

sonar.projectKey

"${project.group}:${project.name}"

sonar.projectName

project.name

sonar.projectDescription

project.description

sonar.projectVersion

project.ext.branchVersion

sonar.projectBaseDir

project.projectDir

sonar.working.directory

<$project.buildDir/sonar>

sonar.dynamicAnalysis

<reuseReports>

Defaults when the java-base plugin is applied

Property Default

sonar.java.source

project.sourceCompatibility

sonar.java.target

project.targetCompatibility

java.sonar.projectName

Java

java.sonar.language

java

java.sonar.sources

sourceSets.main.allSource.srcDirs (filtered to only include existing directories)

java.sonar.tests

sourceSets.test.allSource.srcDirs (filtered to only include existing directories)

java.sonar.binaries

sourceSets.main.runtimeClasspath (filtered to only include directories)

sonar.libraries

sourceSets.main.runtimeClasspath (filtering to only include files; rt.jar added if necessary)

sonar.surefire.reportsPath

test.testResultsDir (if the directory exists)

sonar.junit.reportsPath

test.testResultsDir (if the directory exists)

Defaults when the jacoco plugin is applied

Property Default

sonar.java.coveragePlugin

jacoco

java.sonar.jacoco.reportPath

jacoco.destinationFile

Defaults for Intershop Artifacts

Table 1. Intershop Pipelet Artifacts
Property Default

pipelets.sonar.projectName

Pipelets

pipelets.sonar.sources

sourceSets.main.allSource.srcDirs (filtered to only include existing directories)

pipelets.sonar.binaries

sourceSets.main.runtimeClasspath (filtered to only include directories)

pipelets.sonar.projectBaseDir

project.projectDir

pipelets.sonar.language

pplet

Table 2. Intershop Pagelet Artifacts
Property Default

pagelets.sonar.projectName

Pagelets

pagelets.sonar.sources

'staticfiles/cartridge/pagelets'

pagelets.sonar.projectBaseDir

'staticfiles/cartridge/pagelets'

pagelets.sonar.language

pglet

Table 3. Intershop Template Artifacts
Property Default

templates.sonar.projectName

Templates

templates.sonar.sources

'staticfiles/cartridge/templates'

templates.sonar.projectBaseDir

'staticfiles/cartridge/templates'

templates.sonar.language

isml

Table 4. Intershop Pipeline Artifacts
Property Default

pipelines.sonar.projectName

Pipelines

pipelines.sonar.sources

'staticfiles/cartridge/pipelines'

pipelines.sonar.projectBaseDir

'staticfiles/cartridge/pipelines'

pipelines.sonar.language

pline

Table 5. Intershop Javascript Artifacts
Property Default

js.sonar.projectName

Javascript

js.sonar.sources

'staticfiles/cartridge/static'

js.sonar.projectBaseDir

'staticfiles/cartridge/static'

js.sonar.language

js

Table 6. Intershop CSS Artifacts
Property Default

css.sonar.projectName

CSS

css.sonar.sources

'staticfiles/cartridge/static'

css.sonar.projectBaseDir

'staticfiles/cartridge/static'

css.sonar.language

css

Table 7. Intershop Query Artifacts
Property Default

queries.sonar.projectName

Query

queries.sonar.sources

'staticfiles/cartridge/queries'

queries.sonar.projectBaseDir

'staticfiles/cartridge/queries'

queries.sonar.language

query

Table 8. Intershop WebForm Artifacts
Property Default

webforms.sonar.projectName

Webform

webforms.sonar.sources

'staticfiles/cartridge/webforms'

webforms.sonar.projectBaseDir

'staticfiles/cartridge/webforms'

webforms.sonar.language

webfm

License

Copyright 2014-2016 Intershop Communications.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.