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:43 UTC

[03/13] git commit: Support loading the plugins used by each child app.

Support loading the plugins used by each child app.


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/cd3ae668
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/cd3ae668
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/cd3ae668

Branch: refs/heads/master
Commit: cd3ae668f07bcfcdcc36061c7f315ce754305af0
Parents: 21a2121
Author: Braden Shepherdson <br...@gmail.com>
Authored: Fri Nov 15 15:23:40 2013 -0500
Committer: Braden Shepherdson <br...@gmail.com>
Committed: Mon Jan 6 15:23:27 2014 -0500

----------------------------------------------------------------------
 www/cdvah/js/AppsService.js    | 22 +++++++++++-----------
 www/cdvah/js/Installer.js      | 21 +++++++++++++++++++++
 www/cdvah/js/ServeInstaller.js |  6 +++---
 www/cdvah/js/app.js            |  1 +
 www/cdvah/views/list.html      |  1 +
 5 files changed, 37 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/cd3ae668/www/cdvah/js/AppsService.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/AppsService.js b/www/cdvah/js/AppsService.js
index 65e5d49..cae0dc5 100644
--- a/www/cdvah/js/AppsService.js
+++ b/www/cdvah/js/AppsService.js
@@ -1,22 +1,22 @@
 (function() {
     "use strict";
     /* global myApp */
-    myApp.factory("AppsService", ["$q", "ResourcesLoader", "INSTALL_DIRECTORY", "APPS_JSON", function($q, ResourcesLoader, INSTALL_DIRECTORY, APPS_JSON) {
+    myApp.factory("AppsService", ["$q", "ResourcesLoader", "INSTALL_DIRECTORY", "APPS_JSON", "pluginMetadata", function($q, ResourcesLoader, INSTALL_DIRECTORY, APPS_JSON, pluginMetadata) {
 
-        var platformId = cordova.platformId;
         // Map of type -> installer.
         var _installerFactories = {};
         // Array of installer objects.
         var _installers = null;
 
         function createInstallHandlersFromJson(json) {
-            var appList = json['appList'] || [];
+            var appList = json.appList || [];
             var ret = [];
             for (var i = 0, entry; entry = appList[i]; ++i) {
-                var factory = _installerFactories[entry['appType']];
-                var installer = factory.createFromJson(entry['appUrl'], entry['appId']);
-                installer.lastUpdated = entry['lastUpdated'] && new Date(entry['lastUpdated']);
-                installer.installPath = entry['installPath'];
+                var factory = _installerFactories[entry.appType];
+                var installer = factory.createFromJson(entry.appUrl, entry.appId);
+                installer.lastUpdated = entry.lastUpdated && new Date(entry.lastUpdated);
+                installer.installPath = entry.installPath;
+                installer.plugins = entry.plugins;
                 ret.push(installer);
             }
             return ret;
@@ -49,14 +49,14 @@
             var appsJson = {
                 'appList': []
             };
-            var appList = appsJson['appList'];
             for (var i = 0, installer; installer = _installers[i]; ++i) {
-                appList.push({
+                appsJson.appList.push({
                     'appId' : installer.appId,
                     'appType' : installer.type,
                     'appUrl' : installer.url,
                     'lastUpdated': installer.lastUpdated && +installer.lastUpdated,
-                    'installPath': installer.installPath
+                    'installPath': installer.installPath,
+                    'plugins': installer.plugins
                 });
             }
 
@@ -96,7 +96,7 @@
                 return installer.deleteFiles()
                 .then(function() {
                     _installers.splice(_installers.indexOf(installer), 1);
-                    return writeAppsJson()
+                    return writeAppsJson();
                 });
             },
 

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/cd3ae668/www/cdvah/js/Installer.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/Installer.js b/www/cdvah/js/Installer.js
index d7a33da..61834e6 100644
--- a/www/cdvah/js/Installer.js
+++ b/www/cdvah/js/Installer.js
@@ -31,12 +31,30 @@
             });
         }
 
+        function getAppPlugins(cordovaPluginsFile) {
+            return ResourcesLoader.readFileContents(cordovaPluginsFile)
+            .then(function(contents) {
+                if (!contents) {
+                    throw new Error('cordova_plugins.js file is empty. Something has gone wrong with "cordova prepare".');
+                }
+
+                // Extract the JSON data from inside the JS file.
+                // It's between two magic comments created by Plugman.
+                var startIndex = contents.indexOf('TOP OF METADATA') + 16;
+                var endIndex = contents.indexOf('// BOTTOM OF METADATA');
+                var target = contents.substring(startIndex, endIndex);
+                var metadata = JSON.parse(target);
+                return metadata;
+            });
+        }
+
         function Installer(url, appId) {
             this.url = url;
             this.appId = appId || '';
             this.updatingStatus = null;
             this.lastUpdated = null;
             this.installPath = null;
+            this.plugins = {};
         }
 
         Installer.prototype.type = '';
@@ -49,8 +67,11 @@
                 self.installPath = installPath;
                 self.lastUpdated = new Date();
                 self.updatingStatus = null;
+                return getAppPlugins(installPath + '/www/cordova_plugins.js');
             }, null, function(status) {
                 self.updatingStatus = Math.round(status * 100);
+            }).then(function(metadata) {
+                self.plugins = metadata;
             });
         };
 

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/cd3ae668/www/cdvah/js/ServeInstaller.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/ServeInstaller.js b/www/cdvah/js/ServeInstaller.js
index b946da3..44fe509 100644
--- a/www/cdvah/js/ServeInstaller.js
+++ b/www/cdvah/js/ServeInstaller.js
@@ -50,7 +50,7 @@
             ResourcesLoader.xhrGet(url + '/' + platformId + '/project.json')
             .then(function(xhr) {
                 ret.projectJson = JSON.parse(xhr.responseText);
-                return ResourcesLoader.xhrGet(url + ret.projectJson['configPath']);
+                return ResourcesLoader.xhrGet(url + ret.projectJson.configPath);
             }, function(e) {
                 // If there was no :8000, try again with one appended.
                 if (!/:(\d)/.test(url)) {
@@ -68,7 +68,7 @@
                 deferred.resolve(ret);
             }, deferred.reject);
             return deferred.promise;
-        };
+        }
 
         // TODO: update should be more atomic. Maybe download to a new directory?
         ServeInstaller.prototype.doUpdateApp = function(installPath) {
@@ -134,7 +134,7 @@
                 }
                 return ResourcesLoader.ensureDirectoryExists(installPath + '/config.xml')
                 .then(function() {
-                    return ResourcesLoader.writeFileContents(installPath + '/config.xml', self._cachedConfigXml)
+                    return ResourcesLoader.writeFileContents(installPath + '/config.xml', self._cachedConfigXml);
                 })
                 .then(downloadNext);
             });

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/cd3ae668/www/cdvah/js/app.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/app.js b/www/cdvah/js/app.js
index 1a47ad3..fc0f688 100644
--- a/www/cdvah/js/app.js
+++ b/www/cdvah/js/app.js
@@ -19,6 +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);

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/cd3ae668/www/cdvah/views/list.html
----------------------------------------------------------------------
diff --git a/www/cdvah/views/list.html b/www/cdvah/views/list.html
index ca82771..5be2368 100644
--- a/www/cdvah/views/list.html
+++ b/www/cdvah/views/list.html
@@ -6,6 +6,7 @@
             <div>{{app.url}}</div>
             <div ng-show="app.updatingStatus === null">Last updated: {{app.lastUpdated || 'never'}}</div>
             <div ng-show="app.updatingStatus !== null">Update in progress: {{app.updatingStatus}}%</div>
+            <div>{{ app.plugins }}</div>
             <button ng-click="launchApp(app)">Launch</button>
             <button ng-click="updateApp(app)">Update</button>
             <button ng-click="removeApp(app)">Remove</button>