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 2013/12/06 02:13:40 UTC

[24/32] git commit: add ubuntu platform

add ubuntu platform


Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/7968ae7f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/7968ae7f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/7968ae7f

Branch: refs/heads/fireos
Commit: 7968ae7f9ccc593b7e53bb55da6954a3594a761f
Parents: 6e1d79e
Author: Maxim Ermilov <ma...@canonical.com>
Authored: Wed Nov 27 19:47:24 2013 +0400
Committer: Steven Gill <st...@gmail.com>
Committed: Thu Dec 5 15:39:51 2013 -0800

----------------------------------------------------------------------
 platforms.js                  |   5 ++
 src/lazy_load.js              |   2 +
 src/metadata/ubuntu_parser.js | 177 +++++++++++++++++++++++++++++++++++++
 src/platform.js               |   2 +
 4 files changed, 186 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/7968ae7f/platforms.js
----------------------------------------------------------------------
diff --git a/platforms.js b/platforms.js
index 370d056..d26bf75 100644
--- a/platforms.js
+++ b/platforms.js
@@ -28,6 +28,11 @@ module.exports = {
         url    : 'https://git-wip-us.apache.org/repos/asf?p=cordova-android.git',
         version: '3.2.0'
     }, 
+    'ubuntu' : {
+        parser : './src/metadata/ubuntu_parser',
+        url    : 'https://launchpad.net/cordova-ubuntu/3.0/apha1/+download/campo.tar.gz',
+        version: '3.1.0-rc1'
+    }, 
     'wp7' : {
         parser : './src/metadata/wp7_parser',
         url    : 'https://git-wip-us.apache.org/repos/asf?p=cordova-wp8.git',

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/7968ae7f/src/lazy_load.js
----------------------------------------------------------------------
diff --git a/src/lazy_load.js b/src/lazy_load.js
index dcaa126..fd95031 100644
--- a/src/lazy_load.js
+++ b/src/lazy_load.js
@@ -40,6 +40,8 @@ module.exports = {
         }
 
         var url = platforms[platform].url + ';a=snapshot;h=' + platforms[platform].version + ';sf=tgz';
+        if (platform == 'ubuntu')
+            url = platforms[platform].url;
         return module.exports.custom(url, 'cordova', platform, platforms[platform].version);
     },
     // Returns a promise for the path to the lazy-loaded directory.

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/7968ae7f/src/metadata/ubuntu_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/ubuntu_parser.js b/src/metadata/ubuntu_parser.js
new file mode 100644
index 0000000..1809ecf
--- /dev/null
+++ b/src/metadata/ubuntu_parser.js
@@ -0,0 +1,177 @@
+/*
+ *
+ * Copyright 2013 Canonical Ltd.
+ *
+ * Licensed 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.
+ *
+*/
+
+var fs            = require('fs'),
+    path          = require('path'),
+    et            = require('elementtree'),
+    xml           = require('../xml-helpers'),
+    util          = require('../util'),
+    events        = require('../events'),
+    shell         = require('shelljs'),
+    project_config= require('../config'),
+    Q             = require('q'),
+    os             = require('os'),
+    config_parser = require('../config_parser');
+
+module.exports = function(project) {
+    this.path = project;
+    this.config = new util.config_parser(this.config_xml());
+    this.update_manifest();
+};
+
+function sanitize(str) {
+    return str.replace(/\n/g, ' ').replace(/^\s+|\s+$/g, '');
+}
+
+// Returns a promise.
+module.exports.check_requirements = function(project_root, callback) {
+    var d = Q.defer();
+
+    events.emit('log', 'Checking ubuntu requirements...');
+    command = "dpkg-query -Wf'${db:Status-abbrev}' cmake debhelper libx11-dev libicu-dev pkg-config qtbase5-dev qtchooser qtdeclarative5-dev qtfeedback5-dev qtlocation5-dev qtmultimedia5-dev qtpim5-dev qtsensors5-dev qtsystems5-dev 2>/dev/null | grep -q '^i'";
+    events.emit('log', 'Running "' + command + '" (output to follow)');
+    shell.exec(command, {silent:true, async:true}, function(code, output) {
+        events.emit('log', output);
+        if (code != 0) {
+            d.reject(new Error('Make sure you have the following packages installed: ' + output));
+        } else {
+            d.resolve();
+        }
+    });
+
+    return d.promise;
+};
+
+module.exports.prototype = {
+    // Returns a promise.
+    update_from_config:function(config) {
+        if (config instanceof config_parser) {
+        } else {
+            return Q.reject(new Error('update_from_config requires a config_parser object'));
+        }
+
+        this.config = new util.config_parser(this.config_xml());
+        this.config.name(config.name());
+        this.config.version(config.version());
+        this.config.packageName(config.packageName());
+
+        this.config.doc.find('description').text = config.doc.find('description').text;
+        this.config.update();
+
+        return this.update_manifest();
+    },
+
+    cordovajs_path:function(libDir) {
+        var jsPath = path.join(libDir, 'www', 'cordova.js');
+        return path.resolve(jsPath);
+    },
+
+    update_manifest: function() {
+        var nodearch2debarch = { 'arm': 'armhf',
+                                 'i386': 'i386',
+                                 'x64': 'amd64'};
+        var arch;
+        if (os.arch() in nodearch2debarch)
+            arch = nodearch2debarch[os.arch()];
+        else
+            return Q.reject(new Error('unknown cpu arch'));
+
+        if (!this.config.doc.find('author') || !this.config.doc.find('author').text.length)
+            return Q.reject(new Error('config.xml should contain author'));
+
+        var manifest = { name: this.config.packageName(),
+                         version: this.config.version(),
+                         title: this.config.name(),
+                         hooks: { cordova: { desktop: "cordova.desktop",
+                                             apparmor: "apparmor.json" } },
+                         framework: "ubuntu-sdk-13.10",
+                         maintainer: sanitize(this.config.doc.find('author').text),
+                         architecture: arch,
+                         description: sanitize(this.config.doc.find('description').text) };
+        fs.writeFileSync(path.join(this.path, 'manifest.json'), JSON.stringify(manifest));
+
+        var name = this.config.name().replace(/\n/g, ' '); //FIXME: escaping
+        var content = "[Desktop Entry]\nName=" + name + "\nExec=./cordova-ubuntu www/\nIcon=qmlscene\nTerminal=false\nType=Application\nX-Ubuntu-Touch=true";
+
+        fs.writeFileSync(path.join(this.path, 'cordova.desktop'), content);
+
+        var policy = { policy_groups: ["networking", "audio"], policy_version: 1 };
+
+        this.config.doc.getroot().findall('./feature/param').forEach(function (element) {
+            if (element.attrib.policy_group && policy.policy_groups.indexOf(policy.policy_groups) === -1)
+                policy.policy_groups.push(element.attrib.policy_group);
+        });
+
+        fs.writeFileSync(path.join(this.path, 'apparmor.json'), JSON.stringify(policy));
+
+        return Q();
+    },
+
+    config_xml:function(){
+        return path.join(this.path, 'config.xml');
+    },
+
+    www_dir:function() {
+        return path.join(this.path, 'www');
+    },
+
+    staging_dir: function() {
+        return path.join(this.path, '.staging', 'www');
+    },
+
+    update_www:function() {
+        var projectRoot = util.isCordova(this.path);
+        var www = util.projectWww(projectRoot);
+
+        shell.rm('-rf', this.www_dir());
+        shell.cp('-rf', www, this.path);
+    },
+
+    update_overrides:function() {
+        var projectRoot = util.isCordova(this.path);
+        var mergesPath = path.join(util.appDir(projectRoot), 'merges', 'ubuntu');
+        if(fs.existsSync(mergesPath)) {
+            var overrides = path.join(mergesPath, '*');
+            shell.cp('-rf', overrides, this.www_dir());
+        }
+    },
+
+    update_staging:function() {
+        var projectRoot = util.isCordova(this.path);
+        var stagingDir = path.join(this.path, '.staging', 'www');
+
+        if(fs.existsSync(stagingDir)) {
+            shell.cp('-rf',
+                     path.join(stagingDir, '*'),
+                     this.www_dir());
+        }
+    },
+
+    // Returns a promise.
+    update_project:function(cfg) {
+        var self = this;
+
+        return this.update_from_config(cfg)
+        .then(function() {
+            self.update_overrides();
+            self.update_staging();
+            util.deleteSvnFolders(self.www_dir());
+        });
+    }
+};

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/7968ae7f/src/platform.js
----------------------------------------------------------------------
diff --git a/src/platform.js b/src/platform.js
index 536969c..730e411 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -159,6 +159,8 @@ module.exports = function platform(command, targets) {
                     available.push('wp8');
                     available.push('windows8');
                 }
+                if (os.platform() === 'linux')
+                    available.push('ubuntu');
 
                 available = available.filter(function(p) {
                     return platforms_on_fs.indexOf(p) < 0; // Only those not already installed.