Skip to content

Commit

Permalink
Fix gradle task to set workingDir to the path of the script (#6771)
Browse files Browse the repository at this point in the history
* Fix gradle task to set workingDir to the path of the script

* make workingDir input more visible
  • Loading branch information
Madhuri Gummalla authored Mar 22, 2018
1 parent 8c07f73 commit 528e62a
Show file tree
Hide file tree
Showing 29 changed files with 77 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"loc.group.displayName.CodeAnalysis": "Code Analysis",
"loc.input.label.wrapperScript": "Gradle wrapper",
"loc.input.help.wrapperScript": "Relative path from the repository root to the Gradle Wrapper script.",
"loc.input.label.options": "Options",
"loc.input.label.tasks": "Tasks",
"loc.input.label.cwd": "Working directory",
"loc.input.help.cwd": "Working directory in which to run the Gradle build. If not specified, the repository root directory is used.",
"loc.input.label.options": "Options",
"loc.input.label.tasks": "Tasks",
"loc.input.label.publishJUnitResults": "Publish to TFS/Team Services",
"loc.input.help.publishJUnitResults": "Select this option to publish JUnit test results produced by the Gradle build to TFS/Team Services. Each test results file matching `Test Results Files` will be published as a test run in TFS/Team Services.",
"loc.input.label.testResultsFiles": "Test results files",
Expand Down
1 change: 1 addition & 0 deletions Tasks/Gradle/Tests/L0AllDefaultInputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let taskPath = path.join(__dirname, '..', 'gradletask.js');
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tr.setInput('wrapperScript', 'gradlew');
tr.setInput('cwd', '/home/repo/src');
tr.setInput('options', '');
tr.setInput('tasks', 'build');
tr.setInput('javaHomeSelection', 'JDKVersion');
Expand Down
1 change: 1 addition & 0 deletions Tasks/Gradle/Tests/L0CAEmptyResultsEnabledTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ process.env['BUILD_ARTIFACTSTAGINGDIRECTORY'] = `${tempDir}`;
process.env['SYSTEM_DEFAULTWORKINGDIRECTORY'] = `${taskReportValidDir}`; //'/user/build/s';

tr.setInput('wrapperScript', 'gradlew');
tr.setInput('cwd', '/home/repo/src');
tr.setInput('options', '');
tr.setInput('tasks', 'build');
tr.setInput('javaHomeSelection', 'JDKVersion');
Expand Down
1 change: 1 addition & 0 deletions Tasks/Gradle/Tests/L0CANoToolsEnabled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ process.env['BUILD_ARTIFACTSTAGINGDIRECTORY'] = `${tempDir}`;
process.env['SYSTEM_DEFAULTWORKINGDIRECTORY'] = `${taskReportValidDir}`; //'/user/build/s';

tr.setInput('wrapperScript', 'gradlew');
tr.setInput('cwd', '/home/repo/src');
tr.setInput('options', '');
tr.setInput('tasks', 'build');
tr.setInput('javaHomeSelection', 'JDKVersion');
Expand Down
1 change: 1 addition & 0 deletions Tasks/Gradle/Tests/L0CANoUploadArtifactsIfReportsEmpty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ process.env['BUILD_ARTIFACTSTAGINGDIRECTORY'] = `${tempDir}`;
process.env['SYSTEM_DEFAULTWORKINGDIRECTORY'] = `${taskReportValidDir}`; //'/user/build/s';

tr.setInput('wrapperScript', 'gradlew');
tr.setInput('cwd', '/home/repo/src');
tr.setInput('options', '');
tr.setInput('tasks', 'build');
tr.setInput('javaHomeSelection', 'JDKVersion');
Expand Down
4 changes: 3 additions & 1 deletion Tasks/Gradle/Tests/L0GarbagePublishJUnitResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let taskPath = path.join(__dirname, '..', 'gradletask.js');
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tr.setInput('wrapperScript', 'gradlew');
tr.setInput('cwd', '/home/repo/src');
tr.setInput('options', '');
tr.setInput('tasks', 'build');
tr.setInput('javaHomeSelection', 'JDKVersion');
Expand All @@ -18,7 +19,8 @@ tr.setInput('publishJUnitResults', 'garbage');
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
'checkPath': {
'gradlew': true,
'gradlew.bat': true
'gradlew.bat': true,
'/home/repo/src': true
},
'exec': {
'gradlew build': {
Expand Down
3 changes: 1 addition & 2 deletions Tasks/Gradle/Tests/L0InvalidPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ let taskPath = path.join(__dirname, '..', 'gradletask.js');
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tr.setInput('wrapperScript', 'gradlew');
tr.setInput('cwd', '/home/repo/src2');
tr.setInput('options', '');
tr.setInput('tasks', 'build');
tr.setInput('javaHomeSelection', 'JDKVersion');
tr.setInput('jdkVersion', 'default');
tr.setInput('publishJUnitResults', 'true');
tr.setInput('testResultsFiles', '**/build/test-results/TEST-*.xml');

tr.setInput('cwd', '/home/repo/src2');

// provide answers for task mock
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
'checkPath': {
Expand Down
2 changes: 1 addition & 1 deletion Tasks/Gradle/Tests/L0InvalidWrapperScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ let taskPath = path.join(__dirname, '..', 'gradletask.js');
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tr.setInput('wrapperScript', '/home/gradlew');
tr.setInput('cwd', '/home/repo/src2');
tr.setInput('options', '');
tr.setInput('tasks', 'build');
tr.setInput('javaHomeSelection', 'JDKVersion');
tr.setInput('jdkVersion', 'default');
tr.setInput('publishJUnitResults', 'true');
tr.setInput('testResultsFiles', '**/build/test-results/TEST-*.xml');
tr.setInput('cwd', '/home/repo/src2');

// provide answers for task mock
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
Expand Down
4 changes: 3 additions & 1 deletion Tasks/Gradle/Tests/L0JDKVersion15.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let taskPath = path.join(__dirname, '..', 'gradletask.js');
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tr.setInput('wrapperScript', 'gradlew');
tr.setInput('cwd', '/home/repo/src');
tr.setInput('options', '');
tr.setInput('tasks', 'build');
tr.setInput('javaHomeSelection', 'JDKVersion');
Expand All @@ -18,7 +19,8 @@ tr.setInput('jdkArchitecture', 'x86');
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
'checkPath': {
'gradlew': true,
'gradlew.bat': true
'gradlew.bat': true,
'/home/repo/src': true
},
'exec': {
'gradlew build': {
Expand Down
4 changes: 3 additions & 1 deletion Tasks/Gradle/Tests/L0JDKVersion18.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let taskPath = path.join(__dirname, '..', 'gradletask.js');
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tr.setInput('wrapperScript', 'gradlew');
tr.setInput('cwd', '/home/repo/src');
tr.setInput('options', '');
tr.setInput('tasks', 'build');
tr.setInput('javaHomeSelection', 'JDKVersion');
Expand All @@ -20,7 +21,8 @@ process.env['JAVA_HOME_8_X86'] = '/user/local/bin/Java8'; //replace with mock of
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
'checkPath': {
'gradlew': true,
'gradlew.bat': true
'gradlew.bat': true,
'/home/repo/src': true
},
'exec': {
'gradlew build': {
Expand Down
4 changes: 3 additions & 1 deletion Tasks/Gradle/Tests/L0MissingJavaHomeSelectionInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let taskPath = path.join(__dirname, '..', 'gradletask.js');
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tr.setInput('wrapperScript', 'gradlew');
tr.setInput('cwd', '/home/repo/src');
tr.setInput('options', '/o "/p t i" /o /n /s');
tr.setInput('tasks', 'build test deploy');
tr.setInput('jdkVersion', 'default');
Expand All @@ -18,7 +19,8 @@ tr.setInput('testResultsFiles', '**/build/test-results/TEST-*.xml');
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
'checkPath': {
'gradlew': true,
'gradlew.bat': true
'gradlew.bat': true,
'/home/repo/src': true
}
};
tr.setAnswers(a);
Expand Down
4 changes: 3 additions & 1 deletion Tasks/Gradle/Tests/L0MissingPublishJUnitResultsInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let taskPath = path.join(__dirname, '..', 'gradletask.js');
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tr.setInput('wrapperScript', 'gradlew');
tr.setInput('cwd', '/home/repo/src');
tr.setInput('options', '');
tr.setInput('tasks', 'build');
tr.setInput('javaHomeSelection', 'JDKVersion');
Expand All @@ -18,7 +19,8 @@ tr.setInput('testResultsFiles', '**/build/test-results/TEST-*.xml');
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
'checkPath': {
'gradlew': true,
'gradlew.bat': true
'gradlew.bat': true,
'/home/repo/src': true
},
'exec': {
'gradlew build': {
Expand Down
4 changes: 3 additions & 1 deletion Tasks/Gradle/Tests/L0MissingTestResultsFilesInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let taskPath = path.join(__dirname, '..', 'gradletask.js');
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tr.setInput('wrapperScript', 'gradlew');
tr.setInput('cwd', '/home/repo/src');
tr.setInput('options', '/o "/p t i" /o /n /s');
tr.setInput('tasks', 'build test deploy');
tr.setInput('javaHomeSelection', 'JDKVersion');
Expand All @@ -18,7 +19,8 @@ tr.setInput('publishJUnitResults', 'true');
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
'checkPath': {
'gradlew': true,
'gradlew.bat': true
'gradlew.bat': true,
'/home/repo/src': true
}
};
tr.setAnswers(a);
Expand Down
1 change: 1 addition & 0 deletions Tasks/Gradle/Tests/L0MultiModuleCheckstyleFindBugsPMD.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ process.env['BUILD_ARTIFACTSTAGINGDIRECTORY'] = `${tempDir}`;
process.env['SYSTEM_DEFAULTWORKINGDIRECTORY'] = `${taskReportValidDir}`;

tr.setInput('wrapperScript', 'gradlew');
tr.setInput('cwd', '/home/repo/src');
tr.setInput('options', '');
tr.setInput('tasks', 'build');
tr.setInput('javaHomeSelection', 'JDKVersion');
Expand Down
4 changes: 3 additions & 1 deletion Tasks/Gradle/Tests/L0MultipleTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let taskPath = path.join(__dirname, '..', 'gradletask.js');
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tr.setInput('wrapperScript', 'gradlew');
tr.setInput('cwd', '/home/repo/src');
tr.setInput('options', '/o "/p t i" /o /n /s');
tr.setInput('javaHomeSelection', 'JDKVersion');
tr.setInput('jdkVersion', 'default');
Expand All @@ -18,7 +19,8 @@ tr.setInput('tasks', 'build test deploy');
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
'checkPath': {
'gradlew': true,
'gradlew.bat': true
'gradlew.bat': true,
'/home/repo/src': true
},
'exec': {
'gradlew /o /p t i /o /n /s build test deploy': {
Expand Down
4 changes: 3 additions & 1 deletion Tasks/Gradle/Tests/L0NoCodeCoverageFail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let taskPath = path.join(__dirname, '..', 'gradletask.js');
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tr.setInput('wrapperScript', 'gradlew');
tr.setInput('cwd', '/home/repo/src');
tr.setInput('javaHomeSelection', 'JDKVersion');
tr.setInput('jdkVersion', 'default');
tr.setInput('testResultsFiles', '**/build/test-results/TEST-*.xml');
Expand All @@ -18,7 +19,8 @@ tr.setInput('tasks', 'build');
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
'checkPath': {
'gradlew': true,
'gradlew.bat': true
'gradlew.bat': true,
'/home/repo/src': true
},
'exec': {
'gradlew.bat properties': {
Expand Down
4 changes: 3 additions & 1 deletion Tasks/Gradle/Tests/L0NoCodeCoverageSucceed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let taskPath = path.join(__dirname, '..', 'gradletask.js');
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tr.setInput('wrapperScript', 'gradlew');
tr.setInput('cwd', '/home/repo/src');
tr.setInput('javaHomeSelection', 'JDKVersion');
tr.setInput('jdkVersion', 'default');
tr.setInput('testResultsFiles', '**/build/test-results/TEST-*.xml');
Expand All @@ -18,7 +19,8 @@ tr.setInput('tasks', 'build');
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
'checkPath': {
'gradlew': true,
'gradlew.bat': true
'gradlew.bat': true,
'/home/repo/src': true
},
'exec': {
'gradlew.bat properties': {
Expand Down
4 changes: 3 additions & 1 deletion Tasks/Gradle/Tests/L0OptionsSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let taskPath = path.join(__dirname, '..', 'gradletask.js');
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tr.setInput('wrapperScript', 'gradlew');
tr.setInput('cwd', '/home/repo/src');
tr.setInput('options', '/o "/p t i" /o /n /s');
tr.setInput('tasks', 'build');
tr.setInput('javaHomeSelection', 'JDKVersion');
Expand All @@ -17,7 +18,8 @@ tr.setInput('testResultsFiles', '**/build/test-results/TEST-*.xml');
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
'checkPath': {
'gradlew': true,
'gradlew.bat': true
'gradlew.bat': true,
'/home/repo/src': true
},
'exec': {
'gradlew /o /p t i /o /n /s build': {
Expand Down
4 changes: 3 additions & 1 deletion Tasks/Gradle/Tests/L0PublishTestResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let taskPath = path.join(__dirname, '..', 'gradletask.js');
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tr.setInput('wrapperScript', 'gradlew');
tr.setInput('cwd', '/home/repo/src');
tr.setInput('options', '');
tr.setInput('tasks', 'build');
tr.setInput('javaHomeSelection', 'JDKVersion');
Expand All @@ -18,7 +19,8 @@ tr.setInput('codeCoverageTool', 'None');
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
'checkPath': {
'gradlew': true,
'gradlew.bat': true
'gradlew.bat': true,
'/home/repo/src': true
},
'exec': {
'gradlew build': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let taskPath = path.join(__dirname, '..', 'gradletask.js');
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tr.setInput('wrapperScript', 'gradlew');
tr.setInput('cwd', '/home/repo/src');
tr.setInput('options', '');
tr.setInput('tasks', 'build');
tr.setInput('javaHomeSelection', 'JDKVersion');
Expand All @@ -18,7 +19,8 @@ tr.setInput('codeCoverageTool', 'None');
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
'checkPath': {
'gradlew': true,
'gradlew.bat': true
'gradlew.bat': true,
'/home/repo/src': true
},
'exec': {
'gradlew build': {
Expand Down
1 change: 1 addition & 0 deletions Tasks/Gradle/Tests/L0SQ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ process.env['BUILD_ARTIFACTSTAGINGDIRECTORY'] = `${tempDir}`;
process.env['SYSTEM_DEFAULTWORKINGDIRECTORY'] = `${taskReportValidDir}`;

tr.setInput('wrapperScript', 'gradlew');
tr.setInput('cwd', '/home/repo/src');
tr.setInput('options', '');
tr.setInput('tasks', 'build');
tr.setInput('javaHomeSelection', 'JDKVersion');
Expand Down
1 change: 1 addition & 0 deletions Tasks/Gradle/Tests/L0SQGradleDefaultSQDisabled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ process.env['BUILD_REPOSITORY_PROVIDER'] = 'TFSGit';
process.env['SYSTEM_DEFAULTWORKINGDIRECTORY'] = '/user/build/s';

tr.setInput('wrapperScript', 'gradlew');
tr.setInput('cwd', '/home/repo/src');
tr.setInput('options', '');
tr.setInput('tasks', 'build');
tr.setInput('javaHomeSelection', 'JDKVersion');
Expand Down
1 change: 1 addition & 0 deletions Tasks/Gradle/Tests/L0SingleModuleCheckstyleFindBugsPMD.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ process.env['BUILD_ARTIFACTSTAGINGDIRECTORY'] = `${tempDir}`;
process.env['SYSTEM_DEFAULTWORKINGDIRECTORY'] = `${taskReportValidDir}`; //'/user/build/s';

tr.setInput('wrapperScript', 'gradlew');
tr.setInput('cwd', '/home/repo/src');
tr.setInput('options', '');
tr.setInput('tasks', 'build');
tr.setInput('javaHomeSelection', 'JDKVersion');
Expand Down
4 changes: 3 additions & 1 deletion Tasks/Gradle/Tests/L0TasksNotSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let taskPath = path.join(__dirname, '..', 'gradletask.js');
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tr.setInput('wrapperScript', 'gradlew');
tr.setInput('cwd', '/home/repo/src');
tr.setInput('options', '/o "/p t i" /o /n /s');
tr.setInput('javaHomeSelection', 'JDKVersion');
tr.setInput('jdkVersion', 'default');
Expand All @@ -18,7 +19,8 @@ tr.setInput('testResultsFiles', '**/build/test-results/TEST-*.xml');
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
'checkPath': {
'gradlew': true,
'gradlew.bat': true
'gradlew.bat': true,
'/home/repo/src': true
},
'exec': {
'gradlew build': {
Expand Down
3 changes: 1 addition & 2 deletions Tasks/Gradle/Tests/L0ValidCwdPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ let taskPath = path.join(__dirname, '..', 'gradletask.js');
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tr.setInput('wrapperScript', 'gradlew');
tr.setInput('cwd', '/home/repo/src');
tr.setInput('options', '');
tr.setInput('tasks', 'build');
tr.setInput('javaHomeSelection', 'JDKVersion');
tr.setInput('jdkVersion', 'default');
tr.setInput('publishJUnitResults', 'true');
tr.setInput('testResultsFiles', '**/build/test-results/TEST-*.xml');

tr.setInput('cwd', '/home/repo/src');

// provide answers for task mock
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
'checkPath': {
Expand Down
4 changes: 3 additions & 1 deletion Tasks/Gradle/Tests/L0ValidInputsFailure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let taskPath = path.join(__dirname, '..', 'gradletask.js');
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tr.setInput('wrapperScript', 'gradlew');
tr.setInput('cwd', '/home/repo/src');
tr.setInput('options', '');
tr.setInput('tasks', 'build FAIL');
tr.setInput('javaHomeSelection', 'JDKVersion');
Expand All @@ -17,7 +18,8 @@ tr.setInput('testResultsFiles', '**/build/test-results/TEST-*.xml');
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
'checkPath': {
'gradlew': true,
'gradlew.bat': true
'gradlew.bat': true,
'/home/repo/src': true
},
'exec': {
'gradlew build FAIL': {
Expand Down
3 changes: 0 additions & 3 deletions Tasks/Gradle/gradletask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,6 @@ async function run() {

// Set working directory
let workingDirectory: string = tl.getPathInput('cwd', false, true);
if (!workingDirectory) {
workingDirectory = path.dirname(wrapperScript);
}
tl.cd(workingDirectory);

let javaHomeSelection: string = tl.getInput('javaHomeSelection', true);
Expand Down
Loading

0 comments on commit 528e62a

Please sign in to comment.