You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2017/01/17 18:01:19 UTC

cordova-lib git commit: CB-8978 Add resource-file parsing to config.xml

Repository: cordova-lib
Updated Branches:
  refs/heads/master e4b920ff2 -> 2bf351704


CB-8978 Add resource-file parsing to config.xml

 This closes #468


Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/2bf35170
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/2bf35170
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/2bf35170

Branch: refs/heads/master
Commit: 2bf351704f6a1145fa0372348a124137a9f2a287
Parents: e4b920f
Author: Darryl Pogue <da...@ayogo.com>
Authored: Wed Jul 27 16:28:08 2016 -0700
Committer: Steve Gill <st...@gmail.com>
Committed: Tue Jan 17 09:59:37 2017 -0800

----------------------------------------------------------------------
 .../spec/ConfigParser/ConfigParser.spec.js      | 16 +++++++++++++
 cordova-common/spec/fixtures/test-config.xml    |  3 +++
 cordova-common/src/ConfigParser/ConfigParser.js | 24 ++++++++++++++++++++
 3 files changed, 43 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/2bf35170/cordova-common/spec/ConfigParser/ConfigParser.spec.js
----------------------------------------------------------------------
diff --git a/cordova-common/spec/ConfigParser/ConfigParser.spec.js b/cordova-common/spec/ConfigParser/ConfigParser.spec.js
index 240db17..f3e334d 100644
--- a/cordova-common/spec/ConfigParser/ConfigParser.spec.js
+++ b/cordova-common/spec/ConfigParser/ConfigParser.spec.js
@@ -281,5 +281,21 @@ describe('config.xml parser', function () {
                 expect(cfg.getStaticResources('android', 'icon').getByDensity('mdpi').src).toBe('logo-android.png');
             });
         });
+
+        describe('file resources', function() {
+            var hasSrcPropertyDefined = function (e) { return !!e.src; };
+            var hasTargetPropertyDefined = function (e) { return !!e.target; };
+            var hasArchPropertyDefined = function (e) { return !!e.arch; };
+
+            it('should fetch platform-specific resources', function() {
+                expect(cfg.getFileResources('android').length).toBe(2);
+            });
+
+            it('should parse resources\' attributes', function() {
+                expect(cfg.getFileResources('android').every(hasSrcPropertyDefined)).toBeTruthy();
+                expect(cfg.getFileResources('android').every(hasTargetPropertyDefined)).toBeTruthy();
+                expect(cfg.getFileResources('windows').every(hasArchPropertyDefined)).toBeTruthy();
+            });
+        });
     });
 });

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/2bf35170/cordova-common/spec/fixtures/test-config.xml
----------------------------------------------------------------------
diff --git a/cordova-common/spec/fixtures/test-config.xml b/cordova-common/spec/fixtures/test-config.xml
index a656143..b64e785 100644
--- a/cordova-common/spec/fixtures/test-config.xml
+++ b/cordova-common/spec/fixtures/test-config.xml
@@ -86,6 +86,8 @@
         <icon density="mdpi" height="255" src="logo-android.png" width="255" />
         <icon gap:density="mdpi" height="255" src="logo-android-gap.png" width="255" />
         <icon cdv:density="mdpi" height="255" src="logo-android-cdv.png" width="255" />
+        <resource-file src="appconfig.json" target="appconfig.json" />
+        <resource-file src="androidconfig.json" target="androidconfig.json" />
         <preference name="android-minSdkVersion" value="10" />
         <preference name="orientation" value="landscape" />
     </platform>
@@ -93,6 +95,7 @@
         <icon src="res/windows/logo.scale-200.png" target="logo.png"/>
         <icon src="res/windows/logo-small.scale-400.png" width="72" target="logo.png"/>
         <icon src="res/windows/logo-small.scale-400_48.png" height="48" target="logo.png"/>
+        <resource-file src="windowsconfig.json" target="windowsconfig.json" arch="x86" device-target="all" />
     </platform>
     <plugin name="org.apache.cordova.pluginwithvars">
         <variable name="var" value="varvalue" />

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/2bf35170/cordova-common/src/ConfigParser/ConfigParser.js
----------------------------------------------------------------------
diff --git a/cordova-common/src/ConfigParser/ConfigParser.js b/cordova-common/src/ConfigParser/ConfigParser.js
index 6e74ce3..e477a89 100644
--- a/cordova-common/src/ConfigParser/ConfigParser.js
+++ b/cordova-common/src/ConfigParser/ConfigParser.js
@@ -257,6 +257,30 @@ ConfigParser.prototype = {
     },
 
     /**
+     * Returns all resource-files for a specific platform.
+     * @param  {string} platform Platform name
+     * @return {Resource[]}      Array of resource file objects.
+     */
+    getFileResources: function(platform) {
+        var fileResources = [];
+
+        if (platform) { // platform specific resources
+            fileResources = this.doc.findall('platform[@name=\'' + platform + '\']/resource-file').map(function(tag) {
+                return {
+                    platform: platform,
+                    src: tag.attrib.src,
+                    target: tag.attrib.target,
+                    versions: tag.attrib.versions,
+                    deviceTarget: tag.attrib['device-target'],
+                    arch: tag.attrib.arch
+                };
+            });
+        }
+
+        return fileResources;
+    },
+
+    /**
      * Returns all hook scripts for the hook type specified.
      * @param  {String} hook     The hook type.
      * @param {Array}  platforms Platforms to look for scripts into (root scripts will be included as well).


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