From ab276504fde9c046b0018d9f4d39d5cb21600238 Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Thu, 9 Mar 2017 10:26:48 -0800 Subject: [PATCH] CB-12524: Windows functionality for Gradle execution --- bin/lib/check_reqs.js | 19 +++++++++---------- .../cordova/lib/builders/GradleBuilder.js | 10 +++++++--- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/bin/lib/check_reqs.js b/bin/lib/check_reqs.js index 6b3a630c..c6898e75 100644 --- a/bin/lib/check_reqs.js +++ b/bin/lib/check_reqs.js @@ -81,17 +81,17 @@ module.exports.check_ant = function() { module.exports.get_gradle_wrapper = function() { var androidStudioPath; - if(os.platform() == "darwin") { + if(os.platform() == 'darwin') { androidStudioPath = path.join('/Applications', 'Android Studio.app', 'Contents', 'gradle'); + } else if (os.platform() == 'win32') { + androidStudioPath = path.join(process.env['ProgramFiles'],'Android', 'Android Studio', 'gradle'); } - if(androidStudioPath != null && fs.existsSync(androidStudioPath)) { + if(androidStudioPath !== null && fs.existsSync(androidStudioPath)) { var dirs = fs.readdirSync(androidStudioPath); - if(dirs[0].split('-')[0] == "gradle") + if(dirs[0].split('-')[0] == 'gradle') { - //Sweet, we found the path, let's return it. - var gradle_cmd = os.platform() == "win32" ? "gradle.bat" : "gradle"; - return path.join(androidStudioPath, dirs[0], "bin", gradle_cmd); + return path.join(androidStudioPath, dirs[0], 'bin', 'gradle'); } } else { //OK, let's try to check for Gradle! @@ -107,10 +107,9 @@ module.exports.check_gradle = function() { return Q.reject(new CordovaError('Could not find gradle wrapper within Android SDK. Could not find Android SDK directory.\n' + 'Might need to install Android SDK or set up \'ANDROID_HOME\' env variable.')); - var path = this.get_gradle_wrapper(); - console.log(path); - if(path != '') - d.resolve(path); + var gradlePath = this.get_gradle_wrapper(); + if(gradlePath.length !== 0) + d.resolve(gradlePath); else d.reject(new CordovaError('Could not find an installed version of Gradle either in Android Studio,\n' + 'or on your system to install the gradle wrapper. Please include gradle \n' + diff --git a/bin/templates/cordova/lib/builders/GradleBuilder.js b/bin/templates/cordova/lib/builders/GradleBuilder.js index 24047775..6bad2d20 100644 --- a/bin/templates/cordova/lib/builders/GradleBuilder.js +++ b/bin/templates/cordova/lib/builders/GradleBuilder.js @@ -70,9 +70,13 @@ GradleBuilder.prototype.getArgs = function(cmd, opts) { */ GradleBuilder.prototype.runGradleWrapper = function(gradle_cmd) { - if(!fs.existsSync(this.root, 'gradle')) - return spawn(gradle_cmd, ["wrapper"], {stdio: 'inherit'}); -} + var gradlePath = path.join(this.root, 'gradlew'); + if(fs.existsSync(gradlePath)) { + //Literally do nothing, for some reason this works, while !fs.existsSync didn't on Windows + } else { + return spawn(gradle_cmd, ['wrapper'], {stdio: 'inherit'}); + } +}; // Makes the project buildable, minus the gradle wrapper.