CB-8978 Add resource-file parsing to config.xml
authorDarryl Pogue <darryl@ayogo.com>
Wed, 27 Jul 2016 23:28:08 +0000 (16:28 -0700)
committerSteve Gill <stevengill97@gmail.com>
Tue, 17 Jan 2017 17:59:37 +0000 (09:59 -0800)
 This closes #468

spec/ConfigParser/ConfigParser.spec.js
spec/fixtures/test-config.xml
src/ConfigParser/ConfigParser.js

index 240db17..f3e334d 100644 (file)
@@ -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();
+            });
+        });
     });
 });
index a656143..b64e785 100644 (file)
@@ -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" />
index 6e74ce3..e477a89 100644 (file)
@@ -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).