Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Users/lukillgo/antcc #4061

Merged
merged 3 commits into from
Apr 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Tasks/ANT/Strings/resources.resjson/en-US/resources.resjson
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"loc.input.help.classFilter": "Comma-separated list of filters to include or exclude classes from collecting code coverage. For example: +:com.*,+:org.*,-:my.app*.*.",
"loc.input.label.srcDirectories": "Source Files Directories",
"loc.input.help.srcDirectories": "Comma-separated list of relative paths from the Ant build file to source code directories. Code coverage reports will use these to highlight source code. For example: src/java,src/Test.",
"loc.input.label.failIfCoverageEmpty": "Fail When Code Coverage Results Are Missing",
"loc.input.help.failIfCoverageEmpty": "Fail the build if code coverage did not produce any results to publish.",
"loc.input.label.antHomeUserInputPath": "Set ANT_HOME Path",
"loc.input.help.antHomeUserInputPath": "If set, overrides any existing ANT_HOME environment variable with the given path.",
"loc.input.label.javaHomeSelection": "Set JAVA_HOME by",
Expand All @@ -38,5 +40,6 @@
"loc.input.help.jdkArchitecture": "Optionally supply the architecture (x86, x64) of the JDK.",
"loc.messages.LocateJVMBasedOnVersionAndArch": "Locate JAVA_HOME for Java %s %s",
"loc.messages.FailedToLocateSpecifiedJVM": "Failed to find specified JDK version. Please make sure environment variable '%s' exists and is set to the location of a corresponding JDK.",
"loc.messages.DiscontinueAntCodeCoverage": "We are discontinuing the support of automated Code Coverage report generation for Ant projects. Please refer https://github.com/Microsoft/vsts-tasks/blob/master/Tasks/ANT/README.md for more details."
"loc.messages.DiscontinueAntCodeCoverage": "We are discontinuing the support of automated Code Coverage report generation for Ant projects. Please refer https://github.com/Microsoft/vsts-tasks/blob/master/Tasks/ANT/README.md for more details.",
"loc.messages.NoCodeCoverage": "No code coverage results were found to publish."
}
21 changes: 15 additions & 6 deletions Tasks/ANT/anttask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fs = require('fs');
import os = require('os');
import * as Q from "q";
import javacommons = require('java-common/java-common');
import ccUtils = require('codecoverage-tools/codecoverageutilities');
import {CodeCoverageEnablerFactory} from 'codecoverage-tools/codecoveragefactory';

tl.setResourcePath(path.join(__dirname, 'task.json'));
Expand Down Expand Up @@ -140,8 +141,12 @@ async function doWork() {
return ccEnabler.enableCodeCoverage(buildProps);
}

