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 2014/01/06 21:25:46 UTC

[06/13] git commit: Creating the new PluginMetadata service.

Creating the new PluginMetadata service.


Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/3188903a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/3188903a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/3188903a

Branch: refs/heads/master
Commit: 3188903afdae02cdbfce884051a1183122ab3e13
Parents: 33d8fe2
Author: Braden Shepherdson <br...@gmail.com>
Authored: Mon Dec 2 10:49:57 2013 -0800
Committer: Braden Shepherdson <br...@gmail.com>
Committed: Mon Jan 6 15:24:12 2014 -0500

----------------------------------------------------------------------
 www/cdvah/js/AppsService.js    |  2 +-
 www/cdvah/js/PluginMetadata.js | 53 +++++++++++++++++++++++++++++++++++++
 www/cdvah/js/app.js            |  2 +-
 3 files changed, 55 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/3188903a/www/cdvah/js/AppsService.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/AppsService.js b/www/cdvah/js/AppsService.js
index dc04dcb..d86af42 100644
--- a/www/cdvah/js/AppsService.js
+++ b/www/cdvah/js/AppsService.js
@@ -17,7 +17,7 @@
                 var installer = factory.createFromJson(entry.appUrl, entry.appId);
                 installer.lastUpdated = entry.lastUpdated && new Date(entry.lastUpdated);
                 installer.installPath = entry.installPath;
-                installer.plugins = entry.plugins;
+                installer.plugins = pluginMetadata.process(entry.plugins);
                 ret.push(installer);
             }
             return ret;

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/3188903a/www/cdvah/js/PluginMetadata.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/PluginMetadata.js b/www/cdvah/js/PluginMetadata.js
new file mode 100644
index 0000000..544c49a
--- /dev/null
+++ b/www/cdvah/js/PluginMetadata.js
@@ -0,0 +1,53 @@
+(function() {
+    'use strict';
+    /* global myApp */
+    myApp.factory('pluginMetadata', function() {
+        var harnessPlugins = cordova.require('cordova/plugin_list').metadata;
+
+        // Returns -1, (a > b), 0 (a = b), or 1 (a < b).
+        function semverCompare(a, b) {
+            var regex = /^(\d+)\.(\d+)\.(\d+)/;
+            var aComps = a.match(regex);
+            var bComps = b.match(regex);
+
+            for(var i = 1; i <= 3; i++) {
+                if (+aComps[i] != +bComps[i]) {
+                    return +aComps[i] < +bComps[i] ? 1 : -1;
+                }
+            }
+
+            return 0;
+        }
+
+        return {
+            // Returns an object with plugin matching data.
+            process: function(childPlugins) {
+                var results = {
+                    matched: [],
+                    missing: [],
+                    newer: [], // Those dependencies which are newer in the child than the harness.
+                    older: []  // And those which are older in the child than the harness.
+                };
+
+                Object.keys(childPlugins).forEach(function(plugin) {
+                    if (!harnessPlugins[plugin]) {
+                        results.missing.push({ id: plugin, version: childPlugins[plugin] });
+                    } else {
+                        switch(semverCompare(harnessPlugins[plugin], childPlugins[plugin])) {
+                            case -1: // Child older.
+                                results.older.push({ id: plugin, versions: { harness: harnessPlugins[plugin], child: childPlugins[plugin] } });
+                                break;
+                            case 1: // Child newer.
+                                results.newer.push({ id: plugin, versions: { harness: harnessPlugins[plugin], child: childPlugins[plugin] } });
+                                break;
+                            case 0: // Match!
+                                results.matched.push({ id: plugin, version: harnessPlugins[plugin] });
+                                break;
+                        }
+                    }
+                });
+            }
+        };
+    });
+})();
+

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/3188903a/www/cdvah/js/app.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/app.js b/www/cdvah/js/app.js
index e1d8cdc..48e7dec 100644
--- a/www/cdvah/js/app.js
+++ b/www/cdvah/js/app.js
@@ -19,7 +19,7 @@ document.addEventListener('deviceready', function() {
         var path = dirEntry.fullPath;
         myApp.value('INSTALL_DIRECTORY', path + '/apps');
         myApp.value('APPS_JSON', path + '/apps.json');
-        myApp.value('pluginMetadata', cordova.require('cordova/plugin_list').metadata);
+
         angular.bootstrap(document, ['CordovaAppHarness']);
     });
 }, false);