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

Made project parameters mandatory in code for SonarQube analysis in G… #1814

Merged
merged 1 commit into from
May 31, 2016
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
6 changes: 3 additions & 3 deletions Tasks/Gradle/gradlesonar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ export function applyEnabledSonarQubeArguments(gradleRun: trm.ToolRunner):trm.To
}

// Add parameters to specify the SonarQube project properties (if given by the user)
var projectName:string = tl.getInput('sqProjectName', false);
var projectKey:string = tl.getInput('sqProjectKey', false);
var projectVersion:string = tl.getInput('sqProjectVersion', false);
var projectName:string = tl.getInput('sqProjectName', true);
var projectKey:string = tl.getInput('sqProjectKey', true);
var projectVersion:string = tl.getInput('sqProjectVersion', true);
gradleRun = sqCommon.applySonarQubeAnalysisParams(gradleRun, projectName, projectKey, projectVersion);

return gradleRun;
Expand Down
69 changes: 7 additions & 62 deletions Tests/L0/Gradle/_suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -642,65 +642,6 @@ describe('gradle Suite', function() {

setResponseFile('gradleGood.json');

var tr = new TaskRunner('gradle', true, true);
tr = setDefaultInputs(tr);
tr.setInput('sqAnalysisEnabled', 'true');
tr.setInput('sqConnectedServiceName', 'ID1');

// Act
tr.run()
.then(() => {
// Assert
assert(tr.succeeded, 'task should have succeeded');
assert(tr.invokedToolCount == 1, 'should have only run gradle 1 time');
assert(tr.resultWasSet, 'task should have set a result');
assert(tr.stderr.length == 0, 'should not have written to stderr');
assert(tr.ran('gradlew build -I /gradle/sonar.gradle sonarqube -Dsonar.host.url=http://sonarqube/end/point -Dsonar.login=uname -Dsonar.password=pword'),
'should have run the gradle wrapper with the appropriate SonarQube arguments');
done();
})
.fail((err) => {
console.log(tr.stdout);
done(err);
});
});

it('Gradle with SonarQube - Should run Gradle with SonarQube and apply required parameters for older server versions', function(done) {
// Arrange
setResponseFile('gradleGood.json');

var tr = new TaskRunner('gradle', true, true);
tr = setDefaultInputs(tr);
tr.setInput('sqAnalysisEnabled', 'true');
tr.setInput('sqConnectedServiceName', 'ID1');
tr.setInput('sqDbDetailsRequired', 'true');
tr.setInput('sqDbUrl', 'jdbc:test:tcp://localhost:8080/sonar');
tr.setInput('sqDbUsername', 'testDbUsername');
tr.setInput('sqDbPassword', 'testDbPassword');

// Act
tr.run()
.then(() => {
// Assert
assert(tr.succeeded, 'task should have succeeded');
assert(tr.invokedToolCount == 1, 'should have only run gradle 1 time');
assert(tr.resultWasSet, 'task should have set a result');
assert(tr.stderr.length == 0, 'should not have written to stderr');
assert(tr.ran('gradlew build -I /gradle/sonar.gradle sonarqube -Dsonar.host.url=http://sonarqube/end/point -Dsonar.login=uname -Dsonar.password=pword -Dsonar.jdbc.url=jdbc:test:tcp://localhost:8080/sonar -Dsonar.jdbc.username=testDbUsername -Dsonar.jdbc.password=testDbPassword'),
'should have run the gradle wrapper with the appropriate SonarQube arguments');
done();
})
.fail((err) => {
console.log(tr.stdout);
done(err);
});
});

it('Gradle with SonarQube - Should run Gradle with SonarQube and override project parameters if specified', function(done) {
// Arrange

setResponseFile('gradleGood.json');

var tr = new TaskRunner('gradle', true, true);
tr = setDefaultInputs(tr);
tr.setInput('sqAnalysisEnabled', 'true');
Expand All @@ -727,9 +668,8 @@ describe('gradle Suite', function() {
});
});

