diff --git a/bin/templates/cordova/lib/builders/GradleBuilder.js b/bin/templates/cordova/lib/builders/GradleBuilder.js index 5b5ce13d..0d32d566 100644 --- a/bin/templates/cordova/lib/builders/GradleBuilder.js +++ b/bin/templates/cordova/lib/builders/GradleBuilder.js @@ -22,7 +22,7 @@ var fs = require('fs'); var util = require('util'); var path = require('path'); var shell = require('shelljs'); -var spawn = require('cordova-common').superspawn.spawn; +var superspawn = require('cordova-common').superspawn; var CordovaError = require('cordova-common').CordovaError; var check_reqs = require('../check_reqs'); @@ -75,7 +75,7 @@ GradleBuilder.prototype.runGradleWrapper = function(gradle_cmd) { if(fs.existsSync(gradlePath)) { //Literally do nothing, for some reason this works, while !fs.existsSync didn't on Windows } else { - return spawn(gradle_cmd, ['-p', this.root, 'wrapper', '-b', wrapperGradle], {stdio: 'inherit'}); + return superspawn.spawn(gradle_cmd, ['-p', this.root, 'wrapper', '-b', wrapperGradle], {stdio: 'inherit'}); } }; @@ -223,7 +223,7 @@ GradleBuilder.prototype.build = function(opts) { var wrapper = path.join(this.root, 'gradlew'); var args = this.getArgs(opts.buildType == 'debug' ? 'debug' : 'release', opts); - return spawn(wrapper, args, {stdio: 'pipe'}) + return superspawn.spawn(wrapper, args, {stdio: 'pipe'}) .progress(function (stdio){ if (stdio.stderr) { /* @@ -258,7 +258,7 @@ GradleBuilder.prototype.clean = function(opts) { var wrapper = path.join(this.root, 'gradlew'); var args = builder.getArgs('clean', opts); return Q().then(function() { - return spawn(wrapper, args, {stdio: 'inherit'}); + return superspawn.spawn(wrapper, args, {stdio: 'inherit'}); }) .then(function () { shell.rm('-rf', path.join(builder.root, 'out')); diff --git a/spec/unit/builders/GradleBuilder.spec.js b/spec/unit/builders/GradleBuilder.spec.js new file mode 100644 index 00000000..28652bd2 --- /dev/null +++ b/spec/unit/builders/GradleBuilder.spec.js @@ -0,0 +1,25 @@ +var gradle_builder = require('../../../bin/templates/cordova/lib/builders/GradleBuilder.js'); +var fs = require('fs'); +var superspawn = require('cordova-common').superspawn; +var builder; + +describe('Gradle Builder', function() { + beforeEach(function() { + spyOn(fs, 'existsSync').and.returnValue(true); + builder = new gradle_builder('/root'); + spyOn(superspawn, 'spawn'); + }); + + describe('runGradleWrapper method', function() { + it('should run the provided gradle command if a gradle wrapper does not already exist', function() { + fs.existsSync.and.returnValue(false); + builder.runGradleWrapper('/my/sweet/gradle'); + expect(superspawn.spawn).toHaveBeenCalledWith('/my/sweet/gradle', jasmine.any(Array), jasmine.any(Object)); + }); + it('should do nothing if a gradle wrapper exists in the project directory', function() { + fs.existsSync.and.returnValue(true); + builder.runGradleWrapper('/my/sweet/gradle'); + expect(superspawn.spawn).not.toHaveBeenCalledWith('/my/sweet/gradle', jasmine.any(Array), jasmine.any(Object)); + }); + }); +});