You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2014/05/21 19:19:51 UTC
[1/2] git commit: Fix corner-case in harness-push & add missing usage
examples
Repository: cordova-app-harness
Updated Branches:
refs/heads/master 4a366039f -> a2ae35550
Fix corner-case in harness-push & add missing usage examples
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/3a815ad3
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/3a815ad3
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/3a815ad3
Branch: refs/heads/master
Commit: 3a815ad33c2f61e997b531656243dc6ac62faa2f
Parents: 4a36603
Author: Andrew Grieve <ag...@chromium.org>
Authored: Wed May 21 13:18:22 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed May 21 13:18:22 2014 -0400
----------------------------------------------------------------------
harness-push/harness-push.js | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/3a815ad3/harness-push/harness-push.js
----------------------------------------------------------------------
diff --git a/harness-push/harness-push.js b/harness-push/harness-push.js
index 07e6ff1..83f3367 100755
--- a/harness-push/harness-push.js
+++ b/harness-push/harness-push.js
@@ -76,7 +76,6 @@ function discoverAppId(dir) {
return appId;
}
-// Takes a Node-style callback: function(err).
exports.push = function(target, dir, pretend) {
var appId = discoverAppId(dir);
var appType = 'cordova';
@@ -85,7 +84,6 @@ exports.push = function(target, dir, pretend) {
.then(function(result) {
var derivedWwwDir = getDerivedWwwDir(dir, result.body['platform']);
var derivedConfigXmlPath = getDerivedConfigXmlPath(dir, result.body['platform']);
- console.log(derivedConfigXmlPath);
var cordovaPluginsPath = path.join(derivedWwwDir, 'cordova_plugins.js');
if (!fs.existsSync(cordovaPluginsPath)) {
throw new Error('Could not find: ' + cordovaPluginsPath);
@@ -131,7 +129,7 @@ function buildAssetManifest(dir, configXmlPath) {
var ret = Object.create(null);
for (var i = 0; i < fileList.length; ++i) {
// TODO: convert windows slash to unix slash here.
- var appPath = 'www' + fileList[i].slice(dir.length);
+ var appPath = 'www/' + fileList[i].slice(dir == '.' ? 0 : dir.length + 1);
ret[appPath] = {
path: appPath,
realPath: fileList[i],
@@ -360,11 +358,14 @@ function parseArgs(argv) {
}
function usage() {
- console.log('Usage: harness-push push path/to/chrome_app --target=IP_ADDRESS:PORT');
+ console.log('Usage: harness-push push path/to/app --target=IP_ADDRESS:PORT');
console.log('Usage: harness-push menu');
console.log('Usage: harness-push eval "alert(1)"');
console.log('Usage: harness-push info');
console.log('Usage: harness-push launch [appId]');
+ console.log('Usage: harness-push assetmanifest [appId]');
+ console.log('Usage: harness-push delete appId');
+ console.log('Usage: harness-push deleteall');
console.log();
console.log('--target defaults to localhost:2424');
console.log('To deploy to Android over USB, use: adb forward tcp:2424 tcp:2424');
[2/2] git commit: Split Installer into Installer + CordovaInstaller.
Posted by ag...@apache.org.
Split Installer into Installer + CordovaInstaller.
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/a2ae3555
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/a2ae3555
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/a2ae3555
Branch: refs/heads/master
Commit: a2ae35550037eba9d6096580e369062bee99c5be
Parents: 3a815ad
Author: Andrew Grieve <ag...@chromium.org>
Authored: Wed May 21 13:19:25 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed May 21 13:19:25 2014 -0400
----------------------------------------------------------------------
www/cdvah/harnessmenu.html | 1 +
www/cdvah/js/AppsService.js | 6 ++-
www/cdvah/js/CordovaInstaller.js | 75 ++++++++++++++++++++++++++++
www/cdvah/js/DirectoryManager.js | 7 +++
www/cdvah/js/HarnessServer.js | 15 +-----
www/cdvah/js/Installer.js | 93 ++++++++++++++---------------------
6 files changed, 126 insertions(+), 71 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/a2ae3555/www/cdvah/harnessmenu.html
----------------------------------------------------------------------
diff --git a/www/cdvah/harnessmenu.html b/www/cdvah/harnessmenu.html
index 89f5432..4636d26 100644
--- a/www/cdvah/harnessmenu.html
+++ b/www/cdvah/harnessmenu.html
@@ -27,6 +27,7 @@
<script type="text/javascript" src="js/CacheClear.js"></script>
<script type="text/javascript" src="js/AppHarnessUI.js"></script>
<script type="text/javascript" src="js/Installer.js"></script>
+ <script type="text/javascript" src="js/CordovaInstaller.js"></script>
<script type="text/javascript" src="js/ResourcesLoader.js"></script>
<script type="text/javascript" src="js/DirectoryManager.js"></script>
<script type="text/javascript" src="js/AppsService.js"></script>
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/a2ae3555/www/cdvah/js/AppsService.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/AppsService.js b/www/cdvah/js/AppsService.js
index 98b920a..aac7856 100644
--- a/www/cdvah/js/AppsService.js
+++ b/www/cdvah/js/AppsService.js
@@ -58,7 +58,8 @@
if (!entry) {
return;
}
- return _installerFactories[entry['appType']].createFromJson(entry)
+ var Ctor = _installerFactories[entry['appType']];
+ return new Ctor().initFromJson(entry)
.then(function(app) {
_installers.push(app);
return next();
@@ -163,7 +164,8 @@
addApp : function(appType, /* optional */ appId) {
var installPath = INSTALL_DIRECTORY + 'app' + new Date().getTime() + '/';
return initHandlers().then(function() {
- return _installerFactories[appType].createNew(installPath, appId);
+ var Ctor = _installerFactories[appType];
+ return new Ctor().init(installPath, appId);
}).then(function(installer) {
_installers.push(installer);
return writeAppsJson()
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/a2ae3555/www/cdvah/js/CordovaInstaller.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/CordovaInstaller.js b/www/cdvah/js/CordovaInstaller.js
new file mode 100644
index 0000000..d6a8dda
--- /dev/null
+++ b/www/cdvah/js/CordovaInstaller.js
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+(function(){
+ 'use strict';
+
+ /* global myApp */
+ myApp.factory('CordovaInstaller', ['$q', 'Installer', 'ResourcesLoader', 'PluginMetadata', function($q, Installer, ResourcesLoader, PluginMetadata) {
+
+ function CordovaInstaller() {}
+ CordovaInstaller.prototype = Object.create(Installer.prototype);
+ CordovaInstaller.prototype.constructor = CordovaInstaller;
+ CordovaInstaller.type = 'cordova';
+
+ CordovaInstaller.prototype.initFromJson = function(json) {
+ var self = this;
+ return Installer.prototype.initFromJson.call(this, json)
+ .then(function() {
+ return self.readCordovaPluginsFile();
+ }).then(function() {
+ return self;
+ }, function(e) {
+ console.warn('Deleting broken app: ' + json['installPath']);
+ ResourcesLoader.delete(json['installPath']);
+ throw e;
+ });
+ };
+
+ CordovaInstaller.prototype.onFileAdded = function(path, etag) {
+ var self = this;
+ return $q.when(Installer.prototype.onFileAdded.call(this, path, etag))
+ .then(function() {
+ if (path == 'orig-cordova_plugins.js') {
+ return self.readCordovaPluginsFile();
+ }
+ });
+ };
+
+ CordovaInstaller.prototype.getPluginMetadata = function() {
+ return ResourcesLoader.readFileContents(this.directoryManager.rootURL + 'orig-cordova_plugins.js')
+ .then(function(contents) {
+ return PluginMetadata.extractPluginMetadata(contents);
+ });
+ };
+
+ CordovaInstaller.prototype.readCordovaPluginsFile = function() {
+ var self = this;
+ return this.directoryManager.getAssetManifest()
+ .then(function(assetManifest) {
+ return self.updateCordovaPluginsFile(assetManifest['orig-cordova_plugins.js']);
+ });
+ };
+
+ return CordovaInstaller;
+ }]);
+
+ myApp.run(['CordovaInstaller', 'AppsService', function(CordovaInstaller, AppsService) {
+ AppsService.registerInstallerFactory(CordovaInstaller);
+ }]);
+})();
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/a2ae3555/www/cdvah/js/DirectoryManager.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/DirectoryManager.js b/www/cdvah/js/DirectoryManager.js
index 2a85612..86d7543 100644
--- a/www/cdvah/js/DirectoryManager.js
+++ b/www/cdvah/js/DirectoryManager.js
@@ -25,6 +25,7 @@
function DirectoryManager(rootURL) {
this.rootURL = rootURL;
this.lastUpdated = null;
+ this.onFileAdded = null;
this._assetManifest = null;
this._flushTimerId = null;
}
@@ -71,6 +72,9 @@
.then(function() {
self._assetManifest[relativePath] = etag;
self._lazyWriteAssetManifest();
+ if (self.onFileAdded) {
+ return self.onFileAdded(relativePath, etag);
+ }
});
};
@@ -80,6 +84,9 @@
.then(function() {
self._assetManifest[relativePath] = etag;
self._lazyWriteAssetManifest();
+ if (self.onFileAdded) {
+ return self.onFileAdded(relativePath, etag);
+ }
});
};
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/a2ae3555/www/cdvah/js/HarnessServer.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/HarnessServer.js b/www/cdvah/js/HarnessServer.js
index 51a5c59..6812fdb 100644
--- a/www/cdvah/js/HarnessServer.js
+++ b/www/cdvah/js/HarnessServer.js
@@ -220,23 +220,10 @@
function importFile(fileUrl, destPath, app, etag) {
console.log('Adding file: ' + destPath);
- var ret = $q.when();
if (destPath == 'www/cordova_plugins.js') {
destPath = 'orig-cordova_plugins.js';
}
- ret = ret.then(function() {
- return app.directoryManager.addFile(fileUrl, destPath, etag);
- });
- if (destPath == 'config.xml') {
- ret = ret.then(function() {
- return app.readConfigXml();
- });
- } else if (destPath == 'orig-cordova_plugins.js') {
- ret = ret.then(function() {
- return app.readCordovaPluginsFile();
- });
- }
- return ret;
+ return app.directoryManager.addFile(fileUrl, destPath, etag);
}
function handleZipPush(req, resp) {
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/a2ae3555/www/cdvah/js/Installer.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/Installer.js b/www/cdvah/js/Installer.js
index 434fc85..69bccf6 100644
--- a/www/cdvah/js/Installer.js
+++ b/www/cdvah/js/Installer.js
@@ -23,22 +23,20 @@
myApp.factory('Installer', ['$q', 'UrlRemap', 'ResourcesLoader', 'PluginMetadata', 'CacheClear', 'DirectoryManager', function($q, UrlRemap, ResourcesLoader, PluginMetadata, CacheClear, DirectoryManager) {
var platformId = cordova.require('cordova/platform').id;
- function Installer(installPath) {
- this.updatingStatus = null;
- this.lastUpdated = null;
+ function Installer() {}
+
+ Installer.prototype.init = function(installPath, /* optional */ appId) {
+ var ret = this;
+ ret.appType = ret.constructor.type;
+ ret.updatingStatus = null;
+ ret.lastUpdated = null;
// Asset manifest is a cache of what files have been downloaded along with their etags.
- this.directoryManager = new DirectoryManager(installPath);
- this.appId = null; // Read from config.xml
- this.appName = null; // Read from config.xml
- this.startPage = null; // Read from config.xml
- this.plugins = {}; // Read from orig-cordova_plugins.js
- }
-
- Installer.type = 'cordova';
- Installer.prototype.type = 'cordova';
-
- Installer.createNew = function(installPath, /* optional */ appId) {
- var ret = new Installer(installPath);
+ ret.directoryManager = new DirectoryManager(installPath);
+ ret.directoryManager.onFileAdded = this.onFileAdded.bind(this);
+ ret.appId = null; // Read from config.xml
+ ret.appName = null; // Read from config.xml
+ ret.startPage = null; // Read from config.xml
+ ret.plugins = {}; // Read from orig-cordova_plugins.js
ret.appId = appId;
return ret.directoryManager.getAssetManifest()
.then(function() {
@@ -46,50 +44,24 @@
});
};
- Installer.createFromJson = function(json) {
- var ret = new Installer(json['installPath']);
- ret.lastUpdated = json['lastUpdated'] && new Date(json['lastUpdated']);
- ret.appId = json['appId'];
- return ret.directoryManager.getAssetManifest()
- .then(function() {
- return ret.readCordovaPluginsFile();
- }).then(function() {
- return ret.readConfigXml();
- }).then(function() {
- return ret;
- }, function(e) {
- console.warn('Deleting broken app: ' + json['installPath']);
- ResourcesLoader.delete(json['installPath']);
- throw e;
+ Installer.prototype.initFromJson = function(json) {
+ var self = this;
+ return this.init(json['installPath'], json['appId'])
+ .then(function(ret) {
+ ret.lastUpdated = json['lastUpdated'] && new Date(json['lastUpdated']);
+ return self.readConfigXml();
});
};
Installer.prototype.toDiskJson = function() {
return {
- 'appType' : this.type,
+ 'appType' : this.appType,
'appId' : this.appId,
'lastUpdated': this.lastUpdated && +this.lastUpdated,
'installPath': this.directoryManager.rootURL
};
};
- Installer.prototype.readCordovaPluginsFile = function(force) {
- var self = this;
- return this.directoryManager.getAssetManifest()
- .then(function(assetManifest) {
- if (!force && assetManifest['orig-cordova_plugins.js'] == assetManifest['www/cordova_plugins.js']) {
- return null;
- }
- return self.getPluginMetadata()
- .then(function(metadata) {
- self.plugins = PluginMetadata.process(metadata);
- var pluginIds = Object.keys(metadata);
- var newPluginsFileData = PluginMetadata.createNewPluginListFile(pluginIds);
- return self.directoryManager.writeFile(newPluginsFileData, 'www/cordova_plugins.js', assetManifest['orig-cordova_plugins.js']);
- });
- });
- };
-
Installer.prototype.readConfigXml = function() {
var self = this;
return ResourcesLoader.readFileContents(this.directoryManager.rootURL + 'config.xml')
@@ -106,13 +78,27 @@
});
};
- Installer.prototype.getPluginMetadata = function() {
- return ResourcesLoader.readFileContents(this.directoryManager.rootURL + 'orig-cordova_plugins.js')
- .then(function(contents) {
- return PluginMetadata.extractPluginMetadata(contents);
+ Installer.prototype.updateCordovaPluginsFile = function(etag) {
+ var self = this;
+ return self.getPluginMetadata()
+ .then(function(metadata) {
+ self.plugins = PluginMetadata.process(metadata);
+ var pluginIds = Object.keys(metadata);
+ var newPluginsFileData = PluginMetadata.createNewPluginListFile(pluginIds);
+ return self.directoryManager.writeFile(newPluginsFileData, 'www/cordova_plugins.js', etag);
});
};
+ Installer.prototype.onFileAdded = function(path) {
+ if (path == 'config.xml') {
+ return this.readConfigXml();
+ }
+ };
+
+ Installer.prototype.getPluginMetadata = function() {
+ throw new Error('unimplemented.');
+ };
+
Installer.prototype.deleteFiles = function() {
this.lastUpdated = null;
return this.directoryManager.deleteAll();
@@ -167,8 +153,5 @@
return Installer;
}]);
- myApp.run(['Installer', 'AppsService', function(Installer, AppsService) {
- AppsService.registerInstallerFactory(Installer);
- }]);
})();