it('Gradle with SonarQube - Should run Gradle with SonarQube and override project parameters if specified', function(done) {
it('Gradle with SonarQube - Should run Gradle with SonarQube and apply required parameters for older server versions', function(done) {
// Arrange

setResponseFile('gradleGood.json');

var tr = new TaskRunner('gradle', true, true);
Expand All @@ -740,6 +680,11 @@ describe('gradle Suite', function() {
tr.setInput('sqProjectKey', 'test_sqProjectKey');
tr.setInput('sqProjectVersion', 'test_sqProjectVersion');

tr.setInput('sqDbDetailsRequired', 'true');
tr.setInput('sqDbUrl', 'jdbc:test:tcp://localhost:8080/sonar');
tr.setInput('sqDbUsername', 'testDbUsername');
tr.setInput('sqDbPassword', 'testDbPassword');

// Act
tr.run()
.then(() => {
Expand All @@ -748,7 +693,7 @@ describe('gradle Suite', function() {
assert(tr.invokedToolCount == 1, 'should have only run gradle 1 time');
assert(tr.resultWasSet, 'task should have set a result');
assert(tr.stderr.length == 0, 'should not have written to stderr');
assert(tr.ran('gradlew build -I /gradle/sonar.gradle sonarqube -Dsonar.host.url=http://sonarqube/end/point -Dsonar.login=uname -Dsonar.password=pword -Dsonar.projectName=test_sqProjectName -Dsonar.projectKey=test_sqProjectKey -Dsonar.projectVersion=test_sqProjectVersion'),
assert(tr.ran('gradlew build -I /gradle/sonar.gradle sonarqube -Dsonar.host.url=http://sonarqube/end/point -Dsonar.login=uname -Dsonar.password=pword -Dsonar.jdbc.url=jdbc:test:tcp://localhost:8080/sonar -Dsonar.jdbc.username=testDbUsername -Dsonar.jdbc.password=testDbPassword -Dsonar.projectName=test_sqProjectName -Dsonar.projectKey=test_sqProjectKey -Dsonar.projectVersion=test_sqProjectVersion'),
'should have run the gradle wrapper with the appropriate SonarQube arguments');
done();
})
Expand Down
8 changes: 2 additions & 6 deletions Tests/L0/Gradle/gradleGood.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,13 @@
"code": 0,
"stdout": "More sample gradle output"
},
"gradlew build -I /gradle/sonar.gradle sonarqube -Dsonar.host.url=http://sonarqube/end/point -Dsonar.login=uname -Dsonar.password=pword": {
"gradlew build -I /gradle/sonar.gradle sonarqube -Dsonar.host.url=http://sonarqube/end/point -Dsonar.login=uname -Dsonar.password=pword -Dsonar.projectName=test_sqProjectName -Dsonar.projectKey=test_sqProjectKey -Dsonar.projectVersion=test_sqProjectVersion": {
"code": 0,
"stdout": "Maven package and SQ analysis done"
},
"gradlew build -I /gradle/sonar.gradle sonarqube -Dsonar.host.url=http://sonarqube/end/point -Dsonar.login=uname -Dsonar.password=pword -Dsonar.jdbc.url=jdbc:test:tcp://localhost:8080/sonar -Dsonar.jdbc.username=testDbUsername -Dsonar.jdbc.password=testDbPassword": {
"gradlew build -I /gradle/sonar.gradle sonarqube -Dsonar.host.url=http://sonarqube/end/point -Dsonar.login=uname -Dsonar.password=pword -Dsonar.jdbc.url=jdbc:test:tcp://localhost:8080/sonar -Dsonar.jdbc.username=testDbUsername -Dsonar.jdbc.password=testDbPassword -Dsonar.projectName=test_sqProjectName -Dsonar.projectKey=test_sqProjectKey -Dsonar.projectVersion=test_sqProjectVersion": {
"code": 0,
"stdout": "Maven package and SQ analysis (older version) done"
},
"gradlew build -I /gradle/sonar.gradle sonarqube -Dsonar.host.url=http://sonarqube/end/point -Dsonar.login=uname -Dsonar.password=pword -Dsonar.projectName=test_sqProjectName -Dsonar.projectKey=test_sqProjectKey -Dsonar.projectVersion=test_sqProjectVersion": {
"code": 0,
"stdout": "Maven package and SQ analysis (project name / key / version override) done"
}
},
"checkPath": {
Expand Down