mirror of
https://github.com/apache/cordova-android.git
synced 2025-03-06 01:51:11 +08:00
Use custom Gradle properties to read minSdkVersion value from config.xml (#655)
Co-authored-by: エリス <ellis.bryan@gmail.com> Co-authored-by: Christopher J. Brody <chris.brody@gmail.com>
This commit is contained in:
parent
719acd3ab1
commit
867da56e2e
@ -46,11 +46,17 @@ class GradlePropertiesParser {
|
||||
this.gradleFilePath = path.join(platformDir, 'gradle.properties');
|
||||
}
|
||||
|
||||
configure () {
|
||||
configure (userConfigs) {
|
||||
events.emit('verbose', '[Gradle Properties] Preparing Configuration');
|
||||
|
||||
this._initializeEditor();
|
||||
this._configureDefaults();
|
||||
|
||||
events.emit('verbose', '[Gradle Properties] Appending default configuration properties');
|
||||
this._configureProperties(this._defaults);
|
||||
|
||||
events.emit('verbose', '[Gradle Properties] Appending custom configuration properties');
|
||||
this._configureProperties(userConfigs);
|
||||
|
||||
this._save();
|
||||
}
|
||||
|
||||
@ -69,18 +75,19 @@ class GradlePropertiesParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that defaults are set and set the missing defaults.
|
||||
* Validate that defaults or user configuration properties are set and
|
||||
* set the missing items.
|
||||
*/
|
||||
_configureDefaults () {
|
||||
// Loop though Cordova default properties and set only if missing.
|
||||
Object.keys(this._defaults).forEach(key => {
|
||||
_configureProperties (properties) {
|
||||
// Iterate though the properties and set only if missing.
|
||||
Object.keys(properties).forEach(key => {
|
||||
let value = this.gradleFile.get(key);
|
||||
|
||||
if (!value) {
|
||||
events.emit('verbose', `[Gradle Properties] Appended missing default: ${key}=${this._defaults[key]}`);
|
||||
this.gradleFile.set(key, this._defaults[key]);
|
||||
} else if (value !== this._defaults[key]) {
|
||||
events.emit('info', `[Gradle Properties] Detected Gradle property "${key}" with the value of "${value}", Cordova's recommended value is "${this._defaults[key]}"`);
|
||||
events.emit('verbose', `[Gradle Properties] Appending configuration item: ${key}=${properties[key]}`);
|
||||
this.gradleFile.set(key, properties[key]);
|
||||
} else if (value !== properties[key]) {
|
||||
events.emit('info', `[Gradle Properties] Detected Gradle property "${key}" with the value of "${value}", Cordova's recommended value is "${properties[key]}"`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
8
bin/templates/cordova/lib/prepare.js
vendored
8
bin/templates/cordova/lib/prepare.js
vendored
@ -43,8 +43,14 @@ module.exports.prepare = function (cordovaProject, options) {
|
||||
|
||||
this._config = updateConfigFilesFrom(cordovaProject.projectConfig, munger, this.locations);
|
||||
|
||||
// Get the min SDK version from config.xml
|
||||
const minSdkVersion = this._config.getPreference('android-minSdkVersion', 'android');
|
||||
|
||||
let gradlePropertiesUserConfig = {};
|
||||
if (minSdkVersion) gradlePropertiesUserConfig.cdvMinSdkVersion = minSdkVersion;
|
||||
|
||||
let gradlePropertiesParser = new GradlePropertiesParser(this.locations.root);
|
||||
gradlePropertiesParser.configure();
|
||||
gradlePropertiesParser.configure(gradlePropertiesUserConfig);
|
||||
|
||||
// Update own www dir with project's www assets and plugins' assets and js-files
|
||||
return Q.when(updateWww(cordovaProject, this.locations)).then(function () {
|
||||
|
@ -74,7 +74,7 @@ describe('Gradle Builder', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('_configureDefaults method', () => {
|
||||
describe('_configureProperties method', () => {
|
||||
let parser;
|
||||
let emitSpy;
|
||||
|
||||
@ -99,11 +99,11 @@ describe('Gradle Builder', () => {
|
||||
get: getSpy
|
||||
};
|
||||
|
||||
parser._configureDefaults();
|
||||
parser._configureProperties(parser._defaults);
|
||||
|
||||
expect(getSpy).toHaveBeenCalled();
|
||||
expect(setSpy).toHaveBeenCalled();
|
||||
expect(emitSpy.calls.argsFor(0)[1]).toContain('Appended missing default');
|
||||
expect(emitSpy.calls.argsFor(0)[1]).toContain('Appending configuration item');
|
||||
});
|
||||
|
||||
it('should not detect missing defaults and not call set.', () => {
|
||||
@ -115,7 +115,7 @@ describe('Gradle Builder', () => {
|
||||
get: getSpy
|
||||
};
|
||||
|
||||
parser._configureDefaults();
|
||||
parser._configureProperties(parser._defaults);
|
||||
|
||||
expect(getSpy).toHaveBeenCalled();
|
||||
expect(setSpy).not.toHaveBeenCalled();
|
||||
@ -130,7 +130,7 @@ describe('Gradle Builder', () => {
|
||||
get: getSpy
|
||||
};
|
||||
|
||||
parser._configureDefaults();
|
||||
parser._configureProperties(parser._defaults);
|
||||
|
||||
expect(getSpy).toHaveBeenCalled();
|
||||
expect(setSpy).not.toHaveBeenCalled();
|
||||
|
Loading…
x
Reference in New Issue
Block a user