mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-25 19:32:54 +08:00
CB-10618 Handle gradle frameworks on plugin installation/uninstallation
This closes #259
This commit is contained in:
parent
7233931681
commit
7be9e880c2
@ -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) {
|
||||
|
10
bin/templates/cordova/Api.js
vendored
10
bin/templates/cordova/Api.js
vendored
@ -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;
|
||||
|
5
bin/templates/cordova/lib/build.js
vendored
5
bin/templates/cordova/lib/build.js
vendored
@ -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".
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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>
|
77
spec/unit/plugin.spec.js
Normal file
77
spec/unit/plugin.spec.js
Normal file
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user