Skip to content

Commit

Permalink
Allow passing in sonarqube plugin version in gradle task (#4233)
Browse files Browse the repository at this point in the history
  • Loading branch information
madhurig authored May 5, 2017
1 parent cd65489 commit 6650b4c
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 3 deletions.
13 changes: 13 additions & 0 deletions Tasks/Gradle/CodeAnalysis/SonarQube/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ export function isSonarQubeAnalysisEnabled(): boolean {
return tl.getBoolInput('sqAnalysisEnabled', false);
}

/**
* Returns the SonarQube Gradle plugin version.
* @returns {string}
*/
export function getSonarQubeGradlePluginVersion(): string {
let pluginVersion = '2.0.1';
let userSpecifiedVersion = tl.getInput('sqGradlePluginVersion');
if (userSpecifiedVersion) {
pluginVersion = userSpecifiedVersion.trim();
}
return pluginVersion;
}

/**
* Apply all parameters necessary for SonarQube operation to the given ToolRunner.
* @param toolRunner Master ToolRunner object that will be executed on the command line.
Expand Down
6 changes: 6 additions & 0 deletions Tasks/Gradle/CodeAnalysis/gradlesonar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// <reference path="../../../definitions/vsts-task-lib.d.ts" />
import Q = require('q');
import path = require('path');
import fs = require('fs');

import tl = require('vsts-task-lib/task');
import trm = require('vsts-task-lib/toolrunner');
Expand All @@ -17,7 +18,12 @@ export function applyEnabledSonarQubeArguments(gradleRun: trm.ToolRunner): trm.T

// #1: Inject custom script to the Gradle build, triggering a SonarQube run
// Add a custom initialisation script to the Gradle run that will apply the SonarQube plugin and task
// Set the SonarQube Gralde plugin version in the script
let initScriptPath: string = path.join(__dirname, 'sonar.gradle');
let pluginVersion: string = sqCommon.getSonarQubeGradlePluginVersion();
let scriptContents: string= fs.readFileSync(initScriptPath, 'utf8');
scriptContents = scriptContents.replace('SONARQUBE_GRADLE_PLUGIN_VERSION', pluginVersion);
tl.writeFile(initScriptPath, scriptContents);

// Specify that the build should run the init script
gradleRun.arg(['sonarqube']);
Expand Down
2 changes: 1 addition & 1 deletion Tasks/Gradle/CodeAnalysis/sonar.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ allprojects {
}
}
dependencies {
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.0.1"
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:SONARQUBE_GRADLE_PLUGIN_VERSION"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
"loc.input.help.sqProjectKey": "The SonarQube project unique key, i.e. sonar.projectKey.",
"loc.input.label.sqProjectVersion": "SonarQube Project Version",
"loc.input.help.sqProjectVersion": "The SonarQube project version, i.e. sonar.projectVersion.",
"loc.input.label.sqGradlePluginVersion": "SonarQube Gradle Plugin Version",
"loc.input.help.sqGradlePluginVersion": "The SonarQube Gradle plugin version to use. Refer to https://plugins.gradle.org/plugin/org.sonarqube for all available versions.",
"loc.input.label.sqDbDetailsRequired": "The SonarQube server version is lower than 5.2",
"loc.input.help.sqDbDetailsRequired": "If using a SonarQube server 5.1 or lower, you must specify the database connection details.",
"loc.input.label.sqDbUrl": "Db Connection String",
Expand Down
12 changes: 11 additions & 1 deletion Tasks/Gradle/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"version": {
"Major": 1,
"Minor": 117,
"Patch": 0
"Patch": 1
},
"demands": [
"java"
Expand Down Expand Up @@ -255,6 +255,16 @@
"groupName": "CodeAnalysis",
"visibleRule": "sqAnalysisEnabled = true"
},
{
"name": "sqGradlePluginVersion",
"type": "string",
"label": "SonarQube Gradle Plugin Version",
"required": true,
"defaultValue": "2.0.1",
"helpMarkDown": "The SonarQube Gradle plugin version to use. Refer to https://plugins.gradle.org/plugin/org.sonarqube for all available versions.",
"groupName": "CodeAnalysis",
"visibleRule": "sqAnalysisEnabled = true"
},
{
"name": "sqDbDetailsRequired",
"type": "boolean",
Expand Down
12 changes: 11 additions & 1 deletion Tasks/Gradle/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"version": {
"Major": 1,
"Minor": 117,
"Patch": 0
"Patch": 1
},
"demands": [
"java"
Expand Down Expand Up @@ -255,6 +255,16 @@
"groupName": "CodeAnalysis",
"visibleRule": "sqAnalysisEnabled = true"
},
{
"name": "sqGradlePluginVersion",
"type": "string",
"label": "ms-resource:loc.input.label.sqGradlePluginVersion",
"required": true,
"defaultValue": "2.0.1",
"helpMarkDown": "ms-resource:loc.input.help.sqGradlePluginVersion",
"groupName": "CodeAnalysis",
"visibleRule": "sqAnalysisEnabled = true"
},
{
"name": "sqDbDetailsRequired",
"type": "boolean",
Expand Down

0 comments on commit 6650b4c

Please sign in to comment.