cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bows...@apache.org
Subject [6/6] android commit: CB-11964 Call clean after plugin install and mock it in tests
Date Sat, 08 Oct 2016 01:14:47 GMT
CB-11964 Call clean after plugin install and mock it in tests


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/5db2de95
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/5db2de95
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/5db2de95

Branch: refs/heads/master
Commit: 5db2de95f586eec1713656051e47c0d0bdc73a10
Parents: 6418add
Author: Alexander Sorokin <alexander.sorokin@akvelon.com>
Authored: Fri Oct 7 15:12:25 2016 +0300
Committer: Joe Bowser <bowserj@apache.org>
Committed: Fri Oct 7 18:14:36 2016 -0700

----------------------------------------------------------------------
 bin/templates/cordova/Api.js | 22 ++++++++++++++--------
 spec/unit/Api.spec.js        | 11 +++++++++--
 2 files changed, 23 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/5db2de95/bin/templates/cordova/Api.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/Api.js b/bin/templates/cordova/Api.js
index b7411dc..2f1fd86 100644
--- a/bin/templates/cordova/Api.js
+++ b/bin/templates/cordova/Api.js
@@ -18,6 +18,7 @@
 */
 
 var path = require('path');
+var Q = require('q');
 
 var AndroidProject = require('./lib/AndroidProject');
 var AndroidStudio = require('./lib/AndroidStudio');
@@ -200,6 +201,7 @@ Api.prototype.prepare = function (cordovaProject, prepareOptions) {
  */
 Api.prototype.addPlugin = function (plugin, installOptions) {
     var project = AndroidProject.getProjectFile(this.root);
+    var self = this;
 
     installOptions = installOptions || {};
     installOptions.variables = installOptions.variables || {};
@@ -207,18 +209,22 @@ Api.prototype.addPlugin = function (plugin, installOptions) {
     if (!installOptions.variables.PACKAGE_NAME) {
         installOptions.variables.PACKAGE_NAME = project.getPackageName();
     }
-    
+
     if(this.android_studio === true) {
       installOptions.android_studio = true;
     }
 
-    //CB-11964: Do a clean when installing the plugin code to get around
-    //the Gradle bug introduced by the Android Gradle Plugin Version 2.2
-    //TODO: Delete when the next version of Android Gradle plugin comes out
-    
-    this.clean();
-    return PluginManager.get(this.platform, this.locations, project)
-        .addPlugin(plugin, installOptions)
+    return Q()
+        .then(function () {
+            //CB-11964: Do a clean when installing the plugin code to get around
+            //the Gradle bug introduced by the Android Gradle Plugin Version 2.2
+            //TODO: Delete when the next version of Android Gradle plugin comes out
+            return self.clean();
+        })
+        .then(function () {
+            return PluginManager.get(self.platform, self.locations, project)
+                .addPlugin(plugin, installOptions);
+        })
         .then(function () {
             if (plugin.getFrameworks(this.platform).length === 0) return;
 

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/5db2de95/spec/unit/Api.spec.js
----------------------------------------------------------------------
diff --git a/spec/unit/Api.spec.js b/spec/unit/Api.spec.js
index 11aea92..ab9479e 100644
--- a/spec/unit/Api.spec.js
+++ b/spec/unit/Api.spec.js
@@ -23,6 +23,7 @@ var Q = require('q');
 var os = require('os');
 var path = require('path');
 var common = require('cordova-common');
+var rewire = require('rewire');
 
 var AndroidProject = require('../../bin/templates/cordova/lib/AndroidProject');
 var builders = require('../../bin/templates/cordova/lib/builders/builders');
@@ -33,7 +34,8 @@ var FIXTURES = path.join(__dirname, '../e2e/fixtures');
 var FAKE_PROJECT_DIR = path.join(os.tmpdir(), 'plugin-test-project');
 
 describe('addPlugin method', function () {
-    var api, fail, gradleBuilder;
+    var api, fail, gradleBuilder, oldClean;
+    var Api = rewire('../../bin/templates/cordova/Api');
 
     beforeEach(function() {
         var pluginManager = jasmine.createSpyObj('pluginManager', ['addPlugin']);
@@ -43,7 +45,8 @@ describe('addPlugin method', function () {
         var projectSpy = jasmine.createSpyObj('AndroidProject', ['getPackageName', 'write']);
         spyOn(AndroidProject, 'getProjectFile').andReturn(projectSpy);
 
-        var Api = require('../../bin/templates/cordova/Api');
+        oldClean = Api.__get__('Api.prototype.clean');
+        Api.__set__('Api.prototype.clean', Q);
         api = new Api('android', FAKE_PROJECT_DIR);
 
         fail = jasmine.createSpy('fail');
@@ -51,6 +54,10 @@ describe('addPlugin method', function () {
         spyOn(builders, 'getBuilder').andReturn(gradleBuilder);
     });
 
+    afterEach(function () {
+        Api.__set__('Api.prototype.clean', oldClean);
+    });
+
     it('should call gradleBuilder.prepBuildFiles for every plugin with frameworks', function(done)
{
         api.addPlugin(new PluginInfo(path.join(FIXTURES, 'cordova-plugin-fake')))
         .catch(fail)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message