Updated Branches:
  refs/heads/master 92c392cb6 -> 210a74057

[CB-4180] fixes run tool reference error "generateBarName" not found

run, build tools and session.js references utils for bar name generation
removes utils.js from .gitignore file


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

Branch: refs/heads/master
Commit: 210a74057715aa84da70aafac3ca54fbe5857884
Parents: 92c392c
Author: lorinbeer <[email protected]>
Authored: Thu Jul 11 15:11:03 2013 -0700
Committer: lorinbeer <[email protected]>
Committed: Thu Jul 11 15:11:03 2013 -0700

----------------------------------------------------------------------
 blackberry10/.gitignore                         |   1 -
 .../bin/templates/project/cordova/lib/run       |   2 +-
 .../templates/project/cordova/lib/session.js    |   3 +-
 .../bin/templates/project/cordova/lib/utils.js  | 218 +++++++++++++++++++
 4 files changed, 221 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/210a7405/blackberry10/.gitignore
----------------------------------------------------------------------
diff --git a/blackberry10/.gitignore b/blackberry10/.gitignore
index 88eb1b3..a87ff43 100644
--- a/blackberry10/.gitignore
+++ b/blackberry10/.gitignore
@@ -20,5 +20,4 @@ bin/node_modules
 bin/templates/project/lib
 example/
 node_modules/
