Skip to content

Commit 7be9e88

Browse files
author
Vladimir Kotikov
committedFeb 17, 2016
CB-10618 Handle gradle frameworks on plugin installation/uninstallation
This closes #259
1 parent 7233931 commit 7be9e88

File tree

7 files changed

+132
-9
lines changed

7 files changed

+132
-9
lines changed
 

‎bin/lib/create.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ function writeProjectProperties(projectPath, target_api) {
126126
}
127127

128128
function prepBuildFiles(projectPath) {
129-
var buildModule = require(path.join(path.resolve(projectPath), 'cordova', 'lib', 'build'));
130-
buildModule.prepBuildFiles();
129+
var buildModule = require(path.resolve(projectPath, 'cordova/lib/builders/builders'));
130+
buildModule.getBuilder('gradle').prepBuildFiles();
131131
}
132132

133133
function copyBuildRules(projectPath) {

‎bin/templates/cordova/Api.js

+10
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@ Api.prototype.addPlugin = function (plugin, installOptions) {
219219
.add_plugin_changes(plugin, installOptions.variables, /*is_top_level=*/true, /*should_increment=*/true)
220220
.save_all();
221221

222+
if (plugin.getFrameworks(self.platform).length > 0) {
223+
self.events.emit('verbose', 'Updating build files since android plugin contained <framework>');
224+
require('./lib/builders/builders').getBuilder('gradle').prepBuildFiles();
225+
}
226+
222227
var targetDir = installOptions.usePlatformWww ?
223228
self.locations.platformWww :
224229
self.locations.www;
@@ -272,6 +277,11 @@ Api.prototype.removePlugin = function (plugin, uninstallOptions) {
272277
.remove_plugin_changes(plugin, /*is_top_level=*/true)
273278
.save_all();
274279

280+
if (plugin.getFrameworks(self.platform).length > 0) {
281+
self.events.emit('verbose', 'Updating build files since android plugin contained <framework>');
282+
require('./lib/builders/builders').getBuilder('gradle').prepBuildFiles();
283+
}
284+
275285
var targetDir = uninstallOptions.usePlatformWww ?
276286
self.locations.platformWww :
277287
self.locations.www;

‎bin/templates/cordova/lib/build.js

-5
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,6 @@ module.exports.run = function(options, optResolvedTarget) {
169169
});
170170
};
171171

172-
// Called by plugman after installing plugins, and by create script after creating project.
173-
module.exports.prepBuildFiles = function() {
174-
return builders.getBuilder('gradle').prepBuildFiles();
175-
};
176-
177172
/*
178173
* Detects the architecture of a device/emulator
179174
* Returns "arm" or "x86".

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"apache"
1717
],
1818
"scripts": {
19-
"test": "npm run jshint && jasmine-node --color spec/create",
19+
"test": "npm run jshint && jasmine-node --color spec/unit",
2020
"test-build": "jasmine-node --captureExceptions --color spec/e2e",
2121
"jshint": "node node_modules/jshint/bin/jshint bin && node node_modules/jshint/bin/jshint spec"
2222
},
@@ -43,4 +43,4 @@
4343
"jshint": "^2.6.0",
4444
"promise-matchers": "~0"
4545
}
46-
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
21+
xmlns:android="http://schemas.android.com/apk/res/android"
22+
id="cordova-plugin-fake"
23+
version="1.0.0">
24+
25+
<name>Fake</name>
26+
27+
<description>
28+
Fake plugin to test plugin installation and properties parsing on Android.
29+
</description>
30+
31+
<license>Apache 2.0</license>
32+
33+
<engines>
34+
<!-- Requires > 3.5.0 because of the custom framework tag for Android [CB-6698] -->
35+
<engine name="cordova" version=">=3.5.0" />
36+
</engines>
37+
38+
<platform name="ios">
39+
<framework src="customFramework" custom="true" />
40+
</platform>
41+
</plugin>
File renamed without changes.

‎spec/unit/plugin.spec.js

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
'License'); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
20+
/* jshint node:true */
21+
22+
var Q = require('q');
23+
var os = require('os');
24+
var path = require('path');
25+
var common = require('cordova-common');
26+
27+
var AndroidProject = require('../../bin/templates/cordova/lib/AndroidProject');
28+
var builders = require('../../bin/templates/cordova/lib/builders/builders');
29+
30+
var PluginInfo = common.PluginInfo;
31+
32+
var FIXTURES = path.join(__dirname, '../e2e/fixtures');
33+
var FAKE_PROJECT_DIR = path.join(os.tmpdir(), 'plugin-test-project');
34+
35+
describe('addPlugin method', function () {
36+
var api, fail, gradleBuilder;
37+
38+
beforeEach(function() {
39+
var ActionStack = jasmine.createSpyObj('ActionStack', ['createAction', 'push', 'process']);
40+
ActionStack.process.andReturn(Q());
41+
spyOn(common, 'ActionStack').andReturn(ActionStack);
42+
43+
spyOn(AndroidProject, 'getProjectFile')
44+
.andReturn(jasmine.createSpyObj('AndroidProject', ['getPackageName', 'write']));
45+
46+
var Api = require('../../bin/templates/cordova/Api');
47+
api = new Api('android', FAKE_PROJECT_DIR);
48+
49+
spyOn(api, '_addModulesInfo');
50+
spyOn(api._munger, 'add_plugin_changes')
51+
.andReturn(jasmine.createSpyObj('munger', ['save_all']));
52+
53+
fail = jasmine.createSpy('fail');
54+
gradleBuilder = jasmine.createSpyObj('gradleBuilder', ['prepBuildFiles']);
55+
spyOn(builders, 'getBuilder').andReturn(gradleBuilder);
56+
});
57+
58+
it('should call gradleBuilder.prepBuildFiles for every plugin with frameworks', function(done) {
59+
api.addPlugin(new PluginInfo(path.join(FIXTURES, 'cordova-plugin-fake')))
60+
.catch(fail)
61+
.fin(function () {
62+
expect(fail).not.toHaveBeenCalled();
63+
expect(gradleBuilder.prepBuildFiles).toHaveBeenCalled();
64+
done();
65+
});
66+
});
67+
68+
it('shouldn\'t trigger gradleBuilder.prepBuildFiles for plugins without android frameworks', function(done) {
69+
api.addPlugin(new PluginInfo(path.join(FIXTURES, 'cordova-plugin-fake-ios-frameworks')))
70+
.catch(fail)
71+
.fin(function () {
72+
expect(fail).not.toHaveBeenCalled();
73+
expect(gradleBuilder.prepBuildFiles).not.toHaveBeenCalled();
74+
done();
75+
});
76+
});
77+
});

0 commit comments

Comments
 (0)
Please sign in to comment.