Skip to content

Commit af6ad25

Browse files
author
Anatoly Bolshakov
authored
[Maven] Fixed Jacoco code coverage - SonarQube (binary reports showing 0%) (#13592)
* Fixed maven task - sonar qube for jacoco * Fixed resources
1 parent 99cb7de commit af6ad25

File tree

8 files changed

+54
-6
lines changed

8 files changed

+54
-6
lines changed

Tasks/MavenV2/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
"loc.input.help.mavenFeedAuthenticate": "Automatically authenticate Maven feeds from Azure Artifacts. If built-in Maven feeds are not in use, deselect this option for faster builds.",
4949
"loc.input.label.sqAnalysisEnabled": "Run SonarQube or SonarCloud analysis",
5050
"loc.input.help.sqAnalysisEnabled": "This option has changed from version 1 of the **Maven** task to use the [SonarQube](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarqube) and [SonarCloud](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud) marketplace extensions. Enable this option to run [SonarQube or SonarCloud analysis](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html) after executing goals in the **Goals** field. The **install** or **package** goal should run first. You must also add a **Prepare Analysis Configuration** task from one of the extensions to the build pipeline before this Maven task.",
51+
"loc.input.label.isJacocoCoverageReportXML": "Use XML Jacoco reports for SonarQube analysis",
52+
"loc.input.help.isJacocoCoverageReportXML": "Use XML Jacoco reports for SonarQube analysis. [More info](https://docs.sonarqube.org/latest/analysis/coverage/)",
5153
"loc.input.label.sqMavenPluginVersionChoice": "SonarQube scanner for Maven version",
5254
"loc.input.help.sqMavenPluginVersionChoice": "The SonarQube Maven plugin version to use. You can use latest version, or rely on the version in your pom.xml.",
5355
"loc.input.label.checkstyleAnalysisEnabled": "Run Checkstyle",

Tasks/MavenV2/maventask.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ async function execBuild() {
283283
}
284284

285285
function applySonarQubeArgs(mvnsq: ToolRunner | any, execFileJacoco?: string): ToolRunner | any {
286+
const isJacocoCoverageReportXML: boolean = tl.getBoolInput('isJacocoCoverageReportXML', false);
287+
286288
if (!tl.getBoolInput('sqAnalysisEnabled', false)) {
287289
return mvnsq;
288290
}
@@ -292,7 +294,7 @@ function applySonarQubeArgs(mvnsq: ToolRunner | any, execFileJacoco?: string): T
292294
mvnsq.arg('-Dsonar.jacoco.reportPaths=' + execFileJacoco);
293295
}
294296

295-
if (summaryFile) {
297+
if (isJacocoCoverageReportXML && summaryFile) {
296298
mvnsq.arg(`-Dsonar.coverage.jacoco.xmlReportPaths=${summaryFile}`);
297299
}
298300

Tasks/MavenV2/task.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"version": {
1919
"Major": 2,
2020
"Minor": 176,
21-
"Patch": 0
21+
"Patch": 1
2222
},
2323
"releaseNotes": "Configuration of the SonarQube analysis was moved to the [SonarQube](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarqube) or [SonarCloud](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud) extensions, in task `Prepare Analysis Configuration`",
2424
"demands": [
@@ -314,6 +314,16 @@
314314
"groupName": "CodeAnalysis",
315315
"helpMarkDown": "This option has changed from version 1 of the **Maven** task to use the [SonarQube](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarqube) and [SonarCloud](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud) marketplace extensions. Enable this option to run [SonarQube or SonarCloud analysis](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html) after executing goals in the **Goals** field. The **install** or **package** goal should run first. You must also add a **Prepare Analysis Configuration** task from one of the extensions to the build pipeline before this Maven task."
316316
},
317+
{
318+
"name": "isJacocoCoverageReportXML",
319+
"type": "boolean",
320+
"label": "Use XML Jacoco reports for SonarQube analysis",
321+
"defaultValue": "false",
322+
"required": false,
323+
"groupName": "CodeAnalysis",
324+
"helpMarkDown": "Use XML Jacoco reports for SonarQube analysis. [More info](https://docs.sonarqube.org/latest/analysis/coverage/)",
325+
"visibleRule": "and(sqAnalysisEnabled = true, codeCoverageTool = JaCoCo) "
326+
},
317327
{
318328
"name": "sqMavenPluginVersionChoice",
319329
"type": "radio",

Tasks/MavenV2/task.loc.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"version": {
1919
"Major": 2,
2020
"Minor": 176,
21-
"Patch": 0
21+
"Patch": 1
2222
},
2323
"releaseNotes": "ms-resource:loc.releaseNotes",
2424
"demands": [
@@ -314,6 +314,16 @@
314314
"groupName": "CodeAnalysis",
315315
"helpMarkDown": "ms-resource:loc.input.help.sqAnalysisEnabled"
316316
},
317+
{
318+
"name": "isJacocoCoverageReportXML",
319+
"type": "boolean",
320+
"label": "ms-resource:loc.input.label.isJacocoCoverageReportXML",
321+
"defaultValue": "false",
322+
"required": false,
323+
"groupName": "CodeAnalysis",
324+
"helpMarkDown": "ms-resource:loc.input.help.isJacocoCoverageReportXML",
325+
"visibleRule": "and(sqAnalysisEnabled = true, codeCoverageTool = JaCoCo) "
326+
},
317327
{
318328
"name": "sqMavenPluginVersionChoice",
319329
"type": "radio",

Tasks/MavenV3/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
"loc.input.help.skipEffectivePom": "Authenticate built-in Maven feeds using the POM only, allowing parent POMs in Azure Artifacts/Azure DevOps Server [Package Management] feeds.",
5151
"loc.input.label.sqAnalysisEnabled": "Run SonarQube or SonarCloud analysis",
5252
"loc.input.help.sqAnalysisEnabled": "This option has changed from version 1 of the **Maven** task to use the [SonarQube](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarqube) and [SonarCloud](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud) marketplace extensions. Enable this option to run [SonarQube or SonarCloud analysis](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html) after executing goals in the **Goals** field. The **install** or **package** goal should run first. You must also add a **Prepare Analysis Configuration** task from one of the extensions to the build pipeline before this Maven task.",
53+
"loc.input.label.isJacocoCoverageReportXML": "Use XML Jacoco reports for SonarQube analysis",
54+
"loc.input.help.isJacocoCoverageReportXML": "Use XML Jacoco reports for SonarQube analysis. [More info](https://docs.sonarqube.org/latest/analysis/coverage/)",
5355
"loc.input.label.sqMavenPluginVersionChoice": "SonarQube scanner for Maven version",
5456
"loc.input.help.sqMavenPluginVersionChoice": "The SonarQube Maven plugin version to use. You can use latest version, or rely on the version in your pom.xml.",
5557
"loc.input.label.checkstyleAnalysisEnabled": "Run Checkstyle",

Tasks/MavenV3/maventask.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ async function execBuild() {
295295
}
296296

297297
function applySonarQubeArgs(mvnsq: ToolRunner | any, execFileJacoco?: string): ToolRunner | any {
298+
const isJacocoCoverageReportXML: boolean = tl.getBoolInput('isJacocoCoverageReportXML', false);
299+
298300
if (!tl.getBoolInput('sqAnalysisEnabled', false)) {
299301
return mvnsq;
300302
}
@@ -304,7 +306,7 @@ function applySonarQubeArgs(mvnsq: ToolRunner | any, execFileJacoco?: string): T
304306
mvnsq.arg('-Dsonar.jacoco.reportPaths=' + execFileJacoco);
305307
}
306308

307-
if (summaryFile) {
309+
if (isJacocoCoverageReportXML && summaryFile) {
308310
mvnsq.arg(`-Dsonar.coverage.jacoco.xmlReportPaths=${summaryFile}`);
309311
}
310312

Tasks/MavenV3/task.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"version": {
1919
"Major": 3,
2020
"Minor": 176,
21-
"Patch": 0
21+
"Patch": 1
2222
},
2323
"releaseNotes": "Configuration of the SonarQube analysis was moved to the [SonarQube](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarqube) or [SonarCloud](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud) extensions, in task `Prepare Analysis Configuration`",
2424
"demands": [
@@ -326,6 +326,16 @@
326326
"groupName": "CodeAnalysis",
327327
"helpMarkDown": "This option has changed from version 1 of the **Maven** task to use the [SonarQube](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarqube) and [SonarCloud](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud) marketplace extensions. Enable this option to run [SonarQube or SonarCloud analysis](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html) after executing goals in the **Goals** field. The **install** or **package** goal should run first. You must also add a **Prepare Analysis Configuration** task from one of the extensions to the build pipeline before this Maven task."
328328
},
329+
{
330+
"name": "isJacocoCoverageReportXML",
331+
"type": "boolean",
332+
"label": "Use XML Jacoco reports for SonarQube analysis",
333+
"defaultValue": "false",
334+
"required": false,
335+
"groupName": "CodeAnalysis",
336+
"helpMarkDown": "Use XML Jacoco reports for SonarQube analysis. [More info](https://docs.sonarqube.org/latest/analysis/coverage/)",
337+
"visibleRule": "and(sqAnalysisEnabled = true, codeCoverageTool = JaCoCo) "
338+
},
329339
{
330340
"name": "sqMavenPluginVersionChoice",
331341
"type": "radio",

Tasks/MavenV3/task.loc.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"version": {
1919
"Major": 3,
2020
"Minor": 176,
21-
"Patch": 0
21+
"Patch": 1
2222
},
2323
"releaseNotes": "ms-resource:loc.releaseNotes",
2424
"demands": [
@@ -326,6 +326,16 @@
326326
"groupName": "CodeAnalysis",
327327
"helpMarkDown": "ms-resource:loc.input.help.sqAnalysisEnabled"
328328
},
329+
{
330+
"name": "isJacocoCoverageReportXML",
331+
"type": "boolean",
332+
"label": "ms-resource:loc.input.label.isJacocoCoverageReportXML",
333+
"defaultValue": "false",
334+
"required": false,
335+
"groupName": "CodeAnalysis",
336+
"helpMarkDown": "ms-resource:loc.input.help.isJacocoCoverageReportXML",
337+
"visibleRule": "and(sqAnalysisEnabled = true, codeCoverageTool = JaCoCo) "
338+
},
329339
{
330340
"name": "sqMavenPluginVersionChoice",
331341
"type": "radio",

0 commit comments

Comments
 (0)