function publishCodeCoverage(codeCoverageOpted: boolean, ccReportTask: string) {
if (codeCoverageOpted && ccReportTask) {
async function publishCodeCoverage(codeCoverageOpted: boolean, ccReportTask: string) {
tl.debug("publishCodeCoverage f=" + failIfCodeCoverageEmpty + " opt=" + codeCoverageOpted + " task=" + ccReportTask);
if (failIfCodeCoverageEmpty && codeCoverageOpted && !ccReportTask) {
throw tl.loc('NoCodeCoverage');
}
else if (codeCoverageOpted && ccReportTask) {
tl.debug("Collecting code coverage reports");
var antRunner = tl.tool(anttool);
antRunner.arg('-buildfile');
Expand All @@ -153,7 +158,10 @@ async function doWork() {
antRunner.arg(antBuildFile);
antRunner.arg(ccReportTask);
}
antRunner.exec().then(function (code) {
antRunner.exec().then(async function (code) {
if (failIfCodeCoverageEmpty && await ccUtils.isCodeCoverageFileEmpty(summaryFile, ccTool)) {
throw tl.loc('NoCodeCoverage');
}
if (pathExistsAsFile(summaryFile)) {
tl.debug("Summary file = " + summaryFile);
tl.debug("Report directory = " + reportDirectory);
Expand Down Expand Up @@ -224,6 +232,7 @@ async function doWork() {

var ccTool = tl.getInput('codeCoverageTool');
var isCodeCoverageOpted = (typeof ccTool != "undefined" && ccTool && ccTool.toLowerCase() != 'none');
var failIfCodeCoverageEmpty: boolean = tl.getBoolInput('failIfCoverageEmpty');
var buildRootPath = path.dirname(antBuildFile);

var summaryFile: string = null;
Expand Down Expand Up @@ -252,10 +261,10 @@ async function doWork() {
}
});

antb.exec()
.then(function (code) {
await antb.exec()
.then(async function (code) {
publishTestResults(publishJUnitResults, testResultsFiles);
publishCodeCoverage(isCodeCoverageOpted, ccReportTask);
await publishCodeCoverage(isCodeCoverageOpted, ccReportTask);
tl.setResult(tl.TaskResult.Succeeded, "Task succeeded");
})
.fail(function (err) {
Expand Down
19 changes: 15 additions & 4 deletions Tasks/ANT/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 112,
"Patch": 2
"Minor": 117,
"Patch": 0
},
"demands": [
"ant"
Expand Down Expand Up @@ -139,6 +139,16 @@
"helpMarkDown": "Comma-separated list of relative paths from the Ant build file to source code directories. Code coverage reports will use these to highlight source code. For example: src/java,src/Test.",
"visibleRule": "codeCoverageTool != None"
},
{
"name": "failIfCoverageEmpty",
"type": "boolean",
"label": "Fail When Code Coverage Results Are Missing",
"defaultValue": "false",
"required": false,
"groupName": "codeCoverage",
"helpMarkDown": "Fail the build if code coverage did not produce any results to publish.",
"visibleRule": "codeCoverageTool != None"
},
{
"name": "antHomeUserInputPath",
"type": "string",
Expand Down Expand Up @@ -210,6 +220,7 @@
"messages": {
"LocateJVMBasedOnVersionAndArch": "Locate JAVA_HOME for Java %s %s",
"FailedToLocateSpecifiedJVM": "Failed to find specified JDK version. Please make sure environment variable '%s' exists and is set to the location of a corresponding JDK.",
"DiscontinueAntCodeCoverage": "We are discontinuing the support of automated Code Coverage report generation for Ant projects. Please refer https://github.com/Microsoft/vsts-tasks/blob/master/Tasks/ANT/README.md for more details."
}
"DiscontinueAntCodeCoverage": "We are discontinuing the support of automated Code Coverage report generation for Ant projects. Please refer https://github.com/Microsoft/vsts-tasks/blob/master/Tasks/ANT/README.md for more details.",
"NoCodeCoverage": "No code coverage results were found to publish."
}
}
17 changes: 14 additions & 3 deletions Tasks/ANT/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 112,
"Patch": 2
"Minor": 117,
"Patch": 0
},
"demands": [
"ant"
Expand Down Expand Up @@ -139,6 +139,16 @@
"helpMarkDown": "ms-resource:loc.input.help.srcDirectories",
"visibleRule": "codeCoverageTool != None"
},
{
"name": "failIfCoverageEmpty",
"type": "boolean",
"label": "ms-resource:loc.input.label.failIfCoverageEmpty",
"defaultValue": "false",
"required": false,
"groupName": "codeCoverage",
"helpMarkDown": "ms-resource:loc.input.help.failIfCoverageEmpty",
"visibleRule": "codeCoverageTool != None"
},
{
"name": "antHomeUserInputPath",
"type": "string",
Expand Down Expand Up @@ -210,6 +220,7 @@
"messages": {
"LocateJVMBasedOnVersionAndArch": "ms-resource:loc.messages.LocateJVMBasedOnVersionAndArch",
"FailedToLocateSpecifiedJVM": "ms-resource:loc.messages.FailedToLocateSpecifiedJVM",
"DiscontinueAntCodeCoverage": "ms-resource:loc.messages.DiscontinueAntCodeCoverage"
"DiscontinueAntCodeCoverage": "ms-resource:loc.messages.DiscontinueAntCodeCoverage",
"NoCodeCoverage": "ms-resource:loc.messages.NoCodeCoverage"
}
}
2 changes: 1 addition & 1 deletion Tasks/Gradle/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 116,
"Minor": 117,
"Patch": 0
},
"demands": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/Gradle/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 116,
"Minor": 117,
"Patch": 0
},
"demands": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/Maven/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
"version": {
"Major": 1,
"Minor": 116,
"Minor": 117,
"Patch": 0
},
"minimumAgentVersion": "1.89.0",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/Maven/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
"version": {
"Major": 1,
"Minor": 116,
"Minor": 117,
"Patch": 0
},
"minimumAgentVersion": "1.89.0",
Expand Down