Repository: cordova-android
Updated Branches:
  refs/heads/master 723393168 -> 7be9e880c


CB-10618 Handle gradle frameworks on plugin installation/uninstallation

This closes #259


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

Branch: refs/heads/master
Commit: 7be9e880c28ab753ea32353bbe53836bb85663a9
Parents: 7233931
Author: Vladimir Kotikov <[email protected]>
Authored: Wed Feb 17 16:37:58 2016 +0300
Committer: Vladimir Kotikov <[email protected]>
Committed: Wed Feb 17 17:56:09 2016 +0300

----------------------------------------------------------------------
 bin/lib/create.js                               |  4 +-
 bin/templates/cordova/Api.js                    | 10 +++
 bin/templates/cordova/lib/build.js              |  5 --
 package.json                                    |  4 +-
 spec/create/create.spec.js                      | 87 --------------------
 .../plugin.xml                                  | 41 +++++++++
 spec/unit/create.spec.js                        | 87 ++++++++++++++++++++
 spec/unit/plugin.spec.js                        | 77 +++++++++++++++++
 8 files changed, 219 insertions(+), 96 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/7be9e880/bin/lib/create.js
----------------------------------------------------------------------
diff --git a/bin/lib/create.js b/bin/lib/create.js
index 0307fd5..d8def89 100755
--- a/bin/lib/create.js
+++ b/bin/lib/create.js
@@ -126,8 +126,8 @@ function writeProjectProperties(projectPath, target_api) {
 }
 
 function prepBuildFiles(projectPath) {
-    var buildModule = require(path.join(path.resolve(projectPath), 'cordova', 
'lib', 'build'));
-    buildModule.prepBuildFiles();
+    var buildModule = require(path.resolve(projectPath, 
'cordova/lib/builders/builders'));
+    buildModule.getBuilder('gradle').prepBuildFiles();
 }
 
 function copyBuildRules(projectPath) {

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/7be9e880/bin/templates/cordova/Api.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/Api.js b/bin/templates/cordova/Api.js
index 9a8938c..ad6f71c 100644
--- a/bin/templates/cordova/Api.js
+++ b/bin/templates/cordova/Api.js
@@ -219,6 +219,11 @@ Api.prototype.addPlugin = function (plugin, 
installOptions) {
             .add_plugin_changes(plugin, installOptions.variables, 
/*is_top_level=*/true, /*should_increment=*/true)
             .save_all();
 
+        if (plugin.getFrameworks(self.platform).length > 0) {
+            self.events.emit('verbose', 'Updating build files since android 
plugin contained <framework>');
+            
require('./lib/builders/builders').getBuilder('gradle').prepBuildFiles();
+        }
+
         var targetDir = installOptions.usePlatformWww ?
             self.locations.platformWww :
             self.locations.www;
@@ -272,6 +277,11 @@ Api.prototype.removePlugin = function (plugin, 
uninstallOptions) {
             .remove_plugin_changes(plugin, /*is_top_level=*/true)
             .save_all();
 
+        if (plugin.getFrameworks(self.platform).length > 0) {
+            self.events.emit('verbose', 'Updating build files since android 
plugin contained <framework>');
+            
require('./lib/builders/builders').getBuilder('gradle').prepBuildFiles();
+        }
+
         var targetDir = uninstallOptions.usePlatformWww ?
             self.locations.platformWww :
             self.locations.www;

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/7be9e880/bin/templates/cordova/lib/build.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/build.js 
b/bin/templates/cordova/lib/build.js
index 0a2e5fa..e1263ef 100644
--- a/bin/templates/cordova/lib/build.js
+++ b/bin/templates/cordova/lib/build.js
@@ -169,11 +169,6 @@ module.exports.run = function(options, optResolvedTarget) {
     });
 };
 
-// Called by plugman after installing plugins, and by create script after 
creating project.
-module.exports.prepBuildFiles = function() {
-    return builders.getBuilder('gradle').prepBuildFiles();
-};
-
 /*
  * Detects the architecture of a device/emulator
  * Returns "arm" or "x86".

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/7be9e880/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index cfdcbc2..d3c5942 100644
--- a/package.json
+++ b/package.json
@@ -16,7 +16,7 @@
         "apache"
     ],
     "scripts": {
-        "test": "npm run jshint && jasmine-node --color spec/create",
+        "test": "npm run jshint && jasmine-node --color spec/unit",
         "test-build": "jasmine-node --captureExceptions --color spec/e2e",
         "jshint": "node node_modules/jshint/bin/jshint bin && node 
node_modules/jshint/bin/jshint spec"
     },
@@ -43,4 +43,4 @@
         "jshint": "^2.6.0",
         "promise-matchers": "~0"
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/7be9e880/spec/create/create.spec.js
----------------------------------------------------------------------
diff --git a/spec/create/create.spec.js b/spec/create/create.spec.js
deleted file mode 100644
index 2a1038e..0000000
--- a/spec/create/create.spec.js
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
-    Licensed to the Apache Software Foundation (ASF) under one
-    or more contributor license agreements.  See the NOTICE file
-    distributed with this work for additional information
-    regarding copyright ownership.  The ASF licenses this file
-    to you under the Apache License, Version 2.0 (the
-    "License"); you may not use this file except in compliance
-    with the License.  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing,
-    software distributed under the License is distributed on an
-    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-    KIND, either express or implied.  See the License for the
-    specific language governing permissions and limitations
-    under the License.
-*/
-/* jshint laxcomma:true */
-
-require("promise-matchers");
-
-var create = require("../../bin/lib/create");
-
-describe("create", function () {
-  describe("validatePackageName", function() {
-    var valid = [
-        "org.apache.mobilespec"
-      , "com.example"
-      , "com.floors42.package"
-      , "ball8.ball8.ball8ball"
-    ];
-    var invalid = [
-        ""
-      , "com.class.is.bad"
-      , "0com.example.mobilespec"
-      , "c-m.e@a!p%e.mobilespec"
-      , "notenoughdots"
-      , ".starts.with.a.dot"
-      , "ends.with.a.dot."
-      , "_underscore.anything"
-      , "underscore._something"
-      , "_underscore._all._the._things"
-      , "8.ball"
-      , "8ball.ball"
-      , "ball8.8ball"
-      , "ball8.com.8ball"
-    ];
-
-    valid.forEach(function(package_name) {
-      it("should accept " + package_name, function(done) {
-        
expect(create.validatePackageName(package_name)).toHaveBeenResolved(done);
-      });
-    });
-
-    invalid.forEach(function(package_name) {
-      it("should reject " + package_name, function(done) {
-        
expect(create.validatePackageName(package_name)).toHaveBeenRejected(done);
-      });
-    });
-  });
-  describe("validateProjectName", function() {
-    var valid = [
-        "mobilespec"
-      , "package_name"
-      , "PackageName"
-      , "CordovaLib"
-    ];
-    var invalid = [
-        ""
-      , "0startswithdigit"
-      , "CordovaActivity"
-    ];
-
-    valid.forEach(function(project_name) {
-      it("should accept " + project_name, function(done) {
-        
expect(create.validateProjectName(project_name)).toHaveBeenResolved(done);
-      });
-    });
-
-    invalid.forEach(function(project_name) {
-      it("should reject " + project_name, function(done) {
-        
expect(create.validateProjectName(project_name)).toHaveBeenRejected(done);
-      });
-    });
-  });
-});

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/7be9e880/spec/e2e/fixtures/cordova-plugin-fake-ios-frameworks/plugin.xml
----------------------------------------------------------------------
diff --git a/spec/e2e/fixtures/cordova-plugin-fake-ios-frameworks/plugin.xml 
b/spec/e2e/fixtures/cordova-plugin-fake-ios-frameworks/plugin.xml
new file mode 100644
index 0000000..6df9acd
--- /dev/null
+++ b/spec/e2e/fixtures/cordova-plugin-fake-ios-frameworks/plugin.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0";
+        xmlns:android="http://schemas.android.com/apk/res/android";
+        id="cordova-plugin-fake"
+        version="1.0.0">
+
+    <name>Fake</name>
+
+    <description>
+      Fake plugin to test plugin installation and properties parsing on 
Android.
+    </description>
+
+    <license>Apache 2.0</license>
+
+    <engines>
+        <!-- Requires > 3.5.0 because of the custom framework tag for Android 
[CB-6698] -->
+        <engine name="cordova" version=">=3.5.0" />
+    </engines>
+
+    <platform name="ios">
+        <framework src="customFramework" custom="true" />
+    </platform>
+</plugin>

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/7be9e880/spec/unit/create.spec.js
----------------------------------------------------------------------
diff --git a/spec/unit/create.spec.js b/spec/unit/create.spec.js
new file mode 100644
index 0000000..2a1038e
--- /dev/null
+++ b/spec/unit/create.spec.js
@@ -0,0 +1,87 @@
+/**
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+*/
+/* jshint laxcomma:true */
+
+require("promise-matchers");
+
+var create = require("../../bin/lib/create");
+
+describe("create", function () {
+  describe("validatePackageName", function() {
+    var valid = [
+        "org.apache.mobilespec"
+      , "com.example"
+      , "com.floors42.package"
+      , "ball8.ball8.ball8ball"
+    ];
+    var invalid = [
+        ""
+      , "com.class.is.bad"
+      , "0com.example.mobilespec"
+      , "c-m.e@a!p%e.mobilespec"
+      , "notenoughdots"
+      , ".starts.with.a.dot"
+      , "ends.with.a.dot."
+      , "_underscore.anything"
+      , "underscore._something"
+      , "_underscore._all._the._things"
+      , "8.ball"
+      , "8ball.ball"
+      , "ball8.8ball"
+      , "ball8.com.8ball"
+    ];
+
+    valid.forEach(function(package_name) {
+      it("should accept " + package_name, function(done) {
+        
expect(create.validatePackageName(package_name)).toHaveBeenResolved(done);
+      });
+    });
+
+    invalid.forEach(function(package_name) {
+      it("should reject " + package_name, function(done) {
+        
expect(create.validatePackageName(package_name)).toHaveBeenRejected(done);
+      });
+    });
+  });
+  describe("validateProjectName", function() {
+    var valid = [
+        "mobilespec"
+      , "package_name"
+      , "PackageName"
+      , "CordovaLib"
+    ];
+    var invalid = [
+        ""
+      , "0startswithdigit"
+      , "CordovaActivity"
+    ];
+
+    valid.forEach(function(project_name) {
+      it("should accept " + project_name, function(done) {
+        
expect(create.validateProjectName(project_name)).toHaveBeenResolved(done);
+      });
+    });
+
+    invalid.forEach(function(project_name) {
+      it("should reject " + project_name, function(done) {
+        
expect(create.validateProjectName(project_name)).toHaveBeenRejected(done);
+      });
+    });
+  });
+});

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/7be9e880/spec/unit/plugin.spec.js
----------------------------------------------------------------------
diff --git a/spec/unit/plugin.spec.js b/spec/unit/plugin.spec.js
new file mode 100644
index 0000000..59fb709
--- /dev/null
+++ b/spec/unit/plugin.spec.js
@@ -0,0 +1,77 @@
+/**
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    'License'); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+*/
+
+/* jshint node:true */
+
+var Q = require('q');
+var os = require('os');
+var path = require('path');
+var common = require('cordova-common');
+
+var AndroidProject = require('../../bin/templates/cordova/lib/AndroidProject');
+var builders = require('../../bin/templates/cordova/lib/builders/builders');
+
+var PluginInfo = common.PluginInfo;
+
+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;
+
+    beforeEach(function() {
+        var ActionStack = jasmine.createSpyObj('ActionStack', ['createAction', 
'push', 'process']);
+        ActionStack.process.andReturn(Q());
+        spyOn(common, 'ActionStack').andReturn(ActionStack);
+
+        spyOn(AndroidProject, 'getProjectFile')
+            .andReturn(jasmine.createSpyObj('AndroidProject', 
['getPackageName', 'write']));
+
+        var Api = require('../../bin/templates/cordova/Api');
+        api = new Api('android', FAKE_PROJECT_DIR);
+
+        spyOn(api, '_addModulesInfo');
+        spyOn(api._munger, 'add_plugin_changes')
+            .andReturn(jasmine.createSpyObj('munger', ['save_all']));
+
+        fail = jasmine.createSpy('fail');
+        gradleBuilder = jasmine.createSpyObj('gradleBuilder', 
['prepBuildFiles']);
+        spyOn(builders, 'getBuilder').andReturn(gradleBuilder);
+    });
+
+    it('should call gradleBuilder.prepBuildFiles for every plugin with 
frameworks', function(done) {
+        api.addPlugin(new PluginInfo(path.join(FIXTURES, 
'cordova-plugin-fake')))
+        .catch(fail)
+        .fin(function () {
+            expect(fail).not.toHaveBeenCalled();
+            expect(gradleBuilder.prepBuildFiles).toHaveBeenCalled();
+            done();
+        });
+    });
+
+    it('shouldn\'t trigger gradleBuilder.prepBuildFiles for plugins without 
android frameworks', function(done) {
+        api.addPlugin(new PluginInfo(path.join(FIXTURES, 
'cordova-plugin-fake-ios-frameworks')))
+        .catch(fail)
+        .fin(function () {
+            expect(fail).not.toHaveBeenCalled();
+            expect(gradleBuilder.prepBuildFiles).not.toHaveBeenCalled();
+            done();
+        });
+    });
+});


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to