-bin/templates/project/cordova/lib/utils.js
 .tmp

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/210a7405/blackberry10/bin/templates/project/cordova/lib/run
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/run 
b/blackberry10/bin/templates/project/cordova/lib/run
index 5da5dab..aa226e6 100755
--- a/blackberry10/bin/templates/project/cordova/lib/run
+++ b/blackberry10/bin/templates/project/cordova/lib/run
@@ -42,7 +42,7 @@ var childProcess = require("child_process"),
 
 function generateOptions(uninstall) {
     var options = [];
-    barPath = pkgrUtils.escapeStringForShell(path.normalize(__dirname + 
"/../../build/" + targets.targets[target].type + "/" + generateBarName() + 
".bar"));
+    barPath = pkgrUtils.escapeStringForShell(path.normalize(__dirname + 
"/../../build/" + targets.targets[target].type + "/" + utils.genBarName() + 
".bar"));
 
     options.push("-device");
     options.push(ip);

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/210a7405/blackberry10/bin/templates/project/cordova/lib/session.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/session.js 
b/blackberry10/bin/templates/project/cordova/lib/session.js
index 02ae91a..048d9c3 100644
--- a/blackberry10/bin/templates/project/cordova/lib/session.js
+++ b/blackberry10/bin/templates/project/cordova/lib/session.js
@@ -17,6 +17,7 @@
 var path = require("path"),
     fs = require("fs"),
     wrench = require("wrench"),
+    utils = require("./utils"),
     logger = require("./logger"),
     signingHelper = require("./signing-helper"),
     barConf = require("./bar-conf"),
@@ -55,7 +56,7 @@ module.exports = {
             outputDir = cmdline.output,
             properties = require("../../project.json"),
             archivePath = path.resolve(cmdline.args[0] ? cmdline.args[0] : 
"../../www"),
-            archiveName = properties.barName ? properties.barName : 
path.basename(archivePath, '.zip'),
+            archiveName = utils.genBarName(), 
             appdesc,
             buildId = cmdline.buildId;
 

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/210a7405/blackberry10/bin/templates/project/cordova/lib/utils.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/utils.js 
b/blackberry10/bin/templates/project/cordova/lib/utils.js
new file mode 100644
index 0000000..42b0d16
--- /dev/null
+++ b/blackberry10/bin/templates/project/cordova/lib/utils.js
@@ -0,0 +1,218 @@
+/*
+ *  Copyright 2012 Research In Motion Limited.
+ *
+ * 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'),
+    wrench = require('wrench'),
+    localize = require("./localize"),
+    os = require('os'),
+    DEFAULT_BAR_NAME = "cordova-BB10-app",
+    PROPERTY_FILE_NAME = 'blackberry10.json',
+    CORDOVA_DIR = '.cordova',
+    DEFAULT_PROPERTY_FILE = {
+        targets: {
+        }
+    },
+    _self;
+
+function swapBytes(buffer) {
+    var l = buffer.length,
+        i,
+        a;
+
+    if (l % 2 === 0x01) {
+        throw localize.translate("EXCEPTION_BUFFER_ERROR");
+    }
+
+    for (i = 0; i < l; i += 2) {
+        a = buffer[i];
+        buffer[i] = buffer[i + 1];
+        buffer[i + 1] = a;
+    }
+
+    return buffer;
+}
+
+_self = {
+    writeFile: function (fileLocation, fileName, fileData) {
+        //If directory does not exist, create it.
+        if (!fs.existsSync(fileLocation)) {
+            wrench.mkdirSyncRecursive(fileLocation, "0755");
+        }
+
+        fs.writeFile(path.join(fileLocation, fileName), fileData, function 
(err) {
+            if (err) throw err;
+        });
+    },
+
+    copyFile: function (srcFile, destDir, baseDir) {
+        var filename = path.basename(srcFile),
+            fileBuffer = fs.readFileSync(srcFile),
+            fileLocation;
+
+        //if a base directory was provided, determine
+        //folder structure from the relative path of the base folder
+        if (baseDir && srcFile.indexOf(baseDir) === 0) {
+            fileLocation = srcFile.replace(baseDir, destDir);
+            wrench.mkdirSyncRecursive(path.dirname(fileLocation), "0755");
+            fs.writeFileSync(fileLocation, fileBuffer);
+        } else {
+            if (!fs.existsSync(destDir)) {
+                wrench.mkdirSyncRecursive(destDir, "0755");
+            }
+
+            fs.writeFileSync(path.join(destDir, filename), fileBuffer);
+        }
+    },
+
+    listFiles: function (directory, filter) {
+        var files = wrench.readdirSyncRecursive(directory),
+            filteredFiles = [];
+
+        files.forEach(function (file) {
+            //On mac wrench.readdirSyncRecursive does not return absolute 
paths, so resolve one.
+            file = path.resolve(directory, file);
+
+            if (filter(file)) {
+                filteredFiles.push(file);
+            }
+        });
+
+        return filteredFiles;
+    },
+
+    isWindows: function () {
+        return os.type().toLowerCase().indexOf("windows") >= 0;
+    },
+
+    isArray: function (obj) {
+        return obj.constructor.toString().indexOf("Array") !== -1;
+    },
+
+    isEmpty : function (obj) {
+        for (var prop in obj) {
+            if (obj.hasOwnProperty(prop))
+                return false;
+        }
+        return true;
+    },
+
+    toBoolean: function (myString, defaultVal) {
+        // if defaultVal is not passed, default value is undefined
+        return myString === "true" ? true : myString === "false" ? false : 
defaultVal;
+    },
+
+    parseUri : function (str) {
+        var i, uri = {},
+            key = [ "source", "scheme", "authority", "userInfo", "user", 
"password", "host", "port", "relative", "path", "directory", "file", "query", 
"anchor" ],
+            matcher = 
/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/.exec(str);
+
+        for (i = key.length - 1; i >= 0; i--) {
+            uri[key[i]] = matcher[i] || "";
+        }
+
+        return uri;
+    },
+
+    // uri - output from parseUri
+    isAbsoluteURI : function (uri) {
+        if (uri && uri.source) {
+            return uri.relative !== uri.source;
+        }
+
+        return false;
+    },
+
+    isLocalURI : function (uri) {
+        return uri && uri.scheme && uri.scheme.toLowerCase() === "local";
+    },
+
+    // Convert node.js Buffer data (encoded) to String
+    bufferToString : function (data) {
+        var s = "";
+        if (Buffer.isBuffer(data)) {
+            if (data.length >= 2 && data[0] === 0xFF && data[1] === 0xFE) {
+                s = data.toString("ucs2", 2);
+            } else if (data.length >= 2 && data[0] === 0xFE && data[1] === 
0xFF) {
+                swapBytes(data);
+                s = data.toString("ucs2", 2);
+            } else if (data.length >= 3 && data[0] === 0xEF && data[1] === 
0xBB && data[2] === 0xBF) {
+                s = data.toString("utf8", 3);
+            } else {
+                s = data.toString("ascii");
+            }
+        }
+
+        return s;
+    },
+
+    // Wrap object property in an Array if the property is defined and it is 
not an Array
+    wrapPropertyInArray : function (obj, property) {
+        if (obj && obj[property] && !(obj[property] instanceof Array)) {
+            obj[property] = [ obj[property] ];
+        }
+    },
+
+    loadModule: function (path) {
+        return require(path);
+    },
+
+    findHomePath : function () {
+        return process.env.HOME || process.env.HOMEPATH || 
process.env.USERPROFILE;
+    },
+
+    getCordovaDir: function () {
+        var cordovaPath = path.join(_self.findHomePath(), CORDOVA_DIR);
+
+        if (!fs.existsSync(cordovaPath)) {
+            fs.mkdirSync(cordovaPath);
+        }
+
+        return cordovaPath;
+    },
+
+    getPropertiesFilePath: function () {
+        var propertiesFile = path.join(_self.getCordovaDir(), 
PROPERTY_FILE_NAME);
+
+        if (!fs.existsSync(propertiesFile)) {
+            _self.writeToPropertiesFile(DEFAULT_PROPERTY_FILE);
+        }
+
+        return propertiesFile;
+    },
+
+    getPropertiesFileName: function () {
+        return PROPERTY_FILE_NAME;
+    },
+
+    getProperties: function () {
+        return require(_self.getPropertiesFilePath());
+    },
+
+    writeToPropertiesFile: function (data) {
+        var contents = JSON.stringify(data, null, 4) + "\n",
+            propertiesFile = path.join(_self.getCordovaDir(), 
PROPERTY_FILE_NAME);
+
+        fs.writeFileSync(propertiesFile, contents, 'utf-8');
+    },
+
+    genBarName: function() {
+        return DEFAULT_BAR_NAME;
+    }
+
+};
+
+module.exports = _self;

Reply via email to