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

Changing the Maven task to work for SonarQube #4564

Merged
merged 1 commit into from
Jun 16, 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
8 changes: 8 additions & 0 deletions Tasks/Maven/CodeAnalysis/SonarQube/vsts-server-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -36,6 +43,7 @@ export class VstsServerUtils {
sccProvider.toLowerCase() === "tfsgit" &&
!VstsServerUtils.isNullOrEmpty(sourceBranch) &&
sourceBranch.toLowerCase().startsWith("refs/pull/");
*/
}

/**
Expand Down
58 changes: 2 additions & 56 deletions Tests-Legacy/L0/Maven/_suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down