Skip to content

Commit

Permalink
Merge branch 'users/egor-bryzgalov/MavenV3-node10' of https://github.…
Browse files Browse the repository at this point in the history
…com/microsoft/azure-pipelines-tasks into users/egor-bryzgalov/MavenV3-node10
  • Loading branch information
egor-bryzgalov committed Dec 15, 2020
2 parents 8b1816d + 3b860bc commit 34d4c5f
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 184 deletions.
38 changes: 19 additions & 19 deletions Tasks/MavenV3/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe("Maven L0 Suite", function () {
const testRunner = new MockTestRunner(testPath);

testRunner.run();

console.log(testRunner.stdout);
const mavenHome = "/anotherHome/";
const mavenBin = path.join(mavenHome, "bin", "mvn");
assert(testRunner.ran(`${mavenBin} -version`), "it should have run mvn -version");
Expand All @@ -69,7 +69,7 @@ describe("Maven L0 Suite", function () {
const testRunner = new MockTestRunner(testPath);

testRunner.run();

console.log(testRunner.stdout);
assert(testRunner.invokedToolCount == 0, "should not have run maven");
assert(testRunner.failed, "task should have failed");
assert(testRunner.createdErrorIssue("Unhandled: Input required: mavenVersionSelection"), "Did not create expected error issue, issues created: " + testRunner.errorIssues);
Expand All @@ -83,7 +83,7 @@ describe("Maven L0 Suite", function () {
const testRunner = new MockTestRunner(testPath);

testRunner.run();

console.log(testRunner.stdout);
assert(testRunner.invokedToolCount == 0, "should not have run maven");
assert(testRunner.failed, "task should have failed");
assert(testRunner.createdErrorIssue("Unhandled: Input required: mavenFeedAuthenticate"), "Did not create expected error issue, issues created: " + testRunner.errorIssues);
Expand All @@ -97,7 +97,7 @@ describe("Maven L0 Suite", function () {
const testRunner = new MockTestRunner(testPath);

testRunner.run();

console.log(testRunner.stdout);
assert(testRunner.ran("/home/bin/maven/bin/mvn -version"), "it should have run mvn -version");
assert(testRunner.ran("/home/bin/maven/bin/mvn -f pom.xml help:effective-pom"), "it should have generated effective pom");
assert(testRunner.ran("/home/bin/maven/bin/mvn -f pom.xml package"), "it should have run mvn -f pom.xml package");
Expand All @@ -114,7 +114,7 @@ describe("Maven L0 Suite", function () {
const testRunner = new MockTestRunner(testPath);

testRunner.run();

console.log(testRunner.stdout);
const mavenHome = "/home/bin/maven2/";
const mavenBin = path.join(mavenHome, "bin", "mvn");
assert(testRunner.ran(`${mavenBin} -version`), "it should have run mvn -version");
Expand All @@ -133,7 +133,7 @@ describe("Maven L0 Suite", function () {
const testRunner = new MockTestRunner(testPath);

testRunner.run();

console.log(testRunner.stdout);
assert(testRunner.invokedToolCount == 0, "should not have run maven");
assert(testRunner.failed, "task should have failed");
assert(testRunner.createdErrorIssue("Unhandled: Input required: mavenPath"), "Did not create expected error issue, issues created: " + testRunner.errorIssues);
Expand All @@ -147,7 +147,7 @@ describe("Maven L0 Suite", function () {
const testRunner = new MockTestRunner(testPath);

testRunner.run();

console.log(testRunner.stdout);
assert(testRunner.invokedToolCount == 0, "should not have run maven");
assert(testRunner.failed, "task should have failed");
assert(testRunner.createdErrorIssue("Unhandled: Not found /not/a/valid/maven/path/"), "Did not create expected error issue, issues created: " + testRunner.errorIssues);
Expand All @@ -161,7 +161,7 @@ describe("Maven L0 Suite", function () {
const testRunner = new MockTestRunner(testPath);

testRunner.run();

console.log(testRunner.stdout);
const mavenHome = "/home/bin/maven2/";
const mavenBin = path.join(mavenHome, "bin", "mvn");
assert(testRunner.ran(`${mavenBin} -version`), "it should have run mvn -version");
Expand All @@ -180,7 +180,7 @@ describe("Maven L0 Suite", function () {
const testRunner = new MockTestRunner(testPath);

testRunner.run();

console.log(testRunner.stdout);
const mavenHome = "/home/bin/maven2";
const mavenBin = path.join(mavenHome, "bin", "mvn");
assert(testRunner.ran(`${mavenBin} -version`), "it should have run mvn -version");
Expand All @@ -200,7 +200,7 @@ describe("Maven L0 Suite", function () {
const testRunner = new MockTestRunner(testPath);

testRunner.run();

console.log(testRunner.stdout);
const tempDirectory = getTempDir();
const settingsPath = path.join(tempDirectory, "settings.xml");
const mavenInfoPath = path.join(tempDirectory, ".mavenInfo", "MavenInfo-");
Expand All @@ -221,7 +221,7 @@ describe("Maven L0 Suite", function () {
const testRunner = new MockTestRunner(testPath);

testRunner.run();

console.log(testRunner.stdout);
assert(testRunner.ran("/home/bin/maven/bin/mvn -version"), "it should have run mvn -version");
assert(testRunner.ran(`/home/bin/maven/bin/mvn -f pom.xml package`), "it should have run mvn -f pom.xml package");
assert(testRunner.invokedToolCount == 2, "should have only run maven 2 times: " + testRunner.invokedToolCount);
Expand All @@ -238,7 +238,7 @@ describe("Maven L0 Suite", function () {
const testRunner = new MockTestRunner(testPath);

testRunner.run();

console.log(testRunner.stdout);
assert(testRunner.ran("/home/bin/maven/bin/mvn -version"), "it should have run mvn -version");
assert(testRunner.ran(`/home/bin/maven/bin/mvn -f pom.xml package`), "it should have run mvn -f pom.xml package");
assert(testRunner.invokedToolCount == 2, "should have only run maven 2 times: " + testRunner.invokedToolCount);
Expand All @@ -254,7 +254,7 @@ describe("Maven L0 Suite", function () {
const testRunner = new MockTestRunner(testPath);

testRunner.run();

console.log(testRunner.stdout);
const settingsPath = path.join(getTempDir(), "settings.xml");
const options = `-DoptWithEscaping={\"serverUri\": \"http://elasticsearch:9200\",\"username\": \"elastic\", \"password\": \"changeme\", \"connectionTimeout\": 30000}`;

Expand All @@ -275,11 +275,11 @@ describe("Maven L0 Suite", function () {
const testRunner = new MockTestRunner(testPath);

testRunner.run();

console.log(testRunner.stdout);
const settingsPath = path.join(getTempDir(), "settings.xml");
const options = "/o -s settings.xml /p /t";
const optionsWithoutSettings = "/o /p /t";

console.log(testRunner.stdout);
assert(testRunner.ran("/home/bin/maven/bin/mvn -version"), "it should have run mvn -version");
assert(testRunner.ran(`/home/bin/maven/bin/mvn -f pom.xml help:effective-pom ${options}`), "it should have generated effective pom");
assert(testRunner.ran(`/home/bin/maven/bin/mvn -f pom.xml -s ${settingsPath} ${optionsWithoutSettings} package`), `it should have run mvn -f pom.xml -s ${settingsPath} ${optionsWithoutSettings} package`);
Expand All @@ -296,7 +296,7 @@ describe("Maven L0 Suite", function () {
const testRunner = new MockTestRunner(testPath);

testRunner.run();

console.log(testRunner.stdout);
assert(testRunner.invokedToolCount == 0, "should not have run maven");
assert(testRunner.failed, "task should have failed");
assert(testRunner.createdErrorIssue("Unhandled: Input required: goals"), "Did not create expected error issue, issues created: " + testRunner.errorIssues);
Expand All @@ -310,7 +310,7 @@ describe("Maven L0 Suite", function () {
const testRunner = new MockTestRunner(testPath);

testRunner.run();

console.log(testRunner.stdout);
assert(testRunner.stdOutContained("##vso[results.publish type=JUnit;mergeResults=true;publishRunAttachments=true;resultFiles=/user/build/fun/test-123.xml;]"), "it should have published test results");
assert(testRunner.stderr.length == 0, "should not have written to stderr=" + testRunner.stderr);
assert(testRunner.succeeded, "task should have succeeded");
Expand All @@ -324,7 +324,7 @@ describe("Maven L0 Suite", function () {
const testRunner = new MockTestRunner(testPath);

testRunner.run();

console.log(testRunner.stdout);
assert(testRunner.invokedToolCount == 0, "should not have run maven");
assert(testRunner.failed, "task should have failed");
assert(testRunner.createdErrorIssue("Unhandled: Input required: testResultsFiles"), "Did not create expected error issue, issues created: " + testRunner.errorIssues);
Expand All @@ -338,7 +338,7 @@ describe("Maven L0 Suite", function () {
const testRunner = new MockTestRunner(testPath);

testRunner.run();

console.log(testRunner.stdout);
assert(testRunner.invokedToolCount == 0, "should not have run maven");
assert(testRunner.failed, "task should have failed");
assert(testRunner.createdErrorIssue("Unhandled: Input required: javaHomeSelection"), "Did not create expected error issue, issues created: " + testRunner.errorIssues);
Expand Down
10 changes: 8 additions & 2 deletions Tasks/MavenV3/Tests/L0DefaultsWithHomeSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const inputs: MavenTaskInputs = {
goals: "package",
javaHomeSelection: "JDKVersion",
jdkVersion: "default",
publishJUnitResults: true,
publishJUnitResults: false,
testResultsFiles: "**/TEST-*.xml",
mavenOpts: "-Xmx2048m",
checkstyleAnalysisEnabled: false,
Expand All @@ -34,12 +34,14 @@ setInputs(taskRunner, inputs);
// Env vars in the mock framework must replace '.' with '_'
const mavenHome = "/anotherHome/";
const mavenBin = path.join(mavenHome, "bin", "mvn");
const junitBin = path.join(mavenHome, "bin", "junit");
process.env["M2_HOME"] = mavenHome;

// Provide answers for task mock
const answers: TaskLibAnswers = {
which: {
mvn: mavenBin
mvn: mavenBin,
JUnit: junitBin
},
checkPath: {
[`${mavenBin}`]: true,
Expand All @@ -59,6 +61,10 @@ const answers: TaskLibAnswers = {
code: 0,
stdout: "Maven package done"
},
[`${junitBin} resultfiles=/user/build/fun/test-123.xml mergeResults=true publishrunAttachments=true testRunSystem=VSTS\\ -\\ maven`]: {
code: 0,
stdout: 'published'
}
},
findMatch: {
"**/TEST-*.xml": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/MavenV3/Tests/L0DefaultsWithNoHomeSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const inputs: MavenTaskInputs = {
goals: "package",
javaHomeSelection: "JDKVersion",
jdkVersion: "default",
publishJUnitResults: true,
publishJUnitResults: false,
testResultsFiles: "**/TEST-*.xml",
mavenOpts: "-Xmx2048m",
checkstyleAnalysisEnabled: false,
Expand Down
6 changes: 5 additions & 1 deletion Tasks/MavenV3/maventask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ if (specifiedJavaHome) {
tl.setVariable('JAVA_HOME', specifiedJavaHome);
}

function checkExistance(obj: any): Boolean {
return !!obj;
}

async function execBuild() {
// Maven task orchestration occurs as follows:
// 1. Check that Maven exists by executing it to retrieve its version.
Expand Down Expand Up @@ -249,7 +253,7 @@ async function execBuild() {
userRunFailed = true; // Record the error and continue
})
.then(function (code) {
if (code && code['code'] != 0) {
if (checkExistance(code) && code['code'] != 0) {
userRunFailed = true;
}
// 4. Attempt to collate and upload static code analysis build summaries and artifacts.
Expand Down
Loading

0 comments on commit 34d4c5f

Please sign in to comment.