You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by za...@apache.org on 2014/12/15 14:33:23 UTC

[34/37] cordova-ubuntu git commit: move manifest generator from cordova-lib

move manifest generator from cordova-lib


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

Branch: refs/heads/master
Commit: bbcd1e3b8702f143c1c89e8c87e4e434f125a6d7
Parents: 8379592
Author: Maxim Ermilov <ma...@canonical.com>
Authored: Tue Dec 9 16:51:57 2014 +0300
Committer: Maxim Ermilov <ma...@canonical.com>
Committed: Tue Dec 9 16:51:57 2014 +0300

----------------------------------------------------------------------
 bin/templates/project/cordova/lib/build.js      |  5 ++
 .../project/cordova/lib/config_parser.js        | 65 +++++++++++++++++
 bin/templates/project/cordova/lib/manifest.js   | 74 ++++++++++++++++++++
 package.json                                    |  6 +-
 4 files changed, 148 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/bbcd1e3b/bin/templates/project/cordova/lib/build.js
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/lib/build.js b/bin/templates/project/cordova/lib/build.js
index 64c7fd4..34f3df3 100644
--- a/bin/templates/project/cordova/lib/build.js
+++ b/bin/templates/project/cordova/lib/build.js
@@ -28,6 +28,7 @@ var shell = require('shelljs');
 
 var Constants = require('./constants');
 var Utils = require('./utils');
+var Manifest = require('./manifest');
 var logger = require('./logger');
 
 var PLATFORMS = Constants.PLATFORM_TYPES;
@@ -59,6 +60,8 @@ function buildClickPackage(campoDir, ubuntuDir, nobuild, architecture, framework
 
     assert.ok(architecture && architecture.match(/^[a-z0-9_]+$/));
 
+    Manifest.generate(path.join(ubuntuDir, 'config.xml'), ubuntuDir);
+
     var archDir = path.join(ubuntuDir, framework, architecture);
     var prefixDir = path.join(archDir, 'prefix');
 
@@ -135,6 +138,8 @@ function buildNative(campoDir, ubuntuDir, nobuild, debug) {
 
     checkEnv(ubuntuDir);
 
+    Manifest.generate(path.join(ubuntuDir, 'config.xml'), ubuntuDir);
+
     shell.rm('-rf', prefixDir);
 
     shell.mkdir('-p', path.join(nativeDir, 'build'));

http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/bbcd1e3b/bin/templates/project/cordova/lib/config_parser.js
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/lib/config_parser.js b/bin/templates/project/cordova/lib/config_parser.js
new file mode 100644
index 0000000..0fc6f5f
--- /dev/null
+++ b/bin/templates/project/cordova/lib/config_parser.js
@@ -0,0 +1,65 @@
+/*
+ *
+ * Copyright 2014 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');
+var et = require('elementtree');
+
+var XML = et.XML;
+var ElementTree = et.ElementTree;
+var element = et.Element;
+var subElement = et.SubElement;
+
+function getNodeTextSafe(el) {
+    return el && el.text && el.text.trim();
+}
+
+function getNodeAttrSafe(el, attr) {
+    return el && el.attrib[attr];
+}
+
+function Config(path) {
+    var data = fs.readFileSync(path).toString();
+    this.etree = et.parse(data);
+}
+
+Config.prototype = {
+    id: function() {
+        return getNodeAttrSafe(this.etree.getroot(), 'id');
+    },
+    version: function() {
+        return getNodeAttrSafe(this.etree.getroot(), 'version');
+    },
+    name: function() {
+        return getNodeTextSafe(this.etree.find('name'));
+    },
+    author: function() {
+        return getNodeTextSafe(this.etree.find('author'));
+    },
+    email: function() {
+        return getNodeAttrSafe(this.etree.find('author'), 'email');
+    },
+    description: function() {
+        return getNodeTextSafe(this.etree.find('description'));
+    },
+    icon: function() {
+        return getNodeAttrSafe(this.etree.find('icon'), 'src');
+    }
+};
+
+module.exports = Config;

http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/bbcd1e3b/bin/templates/project/cordova/lib/manifest.js
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/lib/manifest.js b/bin/templates/project/cordova/lib/manifest.js
new file mode 100644
index 0000000..648819c
--- /dev/null
+++ b/bin/templates/project/cordova/lib/manifest.js
@@ -0,0 +1,74 @@
+/*
+ *
+ * Copyright 2014 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 ConfigParser = require('./config_parser');
+var path         = require('path');
+var fs           = require('fs');
+var logger       = require('./logger');
+
+function sanitize(str) {
+    return str.replace(/\n/g, ' ').replace(/^\s+|\s+$/g, '');
+}
+
+module.exports = {
+    generate: function(path, outDir) {
+        var config = new ConfigParser(path);
+
+        this.generateDesktopFile(config, outDir);
+        this.generateManifest(config, outDir);
+        this.generateApparmorProfile(config, outDir);
+    },
+
+    generateDesktopFile: function(config, dir) {
+        var name = sanitize(config.name()); //FIXME: escaping
+        var content = '[Desktop Entry]\nName=' + name + '\nExec=./cordova-ubuntu www/\nTerminal=false\nType=Application\nX-Ubuntu-Touch=true';
+
+        if (config.icon() && fs.existsSync(path.join(dir, 'www', config.icon()))) {
+            content += '\nIcon=www/' + config.icon();
+        } else {
+            logger.error("Missing icon");
+            process.exit(1);
+        }
+
+        fs.writeFileSync(path.join(dir, 'cordova.desktop'), content);
+    },
+
+    generateManifest: function(config, dir) {
+        var manifest = { name: config.id(),
+                         version: config.version(),
+                         title: config.name(),
+                         hooks: { cordova: { desktop: 'cordova.desktop',
+                                             apparmor: 'apparmor.json' } },
+                         maintainer: sanitize(config.author())  + ' <' + config.email() + '>',
+                         description: sanitize(config.description()) };
+
+        fs.writeFileSync(path.join(dir, 'manifest.json'), JSON.stringify(manifest));
+    },
+
+    generateApparmorProfile: function(config, dir) {
+        var policy = { policy_groups: ['networking', 'audio'], policy_version: 1 };
+
+        config.etree.getroot().findall('./feature/param').forEach(function (element) {
+            if (element.attrib.policy_group && policy.policy_groups.indexOf(element.attrib.policy_group) === -1)
+                policy.policy_groups.push(element.attrib.policy_group);
+        });
+
+        fs.writeFileSync(path.join(dir, 'apparmor.json'), JSON.stringify(policy));
+    }
+};

http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/bbcd1e3b/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 4a36966..419f115 100644
--- a/package.json
+++ b/package.json
@@ -15,13 +15,15 @@
         "colors": "0.6.2",
         "optimist": "0.6.0",
         "q": "2.0.*",
-        "shelljs": "0.2.6"
+        "shelljs": "0.2.6",
+        "elementtree": "*"
     },
     "bundledDependencies": [
         "colors",
         "optimist",
         "q",
-        "shelljs"
+        "shelljs",
+        "elementtree"
     ],
     "keywords": [
         "ubuntu",


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org