You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by om...@apache.org on 2016/04/22 04:27:28 UTC

[1/2] cordova-medic git commit: Revert the revert of commits related to CB-11135 and CB-10475 This reverts commit dd33cab36b1498b384eebf9ee3942ef2cfd32d63.

Repository: cordova-medic
Updated Branches:
  refs/heads/master dd33cab36 -> bf99e1977


Revert the revert of commits related to CB-11135 and CB-10475
 This reverts commit dd33cab36b1498b384eebf9ee3942ef2cfd32d63.


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

Branch: refs/heads/master
Commit: b82a1ee969539ee502286ab9f3069ef81c4167ce
Parents: dd33cab
Author: Omar Mefire <om...@gmail.com>
Authored: Thu Apr 21 18:55:46 2016 -0700
Committer: Omar Mefire <om...@gmail.com>
Committed: Thu Apr 21 19:01:06 2016 -0700

----------------------------------------------------------------------
 lib/medicIOSPermissions.js |  42 ++++++++++++++
 lib/util.js                | 120 ++++++++++++++++++++++++++++++++++------
 medic/medic-run.js         |  34 ++++++++++--
 package.json               |   3 +-
 4 files changed, 176 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/b82a1ee9/lib/medicIOSPermissions.js
----------------------------------------------------------------------
diff --git a/lib/medicIOSPermissions.js b/lib/medicIOSPermissions.js
new file mode 100644
index 0000000..573f2fd
--- /dev/null
+++ b/lib/medicIOSPermissions.js
@@ -0,0 +1,42 @@
+#!/usr/bin/env node
+
+/* jshint node: true */
+var path     = require('path');
+var fs       = require('fs');
+var shelljs  = require("shelljs");
+var util     = require('./util');
+
+var TCC_FOLDER_PERMISSION = 0777;
+
+function MedicIOSPermissions(appName, tccDbPath) {
+    this.appName = appName;
+    this.tccDbPath = tccDbPath;
+}
+
+MedicIOSPermissions.prototype.updatePermissions = function(serviceList){
+    var simulatorsFolder   = util.getSimulatorsFolder();
+    var simId              = util.getSimId();
+    util.medicLog('Sim Id is: ' + simId);
+    var destinationTCCFile = path.join(simulatorsFolder, simId, '/data/Library/TCC/TCC.db');
+
+    if(!util.doesFileExist(destinationTCCFile)) {
+        // No TCC.db file exists by default. So, Copy the new TCC.db file
+        var destinationTCCFolder = path.join(simulatorsFolder, simId, '/data/Library/TCC');
+        if(!util.doesFileExist(destinationTCCFolder)){
+            fs.mkdir(destinationTCCFolder, TCC_FOLDER_PERMISSION);
+        }
+        var command = "cp " + this.tccDbPath + " " + destinationTCCFolder;
+        util.medicLog("Running Command: " + command);
+        shelljs.exec(command, {silent: true, async: false});
+    }
+
+    for(var i = 0; i < serviceList.length; i++) {
+        var command = util.getSqlite3InsertionCommand(destinationTCCFile, serviceList[i], this.appName);
+        util.medicLog("Running Command: " + command);
+        // If the service has an entry already, the insert command will fail.
+        // But, such a failure is intentionally not handled here.
+        shelljs.exec(command, {silent: true, async: false});
+    }
+}
+
+module.exports = MedicIOSPermissions;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/b82a1ee9/lib/util.js
----------------------------------------------------------------------
diff --git a/lib/util.js b/lib/util.js
index 06da676..8bc894a 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -21,15 +21,17 @@
 
 "use strict";
 
