You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by br...@apache.org on 2019/02/13 01:11:37 UTC

[cordova-android] branch master updated: Use custom Gradle properties to read minSdkVersion value from config.xml (#655)

This is an automated email from the ASF dual-hosted git repository.

brodybits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-android.git


The following commit(s) were added to refs/heads/master by this push:
     new 867da56  Use custom Gradle properties to read minSdkVersion value from config.xml (#655)
867da56 is described below

commit 867da56e2e545f352fad43707c28edd7f50ce07e
Author: Chris Brody <ch...@gmail.com>
AuthorDate: Tue Feb 12 20:11:32 2019 -0500

    Use custom Gradle properties to read minSdkVersion value from config.xml (#655)
    
    Co-authored-by: エリス <el...@gmail.com>
    Co-authored-by: Christopher J. Brody <ch...@gmail.com>
---
 .../cordova/lib/config/GradlePropertiesParser.js   | 27 ++++++++++++++--------
 bin/templates/cordova/lib/prepare.js               |  8 ++++++-
 spec/unit/config/GradlePropertiesParser.spec.js    | 10 ++++----
 3 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/bin/templates/cordova/lib/config/GradlePropertiesParser.js b/bin/templates/cordova/lib/config/GradlePropertiesParser.js
index ac7f386..b45c0a6 100644
--- a/bin/templates/cordova/lib/config/GradlePropertiesParser.js
+++ b/bin/templates/cordova/lib/config/GradlePropertiesParser.js
@@ -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]}"`);
             }
         });
     }
diff --git a/bin/templates/cordova/lib/prepare.js b/bin/templates/cordova/lib/prepare.js
index 2eb0888..49e0a7d 100644
--- a/bin/templates/cordova/lib/prepare.js
+++ b/bin/templates/cordova/lib/prepare.js
@@ -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 () {
diff --git a/spec/unit/config/GradlePropertiesParser.spec.js b/spec/unit/config/GradlePropertiesParser.spec.js
index 91af627..4f4b9cb 100644
--- a/spec/unit/config/GradlePropertiesParser.spec.js
+++ b/spec/unit/config/GradlePropertiesParser.spec.js
@@ -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();


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