From 3ed79680306ba03a63ebff6a3f0201c304c2345e Mon Sep 17 00:00:00 2001 From: Jason Prickett Date: Fri, 16 Jun 2017 14:40:39 -0400 Subject: [PATCH] Changing the Maven task to work for SonarQube even in PR builds Fixing issue #3976 Internal Bug #976726 --- .../SonarQube/vsts-server-utils.ts | 8 +++ Tests-Legacy/L0/Maven/_suite.ts | 58 +------------------ 2 files changed, 10 insertions(+), 56 deletions(-) diff --git a/Tasks/Maven/CodeAnalysis/SonarQube/vsts-server-utils.ts b/Tasks/Maven/CodeAnalysis/SonarQube/vsts-server-utils.ts index 777765db0ec1..ea82f03a4989 100644 --- a/Tasks/Maven/CodeAnalysis/SonarQube/vsts-server-utils.ts +++ b/Tasks/Maven/CodeAnalysis/SonarQube/vsts-server-utils.ts @@ -26,6 +26,13 @@ export class VstsServerUtils { * @returns {boolean} True if the build is a PR build, false otherwise. */ public static isPrBuild(): boolean { + //////////////////////////////////////////////////////////////////////////////////////////////////////////// + // Changing the behavior of the SonarCube integration if this is a PR build causes at least one known bug + // Because of this bug and other concerns we are disabling that behavior here by returning false + //////////////////////////////////////////////////////////////////////////////////////////////////////////// + return false; + + /* TODO remove this commented code and remove all references to this method let sourceBranch: string = tl.getVariable('build.sourceBranch'); let sccProvider: string = tl.getVariable('build.repository.provider'); @@ -36,6 +43,7 @@ export class VstsServerUtils { sccProvider.toLowerCase() === "tfsgit" && !VstsServerUtils.isNullOrEmpty(sourceBranch) && sourceBranch.toLowerCase().startsWith("refs/pull/"); + */ } /** diff --git a/Tests-Legacy/L0/Maven/_suite.ts b/Tests-Legacy/L0/Maven/_suite.ts index 91c00c1caa2b..7f5a47adc10b 100644 --- a/Tests-Legacy/L0/Maven/_suite.ts +++ b/Tests-Legacy/L0/Maven/_suite.ts @@ -1083,60 +1083,6 @@ describe('Maven Suite', function () { }); }); - it('Maven with SonarQube - Does not fail if report-task.txt is missing during a PR build', function (done) { - // Arrange - createTempDirsForSonarQubeTests(); - var testSrcDir: string = __dirname; - var testStgDir: string = path.join(__dirname, '_temp'); - createTempDir(); - var codeAnalysisStgDir: string = path.join(testStgDir, '.codeAnalysis'); // overall directory for all tools - - mockHelper.setResponseAndBuildVars( - path.join(__dirname, 'response.json'), - path.join(__dirname, 'new_response.json'), - [["build.sourceBranch", "refs/pull/6/master"], ["build.repository.provider", "TFSGit"], - ['build.sourcesDirectory', testSrcDir], ['build.artifactStagingDirectory', testStgDir]]); - var responseJsonFilePath: string = path.join(__dirname, 'new_response.json'); - var responseJsonContent = JSON.parse(fs.readFileSync(responseJsonFilePath, 'utf-8')); - - // Add fields corresponding to responses for mock filesystem operations for the following paths - // Staging directories - responseJsonContent = mockHelper.setupMockResponsesForPaths(responseJsonContent, listFolderContents(testStgDir)); - // Test data files - responseJsonContent = mockHelper.setupMockResponsesForPaths(responseJsonContent, listFolderContents(testSrcDir)); - - // Write and set the newly-changed response file - var newResponseFilePath: string = path.join(__dirname, this.test.title + '_response.json'); - fs.writeFileSync(newResponseFilePath, JSON.stringify(responseJsonContent)); - setResponseFile(path.basename(newResponseFilePath)); - - var tr: trm.TaskRunner = setupDefaultMavenTaskRunner(); - tr.setInput('sqAnalysisEnabled', 'true'); - tr.setInput('sqConnectedServiceName', 'ID1'); - - tr.run() - .then(() => { - assert(tr.ran('/home/bin/maven/bin/mvn -version'), 'it should have run mvn -version'); - assert(tr.ran( - '/home/bin/maven/bin/mvn -f pom.xml package -Dsonar.host.url=http://sonarqubeserver:9000 -Dsonar.login=uname -Dsonar.password=pword -Dsonar.analysis.mode=issues -Dsonar.report.export.path=sonar-report.json sonar:sonar' - ), 'it should have run SQ analysis'); - assert(tr.invokedToolCount == 2, 'should have only run maven 2 times'); - assert(tr.resultWasSet, 'task should have set a result'); - assert(tr.stderr.length < 1, 'should not have written to stderr'); - assert(tr.succeeded, 'task should have succeeded'); - - assert(tr.stdout.indexOf('task.addattachment type=Distributedtask.Core.Summary;name=SonarQube Analysis Report') < 1, - 'should not have uploaded a SonarQube Analysis Report build summary'); - done(); - }) - .fail((err) => { - console.log(tr.stdout); - console.log(tr.stderr); - console.log(err); - done(err); - }); - }); - it('Maven build with publish test results', (done) => { setResponseFile('response.json'); var tr = new trm.TaskRunner('Maven', true); @@ -1770,7 +1716,7 @@ describe('Maven Suite', function () { .fail((reason) => done("an error occured: " + reason)); }); - it('during PR builds SonarQube analysis runs in issues mode', function (done) { + it('during PR builds SonarQube analysis runs normally', function (done) { // Arrange createTempDirsForSonarQubeTests(); var testSrcDir: string = path.join(__dirname, 'data', 'taskreport-valid'); @@ -1803,7 +1749,7 @@ describe('Maven Suite', function () { tr.run() .then(() => { assert(tr.ran('/home/bin/maven/bin/mvn -version'), 'it should have run mvn -version'); - assert(tr.ran('/home/bin/maven/bin/mvn -f pom.xml package -Dsonar.host.url=http://sonarqubeserver:9000 -Dsonar.login=uname -Dsonar.password=pword -Dsonar.analysis.mode=issues -Dsonar.report.export.path=sonar-report.json sonar:sonar'), 'it should have run SQ analysis in issues mode'); + assert(tr.ran('/home/bin/maven/bin/mvn -f pom.xml package -Dsonar.host.url=http://sonarqubeserver:9000 -Dsonar.login=uname -Dsonar.password=pword sonar:sonar'), 'it should NOT have run SQ analysis in issues mode'); assert(tr.invokedToolCount == 2, 'should have only run maven 2 times'); assert(tr.resultWasSet, 'task should have set a result'); assert(tr.stderr.length == 0, 'should not have written to stderr');