-module.exports = (function () {
+module.exports = (function() {
 
     var os = require("os");
     var shelljs = require("shelljs");
+    var util = require('util');
+    var path = require('path-extra');
 
     // constants
-    var ESCAPE    = String.fromCharCode(27);
+    var ESCAPE = String.fromCharCode(27);
     var RED_COLOR = ESCAPE + "[31m";
-    var NO_COLOR  = ESCAPE + "[m";
+    var NO_COLOR = ESCAPE + "[m";
     var DEVICE_ROW_PATTERN = /(emulator|device|host)/m;
     var HEADING_LINE_PATTERN = /List of devices/m;
 
@@ -37,11 +39,22 @@ module.exports = (function () {
         console.log(RED_COLOR + "[MEDIC LOG " + new Date().toUTCString() + "]" + NO_COLOR + " " + message);
     }
 
+    function getLocalCLI(appPath) {
+        var cli;
+        if (isWindows()) {
+            cli = "cordova.bat";
+        } else {
+            cli = "./cordova";
+        }
+
+        return appPath ? path.join(appPath, cli) : cli;
+    }
+
     function contains(collection, item) {
         return collection.indexOf(item) !== (-1);
     }
 
-    function isWindows () {
+    function isWindows() {
         // NOTE:
         //      - including "^" because otherwise "Darwin" matches
         //      - only "win" and not "windows" because "win32" should also match
@@ -53,10 +66,15 @@ module.exports = (function () {
         process.exit(1);
     }
 
-    function secToMin (seconds) {
+    function secToMin(seconds) {
         return Math.ceil(seconds / 60);
     }
 
+    function getSimulatorsFolder() {
+        var simulatorsFolderPath = path.join(path.homedir(), "Library", "Developer", "CoreSimulator", "Devices");
+        return simulatorsFolderPath;
+    }
+
     function countAndroidDevices() {
         var listCommand = "adb devices";
 
@@ -64,8 +82,8 @@ module.exports = (function () {
         medicLog("    " + listCommand);
 
         var numDevices = 0;
-        var result = shelljs.exec(listCommand, {silent: false, async: false});
-        result.output.split('\n').forEach(function (line) {
+        var result = shelljs.exec(listCommand, { silent: false, async: false });
+        result.output.split('\n').forEach(function(line) {
             if (!HEADING_LINE_PATTERN.test(line) && DEVICE_ROW_PATTERN.test(line)) {
                 numDevices += 1;
             }
@@ -74,24 +92,94 @@ module.exports = (function () {
         return numDevices;
     }
 
+    function getSimId() {
+        var findSimCommand = getLocalCLI() + " run --list --emulator | grep ^iPhone | tail -n1";
+
+        medicLog("running:");
+        medicLog("    " + findSimCommand);
+
+        var findSimResult = shelljs.exec(findSimCommand, { silent: true, async: false });
+
+        if (findSimResult.code > 0) {
+            medicLog("Failed to find simulator we deployed to");
+            return;
+        }
+
+        var split = findSimResult.output.split(", ");
+        // Format of the output is "iPhone-6s-Plus, 9.1"
+        // Extract the device name and the version number
+        var device = split[0].replace(/-/g, " ").trim();
+        var version = split[1].trim();
+
+        // Next, figure out the ID of the simulator we found
+        var instrCommand = "instruments -s devices | grep ^iPhone";
+        medicLog("running:");
+        medicLog("    " + instrCommand);
+
+        var instrResult = shelljs.exec(instrCommand, { silent: true, async: false });
+
+        if (instrResult.code > 0) {
+            medicLog("Failed to get the list of simulators");
+            return;
+        }
+
+        // This matches <device> (<version>) [<simulator-id>]
+        // ... or <device> (<version>) [<simulator-id>] (Simulator) in Xcode 7.3
+        var simIdRegex = /^([a-zA-Z\d ]+) \(([\d.]+)\) \[([a-zA-Z\d\-]*)\].*$/;
+
+
+        var simId = null;
+        var lines = instrResult.output.split(/\n/);
+        lines.forEach(function(line) {
+            var simIdMatch = simIdRegex.exec(line);
+            if (simIdMatch && simIdMatch.length === 4 && simIdMatch[1] === device && simIdMatch[2] === version) {
+                simId = encodeURIComponent(simIdMatch[3]);
+            }
+        });
+
+        return simId;
+    }
+
+    function doesFileExist(filePath) {
+        var fileExists = false;
+        try {
+            stats = fs.statSync(filePath);
+            fileExists = true;
+        } catch (e) {
+            fileExists = false;
+        }
+        return fileExists;
+    }
+
+    function getSqlite3InsertionCommand(destinationTCCFile, service, appName) {
+        return util.format('sqlite3 %s "insert into access'
+            + '(service, client, client_type, allowed, prompt_count, csreq) values(\'%s\', \'%s\', '
+            + '0,1,1,NULL)"', destinationTCCFile, service, appName);
+    }
+
     return {
 
         // constants
-        ANDROID:    "android",
+        ANDROID: "android",
         BLACKBERRY: "blackberry10",
-        IOS:        "ios",
-        WINDOWS:    "windows",
+        IOS: "ios",
+        WINDOWS: "windows",
 
         DEFAULT_ENCODING: "utf-8",
         DEFAULT_LOG_TIME: 15,
         DEFAULT_LOG_TIME_ADDITIONAL: 2,
 
         // functions
-        fatal:     fatal,
+        fatal: fatal,
         isWindows: isWindows,
-        medicLog:  medicLog,
-        contains:  contains,
-        secToMin:  secToMin,
-        countAndroidDevices: countAndroidDevices
+        medicLog: medicLog,
+        contains: contains,
+        secToMin: secToMin,
+        countAndroidDevices: countAndroidDevices,
+        getSimulatorsFolder: getSimulatorsFolder,
+        getSimId: getSimId,
+        doesFileExist: doesFileExist,
+        getLocalCLI: getLocalCLI,
+        getSqlite3InsertionCommand: getSqlite3InsertionCommand
     };
-}());
+} ());

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/b82a1ee9/medic/medic-run.js
----------------------------------------------------------------------
diff --git a/medic/medic-run.js b/medic/medic-run.js
index 984c102..a2b3b71 100644
--- a/medic/medic-run.js
+++ b/medic/medic-run.js
@@ -33,6 +33,7 @@ var request  = require("request");
 
 var util     = require("../lib/util");
 var testwait = require("../lib/testwait");
+var MedicIOSPermissions = require("../lib/medicIOSPermissions");
 
 // constants
 var CORDOVA_MEDIC_DIR         = "cordova-medic";
@@ -49,6 +50,11 @@ var SERVER_RESPONSE_TIMEOUT   = 15000; // in milliseconds
 var MAX_NUMBER_OF_TRIES       = 3;
 var WAIT_TIME_TO_RETRY_CONNECTION  = 15000; // in milliseconds
 
+// Used to grant appropriate iOS permissions
+var IOS_APPS_TO_GRANT_PERMISSIONS = ['kTCCServiceAddressBook'];
+var IOS_SIM_FOLDER = "/Users/buildbot/Library/Developer/CoreSimulator/Devices/";
+var IOS_TCC_DB_FOLDER = "/Users/buildbot/Library/Application\ Support/com.apple.TCC/";
+
 // helpers
 function currentMillisecond() {
     return new Date().valueOf();
@@ -243,12 +249,21 @@ function windowsSpecificPreparation(argv) {
     return extraArgs;
 }
 
-function getLocalCLI() {
-    if (util.isWindows()) {
-        return "cordova.bat";
-    } else {
-        return "./cordova";
+function iOSSpecificPreparation(argv) {
+    var extraArgs = "";
+
+    util.medicLog("Granting iOS permissions: ");
+
+    var appName = argv.app;
+    var simulatorsFolder = argv.simulatorsFolder;
+    var tccDbPath = argv.tccDbPath;
+
+    if(appName && simulatorsFolder && tccDbPath) {
+        var medicPerms = new MedicIOSPermissions(appName, simulatorsFolder, tccDbPath);
+        medicPerms.updatePermissions(IOS_APPS_TO_GRANT_PERMISSIONS);
     }
+
+    return extraArgs;
 }
 
 function cordovaReturnedError(returnCode, output) {
@@ -331,6 +346,8 @@ function main() {
         .default("app", DEFAULT_APP_PATH)
         .default("timeout", DEFAULT_TIMEOUT).describe("timeout", "timeout in seconds")
         .default("winvers", DEFAULT_WINDOWS_VERSION).describe("winvers", "[" + WINDOWS_VERSION_CHOICES.join("|") + "]")
+        .default("simulatorsFolder", IOS_SIM_FOLDER)
+        .default("tccDbPath", IOS_TCC_DB_FOLDER)
         .argv;
 
     var platform   = argv.platform;
@@ -342,7 +359,7 @@ function main() {
 
     var workingDir = process.cwd();
 
-    var cli = getLocalCLI();
+    var cli = util.getLocalCLI();
 
     // check that the app exists
     if (!fs.existsSync(appPath)) {
@@ -363,6 +380,11 @@ function main() {
             platformArgs = androidSpecificPreparation(argv);
         } else if (platform === util.WINDOWS) {
             platformArgs = windowsSpecificPreparation(argv);
+        } else if (platform === util.IOS) {
+            // Note: (hack) we need to be in a cordova project before we can run iOS specific preparations
+            shelljs.pushd(appPath);
+            platformArgs = iOSSpecificPreparation(argv);
+            shelljs.popd(appPath);
         }
 
         // enter the app directory

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/b82a1ee9/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index f947f43..c4a43e8 100644
--- a/package.json
+++ b/package.json
@@ -20,7 +20,8 @@
     "tree-kill": "^1.0.0",
     "unorm": "^1.4.1",
     "wd": "^0.3.11",
-    "mkdirp": "^0.5.1"
+    "mkdirp": "^0.5.1",
+    "path-extra": "^3.0.0"
   },
   "subdomain": "cordova.medic",
   "engines": {


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


[2/2] cordova-medic git commit: CB-11135 If folder is pre-existent, don't error out

Posted by om...@apache.org.
CB-11135 If folder is pre-existent, don't error out

 This closes #98


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

Branch: refs/heads/master
Commit: bf99e19777f6f7b93fc03f9490aa36eca2bc77e2
Parents: b82a1ee
Author: Omar Mefire <om...@gmail.com>
Authored: Thu Apr 21 18:53:39 2016 -0700
Committer: Omar Mefire <om...@gmail.com>
Committed: Thu Apr 21 19:21:24 2016 -0700

----------------------------------------------------------------------
 lib/medicIOSPermissions.js | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/bf99e197/lib/medicIOSPermissions.js
----------------------------------------------------------------------
diff --git a/lib/medicIOSPermissions.js b/lib/medicIOSPermissions.js
index 573f2fd..40c1a28 100644
--- a/lib/medicIOSPermissions.js
+++ b/lib/medicIOSPermissions.js
@@ -5,6 +5,7 @@ var path     = require('path');
 var fs       = require('fs');
 var shelljs  = require("shelljs");
 var util     = require('./util');
+var mkdirp   = require('mkdirp');
 
 var TCC_FOLDER_PERMISSION = 0777;
 
@@ -23,7 +24,9 @@ MedicIOSPermissions.prototype.updatePermissions = function(serviceList){
         // No TCC.db file exists by default. So, Copy the new TCC.db file
         var destinationTCCFolder = path.join(simulatorsFolder, simId, '/data/Library/TCC');
         if(!util.doesFileExist(destinationTCCFolder)){
-            fs.mkdir(destinationTCCFolder, TCC_FOLDER_PERMISSION);
+            mkdirp(destinationTCCFolder, {
+                mode: TCC_FOLDER_PERMISSION
+            });
         }
         var command = "cp " + this.tccDbPath + " " + destinationTCCFolder;
         util.medicLog("Running Command: " + command);


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