You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by dblotsky <gi...@git.apache.org> on 2015/04/29 21:05:39 UTC

[GitHub] cordova-medic pull request: [CB-8870] Consolidating medic code.

GitHub user dblotsky opened a pull request:

    https://github.com/apache/cordova-medic/pull/47

    [CB-8870] Consolidating medic code.

    Consolidating medic code as the following commands to `medic.js`:
    
        medic.js kill     - kills emulators
        medic.js clean    - cleans workspace
        medic.js checkout - checks out code
        medic.js run      - runs mobilespec
        medic.js check    - checks run results
    
    The old code can be deleted once this is accepted.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/MSOpenTech/cordova-medic CB-8870

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/cordova-medic/pull/47.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #47
    
----
commit 0497c2cdbefeb2752019fcbaa13be787ec9e5fb7
Author: Dmitry Blotsky <dm...@gmail.com>
Date:   2015-04-17T21:34:52Z

    [CB-8870] Consolidating medic code.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-medic pull request: [CB-8870] Consolidating medic code.

Posted by robpaveza <gi...@git.apache.org>.
Github user robpaveza commented on a diff in the pull request:

    https://github.com/apache/cordova-medic/pull/47#discussion_r29370150
  
    --- Diff: bin/medic.js ---
    @@ -19,18 +19,44 @@
      * under the License.
      */
     
    -"use strict";
    +/* jshint node: true */
    +
    +// "use strict";
     
     // node dependencies
    -var fs = require("fs");
    -var os = require("os");
    +var fs   = require("fs");
    +var os   = require("os");
    +var path = require("path");
     
     // external dependencies
     var shelljs  = require("shelljs");
     var optimist = require("optimist");
     
    +// internal dependencies
    +var testwait  = require("./lib/testwait");
    +var testcheck = require("./lib/testcheck");
    +
     // constants
    -var MAX_REMOVAL_ATTEMPTS = 3;
    +var MAX_REMOVAL_ATTEMPTS    = 3;
    +var CORDOVA_MEDIC_DIR       = "cordova-medic";
    +var DEFAULT_APP_PATH        = "mobilespec";
    +var DEFAULT_APP_ENTRY       = "index.html";
    +var ANDROID_TIMEOUT         = 120000;
    +var MEDIC_BUILD_PREFIX      = "medic-cli-build";
    +var DEFAULT_ENCODING        = "utf-8";
    +var DEFAULT_WINDOWS_VERSION = "store";
    +var WINDOWS_VERSION_CHOICES = ["store", "store80", "phone"];
    +var ONE_MINUTE              = 1 * 60;
    --- End diff --
    
    Why 1 times 60?  Time is in ms or s?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-medic pull request: [CB-8870] Consolidating medic code.

Posted by dblotsky <gi...@git.apache.org>.
Github user dblotsky commented on a diff in the pull request:

    https://github.com/apache/cordova-medic/pull/47#discussion_r29374675
  
    --- Diff: bin/medic.js ---
    @@ -19,18 +19,44 @@
      * under the License.
      */
     
    -"use strict";
    +/* jshint node: true */
    +
    +// "use strict";
     
     // node dependencies
    -var fs = require("fs");
    -var os = require("os");
    +var fs   = require("fs");
    +var os   = require("os");
    +var path = require("path");
     
     // external dependencies
     var shelljs  = require("shelljs");
     var optimist = require("optimist");
     
    +// internal dependencies
    +var testwait  = require("./lib/testwait");
    +var testcheck = require("./lib/testcheck");
    +
     // constants
    -var MAX_REMOVAL_ATTEMPTS = 3;
    +var MAX_REMOVAL_ATTEMPTS    = 3;
    +var CORDOVA_MEDIC_DIR       = "cordova-medic";
    +var DEFAULT_APP_PATH        = "mobilespec";
    +var DEFAULT_APP_ENTRY       = "index.html";
    +var ANDROID_TIMEOUT         = 120000;
    +var MEDIC_BUILD_PREFIX      = "medic-cli-build";
    +var DEFAULT_ENCODING        = "utf-8";
    +var DEFAULT_WINDOWS_VERSION = "store";
    +var WINDOWS_VERSION_CHOICES = ["store", "store80", "phone"];
    +var ONE_MINUTE              = 1 * 60;
    --- End diff --
    
    Good catch. Will add comments regarding units and fix the redundant multiplication.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-medic pull request: [CB-8870] Consolidating medic code.

Posted by dblotsky <gi...@git.apache.org>.
Github user dblotsky commented on the pull request:

    https://github.com/apache/cordova-medic/pull/47#issuecomment-97549951
  
    Comment from myself: fix license headers.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-medic pull request: [CB-8870] Consolidating medic code.

Posted by robpaveza <gi...@git.apache.org>.
Github user robpaveza commented on a diff in the pull request:

    https://github.com/apache/cordova-medic/pull/47#discussion_r29370686
  
    --- Diff: bin/medic.js ---
    @@ -39,9 +65,109 @@ var argv = optimist
         .argv;
     
     // helpers
    +function killTasks(taskNames) {
    +
    +    if (!taskNames || taskNames.length < 1) {
    +        console.warn("no tasks to kill");
    +        return;
    +    }
    +
    +    if (isWindows()) {
    +        var cli  = "taskkill /F";
    +        var args = taskNames.map(function (name) { return "/IM \"" + name + "\""; });
    +    } else {
    +        var cli  = "killall";
    +        var args = taskNames.map(function (name) { return "\"" + name + "\""; });
    +    }
    +
    +    var command = cli + " " + args.join(" ");
    +    medicLog("running the following command:");
    +    medicLog("    " + command);
    +
    +    shelljs.exec(command, {silent: false, async: true}, function (returnCode, output) {
    +        if (returnCode !== 0) {
    +            console.warn("WARNING: kill command returned " + returnCode);
    +        }
    +    });
    +}
    +
     function fatal(message) {
    -    console.error("ERROR: " + message);
    -    process.exit(1);
    +    console.error("FATAL: " + message);
    +    process.exit(ERROR);
    +}
    +
    +function medicLog(message) {
    +    console.log("\033[32m[MEDIC LOG]\033[m " + message);
    +}
    +
    +function currentMillisecond() {
    +    // NOTE:
    +    //      coercing a Date to a Number returns
    +    //      the Date's representation in milliseconds
    +    return Number(new Date());
    --- End diff --
    
    Consider new Date().valueOf() instead of the coercing operator.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-medic pull request: [CB-8870] Consolidating medic code.

Posted by muratsu <gi...@git.apache.org>.
Github user muratsu commented on a diff in the pull request:

    https://github.com/apache/cordova-medic/pull/47#discussion_r29369904
  
    --- Diff: bin/lib/couchdb.js ---
    @@ -0,0 +1,151 @@
    +
    +/*
    +Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
    +
    +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 request = require('request');
    +var follow = require('follow');
    +
    +var DEFAULT_COUCHDB_URI = "http://localhost";
    +
    +var couchdbURI = DEFAULT_COUCHDB_URI;
    +
    +function init(uri) {
    +    couchdbURI = uri;
    +}
    +
    +// Generic interface + convenience functions for working with couch dbs
    +function db(name) {
    +    this.name = name;
    +    this.db_url = couchdbURI + '/' + this.name;
    +    this.is_following = false;
    +}
    +
    +db.prototype = {
    +    get:function(id, callback) {
    +        // Gets a specific document by id
    +
    +        var db = this;
    +        var url = this.db_url + '/' + id;
    +        request.get(url, function(error, response, body) {
    +            if (error) {
    +                callback(error);
    +            } else {
    +                if (response.statusCode == 200) {
    +                    callback(false, JSON.parse(body));
    +                } else if (response.statusCode == 404) {
    +                    callback(true, 404);
    +                } else {
    +                    callback(true, response.statusCode);
    +                }
    +            }
    +        });
    +    },
    +    query_view:function(design, view, callback) {
    +        // Queries a view.
    +
    +        var db = this;
    +        var url = this.db_url + '/_design/' + design + '/_view/' + view;
    +        request.get(url, function(error, response, body) {
    +            if (error) {
    +                callback(error);
    +            } else {
    +                if (response.statusCode == 200) {
    +                    callback(false, JSON.parse(body));
    +                } else if (response.statusCode == 404) {
    +                    callback(true, 404);
    +                } else {
    +                    callback(true, response.statusCode);
    +                }
    +            }
    +        });
    +    },
    +    clobber:function(id, document, callback) {
    +        // Overwrites a document
    +        var db = this;
    +        var url = this.db_url + '/' + id;
    +
    +        request.put({
    +            url:url,
    +            json:document
    +        }, function(error, response, body) {
    +            if (error || response.statusCode === 404) {
    +                console.error('Request failed: ' + url);
    +                callback(true, JSON.stringify(body));
    +                return;
    +            }
    +
    +            var status = response.statusCode;
    +            if (status == 201) callback(false, body);
    +            else if (status == 409) {
    +                request.get(url, function(err, resp, bod) {
    +                    if (err) callback(err);
    +                    else {
    +                        if (resp.statusCode == 200) {
    +                            var existing = JSON.parse(bod);
    +                            var rev = existing._rev;
    +                            request.del({
    +                                url:url + '?rev=' + rev,
    +                            }, function(er, res, boday) {
    +                                if (er) callback(er);
    +                                else {
    +                                    if (res.statusCode == 200) {
    +                                        request.put({
    +                                            url:url,
    +                                            json:document
    +                                        }, function(argh, r, bodee) {
    +                                            if (argh) callback(argh);
    +                                            else {
    +                                                if(r){
    +                                                    if (r.statusCode == 201) callback(false, bodee);
    +                                                    else callback(true, r.statusCode);
    +                                                } else {
    +                                                    callback(true,"URL failed?");
    +                                                }
    +                                            }
    +                                        });
    +                                    } else callback(true, res.statusCode);
    +                                }
    +                            });
    +                        } else callback(true, resp.statusCode);
    +                    }
    +                });
    +            } else callback(true, response.statusCode);
    +
    +        });
    +    },
    +    follow:function(callback) {
    +        if (!this.is_following) {
    +            this.is_following = true;
    +            follow({
    +                db:this.db_url,
    +                since:'now',
    +                include_docs:true
    +            }, function(err, change) {
    +                if (!err) callback(false, change);
    +                else callback(err);
    +            });
    +            return true;
    +        } else return false;
    +    }
    +};
    +
    +module.exports = {
    +    init: init,
    +    db:   db,
    +};
    +
    +// build_errors:new db('build_errors'),
    +// mobilespec_results:new db('mobilespec_results'),
    +// test_details:new db('test_details')
    --- End diff --
    
    Unncecessary comments?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-medic pull request: [CB-8870] Consolidating medic code.

Posted by robpaveza <gi...@git.apache.org>.
Github user robpaveza commented on a diff in the pull request:

    https://github.com/apache/cordova-medic/pull/47#discussion_r29370556
  
    --- Diff: bin/medic.js ---
    @@ -39,9 +65,109 @@ var argv = optimist
         .argv;
     
     // helpers
    +function killTasks(taskNames) {
    +
    +    if (!taskNames || taskNames.length < 1) {
    +        console.warn("no tasks to kill");
    +        return;
    +    }
    +
    +    if (isWindows()) {
    +        var cli  = "taskkill /F";
    +        var args = taskNames.map(function (name) { return "/IM \"" + name + "\""; });
    +    } else {
    +        var cli  = "killall";
    +        var args = taskNames.map(function (name) { return "\"" + name + "\""; });
    +    }
    +
    +    var command = cli + " " + args.join(" ");
    +    medicLog("running the following command:");
    +    medicLog("    " + command);
    +
    +    shelljs.exec(command, {silent: false, async: true}, function (returnCode, output) {
    +        if (returnCode !== 0) {
    +            console.warn("WARNING: kill command returned " + returnCode);
    +        }
    +    });
    +}
    +
     function fatal(message) {
    -    console.error("ERROR: " + message);
    -    process.exit(1);
    +    console.error("FATAL: " + message);
    +    process.exit(ERROR);
    +}
    +
    +function medicLog(message) {
    +    console.log("\033[32m[MEDIC LOG]\033[m " + message);
    --- End diff --
    
    Might be worth adding a comment so that people can parse out what your escaped characters are.  They look like octal encodings instead of Unicode.  While valid, is uncommon because translating to octal and then to Latin-1 is a two-step process.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-medic pull request: [CB-8870] Consolidating medic code.

Posted by robpaveza <gi...@git.apache.org>.
Github user robpaveza commented on a diff in the pull request:

    https://github.com/apache/cordova-medic/pull/47#discussion_r29371372
  
    --- Diff: bin/medic.js ---
    @@ -55,6 +181,210 @@ function exclusiveLs(lsPath, excludes) {
         });
     }
     
    +function getConfigPath(appPath) {
    +    return path.join(appPath, "config.xml");
    +}
    +
    +function getCSPPath(appPath) {
    +    return path.join(appPath, "www", "csp-incl.js");
    +}
    +
    +function addURIToWhitelist(appPath, uri) {
    +
    +    var configFile = getConfigPath(appPath);
    +    var cspFile    = getCSPPath(appPath);
    +
    +    var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING);
    +    var cspContent    = fs.readFileSync(cspFile, DEFAULT_ENCODING);
    +
    +    // add whitelisting rule allow access to couch server
    +    medicLog("Adding whitelist rule for CouchDB host: " + uri);
    +    var accessOriginTag = "<access origin=\"" + uri + "\" />";
    +    if (!contains(configContent, accessOriginTag)) {
    +        configContent = configContent.split("</widget>").join("");
    +        configContent += "    " + accessOriginTag + "\n</widget>\n";
    +        fs.writeFileSync(configFile, configContent, DEFAULT_ENCODING);
    +    }
    +
    +    // add couchdb address to csp rules
    +    medicLog("Adding CSP rule for CouchDB host: " + uri);
    +    var cspRule = "connect-src " + uri;
    +    if (!contains(cspContent, cspRule)) {
    +        cspContent = cspContent.replace("connect-src", cspRule);
    +        fs.writeFileSync(cspFile, cspContent, DEFAULT_ENCODING);
    +    }
    +}
    +
    +function setEntryPoint(appPath, entryPoint) {
    +
    +    var configFile = getConfigPath(appPath);
    +    var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING);
    +
    +    // replace/add start page preference
    +    // check if config.xml already contains <content /> element
    +    medicLog("Setting entry point to " + entryPoint + " in config.xml");
    +
    +    if (configContent.match(/<content\s*src=".*"\s*\/>/gi)) {
    +        configContent = configContent.replace(
    +            /<content\s*src=".*"\s*\/>/gi,
    +            "<content src=\"" + entryPoint + "\" />"
    +        );
    +
    +    } else {
    +
    +        // add entry point to config
    +        configContent = configContent.split("</widget>").join("") +
    +            "    <content src=\"" + entryPoint + "\" />\n</widget>";
    +    }
    +
    +    // write the changes
    +    fs.writeFileSync(configFile, configContent, DEFAULT_ENCODING);
    +}
    +
    +function changeLoadTimeout(appPath, timeout) {
    +
    +    medicLog("Increasing url loading timeout for android to " + timeout);
    +
    +    var timeoutRegex           = /<preference\s*name\s *= \s*"?loadUrlTimeoutValue"?.*?((\/>)|(>.*?<\/\s*preference>))/i;
    +    var timeoutTag             = "<preference name=\"loadUrlTimeoutValue\" value=\"" + timeout + "\" />";
    +    var timeoutTagWithPlatform = "    <platform name=\"android\">\n        <preference name=\"loadUrlTimeoutValue\" value=\"120000\" />\n    </platform>\n";
    +    var platformRegex          = /<platform\s*name\s *= \s*"android"\s*>/i;
    +    var widgetRegex            = /<\/s*widget\s*>/i;
    +
    +    var configFile    = getConfigPath(appPath);
    +    var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING);
    +
    +    if (timeoutRegex.test(configContent)) {
    +        configContent = configContent.replace(timeoutRegex, timeoutTag);
    +        medicLog("Found \"loadUrlTimeoutValue\" preference, replacing with desired value");
    +    } else if (platformRegex.test(configContent)) {
    +        var oldPlatformTag = platformRegex.exec(configContent)[0];
    +        configContent = configContent.replace(platformRegex, oldPlatformTag + "\n        " + timeoutTag);
    +        medicLog("Found platform tag, appending \"loadUrlTimeoutValue\" preference");
    +    } else if (widgetRegex.test(configContent)) {
    +        var oldWidgetTag = widgetRegex.exec(configContent)[0];
    +        configContent = configContent.replace(widgetRegex, timeoutTagWithPlatform + oldWidgetTag);
    +        medicLog("Did not find platform tag, adding preference with platform tag");
    +    } else {
    +        medicLog("Warning: could not modify config.xml for android: no <widget> tag found!");
    +    }
    +
    +    // write the changes
    +    fs.writeFileSync(configFile, configContent, DEFAULT_ENCODING);
    +}
    +
    +function setWindowsTargetStoreVersion(appPath, version) {
    +
    +    medicLog('setting target store version to ' + version);
    +
    +    var configFile    = getConfigPath(appPath);
    +    var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING);
    +
    +    var versionPreference = '    <preference name="windows-target-version" value="' + version + '" />';
    --- End diff --
    
    Another example where you should be using ElementTree instead.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-medic pull request: [CB-8870] Consolidating medic code.

Posted by muratsu <gi...@git.apache.org>.
Github user muratsu commented on a diff in the pull request:

    https://github.com/apache/cordova-medic/pull/47#discussion_r29370417
  
    --- Diff: bin/lib/testcheck.js ---
    @@ -0,0 +1,77 @@
    +var http = require('http'),
    +    url = require('url'),
    +    q = require('q');
    +
    +module.exports = function (sha, dbHost) {
    +
    +    function getDocumentIdBySha() {
    +        var options = {
    +            host : url.parse(dbHost).hostname,
    +            port : url.parse(dbHost).port,
    +            path : '/mobilespec_results/_all_docs?start_key="' + sha + '"&limit=1'
    +        },
    +            resultsDoc = '',
    +            d = q.defer();
    +
    +        http.get(options, function (result) {
    +            result.on("data", function (chunk) {
    +                resultsDoc += chunk.toString();
    +            });
    +            result.on('end', function () {
    +                d.resolve(JSON.parse(resultsDoc).rows[0].id);
    +            });
    +        }).on('error', function (e) {
    +            console.log("Got error: " + e.message);
    +            d.reject(e);
    +        });
    +
    +        return d.promise;
    +    };
    +
    +    function getTestResult(resultId) {
    +        var options = {
    +            host : url.parse(dbHost).hostname,
    +            port : url.parse(dbHost).port,
    +            path : '/mobilespec_results/' + resultId
    +        };
    +        var d = q.defer();
    +        var resultsJSON = "";
    +        var failure;
    --- End diff --
    
    never used?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-medic pull request: [CB-8870] Consolidating medic code.

Posted by robpaveza <gi...@git.apache.org>.
Github user robpaveza commented on a diff in the pull request:

    https://github.com/apache/cordova-medic/pull/47#discussion_r29370102
  
    --- Diff: bin/medic.js ---
    @@ -19,18 +19,44 @@
      * under the License.
      */
     
    -"use strict";
    +/* jshint node: true */
    +
    +// "use strict";
     
     // node dependencies
    -var fs = require("fs");
    -var os = require("os");
    +var fs   = require("fs");
    +var os   = require("os");
    +var path = require("path");
     
     // external dependencies
     var shelljs  = require("shelljs");
     var optimist = require("optimist");
     
    +// internal dependencies
    +var testwait  = require("./lib/testwait");
    +var testcheck = require("./lib/testcheck");
    +
     // constants
    -var MAX_REMOVAL_ATTEMPTS = 3;
    +var MAX_REMOVAL_ATTEMPTS    = 3;
    +var CORDOVA_MEDIC_DIR       = "cordova-medic";
    +var DEFAULT_APP_PATH        = "mobilespec";
    +var DEFAULT_APP_ENTRY       = "index.html";
    +var ANDROID_TIMEOUT         = 120000;
    +var MEDIC_BUILD_PREFIX      = "medic-cli-build";
    +var DEFAULT_ENCODING        = "utf-8";
    +var DEFAULT_WINDOWS_VERSION = "store";
    +var WINDOWS_VERSION_CHOICES = ["store", "store80", "phone"];
    +var ONE_MINUTE              = 1 * 60;
    --- End diff --
    
    Seems like 1/1000th of a minute.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-medic pull request: [CB-8870] Consolidating medic code.

Posted by nikhilkh <gi...@git.apache.org>.
Github user nikhilkh commented on a diff in the pull request:

    https://github.com/apache/cordova-medic/pull/47#discussion_r29375808
  
    --- Diff: bin/medic.js ---
    @@ -39,9 +65,109 @@ var argv = optimist
         .argv;
     
     // helpers
    +function killTasks(taskNames) {
    +
    +    if (!taskNames || taskNames.length < 1) {
    +        console.warn("no tasks to kill");
    +        return;
    +    }
    +
    +    if (isWindows()) {
    +        var cli  = "taskkill /F";
    +        var args = taskNames.map(function (name) { return "/IM \"" + name + "\""; });
    +    } else {
    +        var cli  = "killall";
    +        var args = taskNames.map(function (name) { return "\"" + name + "\""; });
    +    }
    +
    +    var command = cli + " " + args.join(" ");
    +    medicLog("running the following command:");
    +    medicLog("    " + command);
    +
    +    shelljs.exec(command, {silent: false, async: true}, function (returnCode, output) {
    +        if (returnCode !== 0) {
    +            console.warn("WARNING: kill command returned " + returnCode);
    +        }
    +    });
    +}
    +
     function fatal(message) {
    -    console.error("ERROR: " + message);
    -    process.exit(1);
    +    console.error("FATAL: " + message);
    +    process.exit(ERROR);
    +}
    +
    +function medicLog(message) {
    +    console.log("\033[32m[MEDIC LOG]\033[m " + message);
    +}
    +
    +function currentMillisecond() {
    +    // NOTE:
    +    //      coercing a Date to a Number returns
    +    //      the Date's representation in milliseconds
    +    return Number(new Date());
    +}
    +
    +function generateBuildID() {
    +    var components = [MEDIC_BUILD_PREFIX, currentMillisecond()];
    +    return components.join("-");
    +}
    +
    +function tasksOnPlatform(platformName) {
    +    switch (platformName) {
    +        case WINDOWS:
    +            return ["WWAHost.exe"];
    +        case WP8:
    +            return ["Xde.exe"];
    +        case IOS:
    +            return ["iOS Simulator"];
    +        case ANDROID:
    +            if (isWindows()) {
    +                return ["emulator-arm.exe", "adb.exe"];
    +            } else {
    +                return ["emulator64-x86"];
    +            }
    +        case BLACKBERRY:
    +            return [];
    +        default:
    +            fatal("unknown platform " + platformName);
    +    }
    +}
    +
    +function cloneProject(projectName, projectsConfig) {
    +
    +    var project  = projectsConfig[projectName];
    +    var codebase = project.codebases[project.codebase];
    +    var command  = "git clone " + codebase.repo + " --branch=" + codebase.branch + " --depth 1"
    +
    +    shelljs.exec(command, {silent: false, async: true}, function (returnCode, output) {
    +        if (returnCode !== 0) {
    +            fatal("command \"" + command + "\" failed with code " + returnCode);
    --- End diff --
    
    It will be nice to provide the `output` for diagnostics of why it failed


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-medic pull request: [CB-8870] Consolidating medic code.

Posted by nikhilkh <gi...@git.apache.org>.
Github user nikhilkh commented on a diff in the pull request:

    https://github.com/apache/cordova-medic/pull/47#discussion_r29376311
  
    --- Diff: bin/medic.js ---
    @@ -109,10 +441,175 @@ function commandClean() {
     
         // if loop exited without success, return an error
         if (success === false) {
    -        fatal("failed to remove files");
    +        console.error("failed to remove files");
    +        process.exitCode = ERROR;
    +    } else {
    +        medicLog("cleanup succeeded");
         }
     }
     
    +function commandKill() {
    +
    +    // get command-specific args
    +    argv = optimist
    +        .usage("Usage: $0 --platform {platform}")
    +        .demand("platform")
    +        .argv;
    +
    +    var platform = argv.platform;
    +
    +    // get and kill platform tasks
    +    var platformTasks = tasksOnPlatform(platform)
    +    killTasks(platformTasks);
    +}
    +
    +function commandCheckout() {
    +
    +    // get command-specific args
    +    argv = optimist
    +        .usage("Usage: $0 --config {path} --exclude {name[,name[,...]]}")
    +        .demand("config")
    +        .argv;
    +
    +    var configFile    = argv.config;
    +    var excludedNames = [];
    +
    +    // parse excludes
    +    if (argv.exclude) {
    +        excludedNames = argv.exclude.split(",");
    +    }
    +
    +    // read in config
    +    var projectsConfig = JSON.parse(fs.readFileSync(configFile, DEFAULT_ENCODING));
    +
    +    // clone all projects in the config
    +    for (var projectName in projectsConfig) {
    +        if (excludedNames.indexOf(projectName) === (-1)) {
    +            cloneProject(projectName, projectsConfig);
    +        }
    +    }
    +}
    +
    +function commandRun() {
    +
    +    // get command-specific args
    +    argv = optimist
    +        .usage("Usage: $0 {options}")
    +        .demand("platform")
    +        .demand("couchdb")
    +        .default("entry", DEFAULT_APP_ENTRY)
    +        .default("id", generateBuildID())
    +        .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("|") + "]")
    +        .argv;
    +
    +    var platform   = argv.platform;
    +    var buildId    = argv.id;
    +    var appPath    = argv.app;
    +    var couchdbURI = argv.couchdb;
    +    var entryPoint = argv.entry;
    +    var timeout    = argv.timeout;
    +
    +    var cli = getLocalCLI();
    +
    +    // check that the app exists
    +    if (!fs.existsSync(appPath)) {
    +        fatal("app " + appPath + " does not exist");
    +    }
    +
    +    // modify the app to run autonomously
    +    createMedicJson(appPath, buildId, couchdbURI);
    +    setEntryPoint(appPath, entryPoint);
    +    addURIToWhitelist(appPath, couchdbURI);
    +
    +    // do platform-specific modifications
    +    var platformArgs = "";
    +    if (platform === ANDROID) {
    +        platformArgs = androidSpecifics(argv);
    +    } else if (platform === WINDOWS) {
    +        platformArgs = windowsSpecifics(argv);
    +    } else if (platform === WP8) {
    +        platformArgs = wp8Specifics(argv);
    +    }
    +
    +    // enter the app directory
    +    shelljs.pushd(appPath);
    +
    +    // build the code (synchronously)
    +    var buildCommand = cli + " build " + platform + " -- " + platformArgs;
    +    medicLog("building:");
    +    medicLog("    " + buildCommand);
    +
    +    var result = shelljs.exec(buildCommand, {silent: false, async: false});
    +    if (result.code != 0) {
    +        console.error("BUILD FAILED:\n" + result.output);
    +        fatal("build failed");
    +    }
    +
    +    // run the code (asynchronously)
    +    var runCommand = cli + " run " + platform + " -- " + platformArgs;
    +    medicLog("running:");
    +    medicLog("    " + runCommand);
    +
    +    shelljs.exec(runCommand, {silent: false, async: true}, function (returnCode, output) {
    +        if (returnCode != 0) {
    --- End diff --
    
    `returncode` is not always set correctly - cordova build & run.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-medic pull request: [CB-8870] Consolidating medic code.

Posted by muratsu <gi...@git.apache.org>.
Github user muratsu commented on a diff in the pull request:

    https://github.com/apache/cordova-medic/pull/47#discussion_r29369965
  
    --- Diff: bin/lib/couchdb.js ---
    @@ -0,0 +1,151 @@
    +
    +/*
    +Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
    +
    +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.
    +*/
    --- End diff --
    
    is this an external lib? header license looks different


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-medic pull request: [CB-8870] Consolidating medic code.

Posted by nikhilkh <gi...@git.apache.org>.
Github user nikhilkh commented on a diff in the pull request:

    https://github.com/apache/cordova-medic/pull/47#discussion_r29375447
  
    --- Diff: bin/medic.js ---
    @@ -39,9 +65,109 @@ var argv = optimist
         .argv;
     
     // helpers
    +function killTasks(taskNames) {
    +
    +    if (!taskNames || taskNames.length < 1) {
    +        console.warn("no tasks to kill");
    +        return;
    +    }
    +
    +    if (isWindows()) {
    +        var cli  = "taskkill /F";
    +        var args = taskNames.map(function (name) { return "/IM \"" + name + "\""; });
    +    } else {
    +        var cli  = "killall";
    +        var args = taskNames.map(function (name) { return "\"" + name + "\""; });
    +    }
    +
    +    var command = cli + " " + args.join(" ");
    +    medicLog("running the following command:");
    +    medicLog("    " + command);
    +
    +    shelljs.exec(command, {silent: false, async: true}, function (returnCode, output) {
    +        if (returnCode !== 0) {
    +            console.warn("WARNING: kill command returned " + returnCode);
    --- End diff --
    
    Does it make sense to print the output also here - along with the return code?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-medic pull request: [CB-8870] Consolidating medic code.

Posted by nikhilkh <gi...@git.apache.org>.
Github user nikhilkh commented on a diff in the pull request:

    https://github.com/apache/cordova-medic/pull/47#discussion_r29376101
  
    --- Diff: bin/medic.js ---
    @@ -55,6 +181,210 @@ function exclusiveLs(lsPath, excludes) {
         });
     }
     
    +function getConfigPath(appPath) {
    +    return path.join(appPath, "config.xml");
    +}
    +
    +function getCSPPath(appPath) {
    +    return path.join(appPath, "www", "csp-incl.js");
    +}
    +
    +function addURIToWhitelist(appPath, uri) {
    +
    +    var configFile = getConfigPath(appPath);
    +    var cspFile    = getCSPPath(appPath);
    +
    +    var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING);
    +    var cspContent    = fs.readFileSync(cspFile, DEFAULT_ENCODING);
    +
    +    // add whitelisting rule allow access to couch server
    +    medicLog("Adding whitelist rule for CouchDB host: " + uri);
    +    var accessOriginTag = "<access origin=\"" + uri + "\" />";
    +    if (!contains(configContent, accessOriginTag)) {
    +        configContent = configContent.split("</widget>").join("");
    +        configContent += "    " + accessOriginTag + "\n</widget>\n";
    +        fs.writeFileSync(configFile, configContent, DEFAULT_ENCODING);
    +    }
    +
    +    // add couchdb address to csp rules
    +    medicLog("Adding CSP rule for CouchDB host: " + uri);
    +    var cspRule = "connect-src " + uri;
    +    if (!contains(cspContent, cspRule)) {
    +        cspContent = cspContent.replace("connect-src", cspRule);
    +        fs.writeFileSync(cspFile, cspContent, DEFAULT_ENCODING);
    +    }
    +}
    +
    +function setEntryPoint(appPath, entryPoint) {
    +
    +    var configFile = getConfigPath(appPath);
    +    var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING);
    +
    +    // replace/add start page preference
    +    // check if config.xml already contains <content /> element
    +    medicLog("Setting entry point to " + entryPoint + " in config.xml");
    +
    +    if (configContent.match(/<content\s*src=".*"\s*\/>/gi)) {
    +        configContent = configContent.replace(
    +            /<content\s*src=".*"\s*\/>/gi,
    +            "<content src=\"" + entryPoint + "\" />"
    +        );
    +
    +    } else {
    +
    +        // add entry point to config
    +        configContent = configContent.split("</widget>").join("") +
    +            "    <content src=\"" + entryPoint + "\" />\n</widget>";
    +    }
    +
    +    // write the changes
    +    fs.writeFileSync(configFile, configContent, DEFAULT_ENCODING);
    +}
    +
    +function changeLoadTimeout(appPath, timeout) {
    +
    +    medicLog("Increasing url loading timeout for android to " + timeout);
    +
    +    var timeoutRegex           = /<preference\s*name\s *= \s*"?loadUrlTimeoutValue"?.*?((\/>)|(>.*?<\/\s*preference>))/i;
    +    var timeoutTag             = "<preference name=\"loadUrlTimeoutValue\" value=\"" + timeout + "\" />";
    +    var timeoutTagWithPlatform = "    <platform name=\"android\">\n        <preference name=\"loadUrlTimeoutValue\" value=\"120000\" />\n    </platform>\n";
    +    var platformRegex          = /<platform\s*name\s *= \s*"android"\s*>/i;
    +    var widgetRegex            = /<\/s*widget\s*>/i;
    +
    +    var configFile    = getConfigPath(appPath);
    +    var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING);
    +
    +    if (timeoutRegex.test(configContent)) {
    +        configContent = configContent.replace(timeoutRegex, timeoutTag);
    +        medicLog("Found \"loadUrlTimeoutValue\" preference, replacing with desired value");
    +    } else if (platformRegex.test(configContent)) {
    +        var oldPlatformTag = platformRegex.exec(configContent)[0];
    +        configContent = configContent.replace(platformRegex, oldPlatformTag + "\n        " + timeoutTag);
    +        medicLog("Found platform tag, appending \"loadUrlTimeoutValue\" preference");
    +    } else if (widgetRegex.test(configContent)) {
    +        var oldWidgetTag = widgetRegex.exec(configContent)[0];
    +        configContent = configContent.replace(widgetRegex, timeoutTagWithPlatform + oldWidgetTag);
    +        medicLog("Did not find platform tag, adding preference with platform tag");
    +    } else {
    +        medicLog("Warning: could not modify config.xml for android: no <widget> tag found!");
    +    }
    +
    +    // write the changes
    +    fs.writeFileSync(configFile, configContent, DEFAULT_ENCODING);
    +}
    +
    +function setWindowsTargetStoreVersion(appPath, version) {
    +
    +    medicLog('setting target store version to ' + version);
    +
    +    var configFile    = getConfigPath(appPath);
    +    var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING);
    +
    +    var versionPreference = '    <preference name="windows-target-version" value="' + version + '" />';
    +    configContent = configContent.replace('</widget>', versionPreference + '\r\n</widget>');
    +
    +    fs.writeFileSync(configFile, configContent, "utf8");
    +}
    +
    +function androidSpecifics(argv) {
    --- End diff --
    
    +1 Please provide meaningful names.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-medic pull request: [CB-8870] Consolidating medic code.

Posted by robpaveza <gi...@git.apache.org>.
Github user robpaveza commented on a diff in the pull request:

    https://github.com/apache/cordova-medic/pull/47#discussion_r29370291
  
    --- Diff: bin/medic.js ---
    @@ -39,9 +65,109 @@ var argv = optimist
         .argv;
     
     // helpers
    +function killTasks(taskNames) {
    +
    +    if (!taskNames || taskNames.length < 1) {
    +        console.warn("no tasks to kill");
    --- End diff --
    
    No tasks seems to equal success case.  If truly a usage error, throw, but otherwise this seems unnecessarily chatty.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-medic pull request: [CB-8870] Consolidating medic code.

Posted by robpaveza <gi...@git.apache.org>.
Github user robpaveza commented on a diff in the pull request:

    https://github.com/apache/cordova-medic/pull/47#discussion_r29370199
  
    --- Diff: bin/medic.js ---
    @@ -19,18 +19,44 @@
      * under the License.
      */
     
    -"use strict";
    +/* jshint node: true */
    +
    +// "use strict";
     
     // node dependencies
    -var fs = require("fs");
    -var os = require("os");
    +var fs   = require("fs");
    +var os   = require("os");
    +var path = require("path");
     
     // external dependencies
     var shelljs  = require("shelljs");
     var optimist = require("optimist");
     
    +// internal dependencies
    +var testwait  = require("./lib/testwait");
    +var testcheck = require("./lib/testcheck");
    +
     // constants
    -var MAX_REMOVAL_ATTEMPTS = 3;
    +var MAX_REMOVAL_ATTEMPTS    = 3;
    +var CORDOVA_MEDIC_DIR       = "cordova-medic";
    +var DEFAULT_APP_PATH        = "mobilespec";
    +var DEFAULT_APP_ENTRY       = "index.html";
    +var ANDROID_TIMEOUT         = 120000;
    --- End diff --
    
    Android timeout is really, really long if minute is 60...  Maybe rewrite ANDROID_TIMEOUT in context of ONE_MINUTE?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-medic pull request: [CB-8870] Consolidating medic code.

Posted by robpaveza <gi...@git.apache.org>.
Github user robpaveza commented on a diff in the pull request:

    https://github.com/apache/cordova-medic/pull/47#discussion_r29370995
  
    --- Diff: bin/medic.js ---
    @@ -39,9 +65,109 @@ var argv = optimist
         .argv;
     
     // helpers
    +function killTasks(taskNames) {
    +
    +    if (!taskNames || taskNames.length < 1) {
    +        console.warn("no tasks to kill");
    +        return;
    +    }
    +
    +    if (isWindows()) {
    +        var cli  = "taskkill /F";
    +        var args = taskNames.map(function (name) { return "/IM \"" + name + "\""; });
    +    } else {
    +        var cli  = "killall";
    +        var args = taskNames.map(function (name) { return "\"" + name + "\""; });
    +    }
    +
    +    var command = cli + " " + args.join(" ");
    +    medicLog("running the following command:");
    +    medicLog("    " + command);
    +
    +    shelljs.exec(command, {silent: false, async: true}, function (returnCode, output) {
    +        if (returnCode !== 0) {
    +            console.warn("WARNING: kill command returned " + returnCode);
    +        }
    +    });
    +}
    +
     function fatal(message) {
    -    console.error("ERROR: " + message);
    -    process.exit(1);
    +    console.error("FATAL: " + message);
    +    process.exit(ERROR);
    +}
    +
    +function medicLog(message) {
    +    console.log("\033[32m[MEDIC LOG]\033[m " + message);
    +}
    +
    +function currentMillisecond() {
    +    // NOTE:
    +    //      coercing a Date to a Number returns
    +    //      the Date's representation in milliseconds
    +    return Number(new Date());
    +}
    +
    +function generateBuildID() {
    +    var components = [MEDIC_BUILD_PREFIX, currentMillisecond()];
    +    return components.join("-");
    +}
    +
    +function tasksOnPlatform(platformName) {
    +    switch (platformName) {
    +        case WINDOWS:
    +            return ["WWAHost.exe"];
    +        case WP8:
    +            return ["Xde.exe"];
    +        case IOS:
    +            return ["iOS Simulator"];
    +        case ANDROID:
    +            if (isWindows()) {
    +                return ["emulator-arm.exe", "adb.exe"];
    +            } else {
    +                return ["emulator64-x86"];
    +            }
    +        case BLACKBERRY:
    +            return [];
    +        default:
    +            fatal("unknown platform " + platformName);
    +    }
    +}
    +
    +function cloneProject(projectName, projectsConfig) {
    +
    +    var project  = projectsConfig[projectName];
    +    var codebase = project.codebases[project.codebase];
    +    var command  = "git clone " + codebase.repo + " --branch=" + codebase.branch + " --depth 1"
    +
    +    shelljs.exec(command, {silent: false, async: true}, function (returnCode, output) {
    +        if (returnCode !== 0) {
    +            fatal("command \"" + command + "\" failed with code " + returnCode);
    +        }
    +    });
    +}
    +
    +function createMedicJson(appPath, buildId, couchdbURI) {
    +
    +    medicLog("Writing medic.json to " + appPath);
    +    medicLog("    sha:     " + buildId);
    +    medicLog("    couchdb: " + couchdbURI);
    +
    +    // NOTE:
    +    //      the "sha" name is a misnomer, but is kept
    +    //      to be compatible with plugin-test-framework
    +    var medicConfig = {
    +        sha:     buildId,
    +        couchdb: couchdbURI
    +    };
    +
    +    var medicConfigContents = JSON.stringify(medicConfig) + "\n";
    +    var medicConfigPath     = path.join(appPath, "www", "medic.json");
    +
    +    fs.writeFileSync(medicConfigPath, medicConfigContents, DEFAULT_ENCODING);
    +}
    +
    +function isWindows() {
    +    return /^win/.test(os.platform());
    --- End diff --
    
    Why assert at the beginning of the string?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-medic pull request: [CB-8870] Consolidating medic code.

Posted by dblotsky <gi...@git.apache.org>.
Github user dblotsky commented on a diff in the pull request:

    https://github.com/apache/cordova-medic/pull/47#discussion_r29374599
  
    --- Diff: bin/lib/couchdb.js ---
    @@ -0,0 +1,151 @@
    +
    +/*
    +Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
    +
    +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.
    +*/
    --- End diff --
    
    Nope, it's just the license this file had. It's this file: https://github.com/apache/cordova-medic/blob/master/src/couchdb/interface.js. What should the license be?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-medic pull request: [CB-8870] Consolidating medic code.

Posted by robpaveza <gi...@git.apache.org>.
Github user robpaveza commented on a diff in the pull request:

    https://github.com/apache/cordova-medic/pull/47#discussion_r29371466
  
    --- Diff: bin/medic.js ---
    @@ -55,6 +181,210 @@ function exclusiveLs(lsPath, excludes) {
         });
     }
     
    +function getConfigPath(appPath) {
    +    return path.join(appPath, "config.xml");
    +}
    +
    +function getCSPPath(appPath) {
    +    return path.join(appPath, "www", "csp-incl.js");
    +}
    +
    +function addURIToWhitelist(appPath, uri) {
    +
    +    var configFile = getConfigPath(appPath);
    +    var cspFile    = getCSPPath(appPath);
    +
    +    var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING);
    +    var cspContent    = fs.readFileSync(cspFile, DEFAULT_ENCODING);
    +
    +    // add whitelisting rule allow access to couch server
    +    medicLog("Adding whitelist rule for CouchDB host: " + uri);
    +    var accessOriginTag = "<access origin=\"" + uri + "\" />";
    +    if (!contains(configContent, accessOriginTag)) {
    +        configContent = configContent.split("</widget>").join("");
    +        configContent += "    " + accessOriginTag + "\n</widget>\n";
    +        fs.writeFileSync(configFile, configContent, DEFAULT_ENCODING);
    +    }
    +
    +    // add couchdb address to csp rules
    +    medicLog("Adding CSP rule for CouchDB host: " + uri);
    +    var cspRule = "connect-src " + uri;
    +    if (!contains(cspContent, cspRule)) {
    +        cspContent = cspContent.replace("connect-src", cspRule);
    +        fs.writeFileSync(cspFile, cspContent, DEFAULT_ENCODING);
    +    }
    +}
    +
    +function setEntryPoint(appPath, entryPoint) {
    +
    +    var configFile = getConfigPath(appPath);
    +    var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING);
    +
    +    // replace/add start page preference
    +    // check if config.xml already contains <content /> element
    +    medicLog("Setting entry point to " + entryPoint + " in config.xml");
    +
    +    if (configContent.match(/<content\s*src=".*"\s*\/>/gi)) {
    +        configContent = configContent.replace(
    +            /<content\s*src=".*"\s*\/>/gi,
    +            "<content src=\"" + entryPoint + "\" />"
    +        );
    +
    +    } else {
    +
    +        // add entry point to config
    +        configContent = configContent.split("</widget>").join("") +
    +            "    <content src=\"" + entryPoint + "\" />\n</widget>";
    +    }
    +
    +    // write the changes
    +    fs.writeFileSync(configFile, configContent, DEFAULT_ENCODING);
    +}
    +
    +function changeLoadTimeout(appPath, timeout) {
    +
    +    medicLog("Increasing url loading timeout for android to " + timeout);
    +
    +    var timeoutRegex           = /<preference\s*name\s *= \s*"?loadUrlTimeoutValue"?.*?((\/>)|(>.*?<\/\s*preference>))/i;
    +    var timeoutTag             = "<preference name=\"loadUrlTimeoutValue\" value=\"" + timeout + "\" />";
    +    var timeoutTagWithPlatform = "    <platform name=\"android\">\n        <preference name=\"loadUrlTimeoutValue\" value=\"120000\" />\n    </platform>\n";
    +    var platformRegex          = /<platform\s*name\s *= \s*"android"\s*>/i;
    +    var widgetRegex            = /<\/s*widget\s*>/i;
    +
    +    var configFile    = getConfigPath(appPath);
    +    var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING);
    +
    +    if (timeoutRegex.test(configContent)) {
    +        configContent = configContent.replace(timeoutRegex, timeoutTag);
    +        medicLog("Found \"loadUrlTimeoutValue\" preference, replacing with desired value");
    +    } else if (platformRegex.test(configContent)) {
    +        var oldPlatformTag = platformRegex.exec(configContent)[0];
    +        configContent = configContent.replace(platformRegex, oldPlatformTag + "\n        " + timeoutTag);
    +        medicLog("Found platform tag, appending \"loadUrlTimeoutValue\" preference");
    +    } else if (widgetRegex.test(configContent)) {
    +        var oldWidgetTag = widgetRegex.exec(configContent)[0];
    +        configContent = configContent.replace(widgetRegex, timeoutTagWithPlatform + oldWidgetTag);
    +        medicLog("Did not find platform tag, adding preference with platform tag");
    +    } else {
    +        medicLog("Warning: could not modify config.xml for android: no <widget> tag found!");
    +    }
    +
    +    // write the changes
    +    fs.writeFileSync(configFile, configContent, DEFAULT_ENCODING);
    +}
    +
    +function setWindowsTargetStoreVersion(appPath, version) {
    +
    +    medicLog('setting target store version to ' + version);
    +
    +    var configFile    = getConfigPath(appPath);
    +    var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING);
    +
    +    var versionPreference = '    <preference name="windows-target-version" value="' + version + '" />';
    +    configContent = configContent.replace('</widget>', versionPreference + '\r\n</widget>');
    +
    +    fs.writeFileSync(configFile, configContent, "utf8");
    +}
    +
    +function androidSpecifics(argv) {
    --- End diff --
    
    Your "(platform)Specifics" functions don't really indicate what it is they do by their names.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-medic pull request: [CB-8870] Consolidating medic code.

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/cordova-medic/pull/47


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-medic pull request: [CB-8870] Consolidating medic code.

Posted by robpaveza <gi...@git.apache.org>.
Github user robpaveza commented on a diff in the pull request:

    https://github.com/apache/cordova-medic/pull/47#discussion_r29371130
  
    --- Diff: bin/medic.js ---
    @@ -55,6 +181,210 @@ function exclusiveLs(lsPath, excludes) {
         });
     }
     
    +function getConfigPath(appPath) {
    +    return path.join(appPath, "config.xml");
    +}
    +
    +function getCSPPath(appPath) {
    +    return path.join(appPath, "www", "csp-incl.js");
    +}
    +
    +function addURIToWhitelist(appPath, uri) {
    +
    +    var configFile = getConfigPath(appPath);
    +    var cspFile    = getCSPPath(appPath);
    +
    +    var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING);
    +    var cspContent    = fs.readFileSync(cspFile, DEFAULT_ENCODING);
    +
    +    // add whitelisting rule allow access to couch server
    +    medicLog("Adding whitelist rule for CouchDB host: " + uri);
    +    var accessOriginTag = "<access origin=\"" + uri + "\" />";
    +    if (!contains(configContent, accessOriginTag)) {
    +        configContent = configContent.split("</widget>").join("");
    +        configContent += "    " + accessOriginTag + "\n</widget>\n";
    +        fs.writeFileSync(configFile, configContent, DEFAULT_ENCODING);
    +    }
    +
    +    // add couchdb address to csp rules
    +    medicLog("Adding CSP rule for CouchDB host: " + uri);
    +    var cspRule = "connect-src " + uri;
    +    if (!contains(cspContent, cspRule)) {
    +        cspContent = cspContent.replace("connect-src", cspRule);
    +        fs.writeFileSync(cspFile, cspContent, DEFAULT_ENCODING);
    +    }
    +}
    +
    +function setEntryPoint(appPath, entryPoint) {
    +
    +    var configFile = getConfigPath(appPath);
    +    var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING);
    +
    +    // replace/add start page preference
    +    // check if config.xml already contains <content /> element
    +    medicLog("Setting entry point to " + entryPoint + " in config.xml");
    +
    +    if (configContent.match(/<content\s*src=".*"\s*\/>/gi)) {
    +        configContent = configContent.replace(
    +            /<content\s*src=".*"\s*\/>/gi,
    +            "<content src=\"" + entryPoint + "\" />"
    +        );
    +
    +    } else {
    +
    +        // add entry point to config
    +        configContent = configContent.split("</widget>").join("") +
    +            "    <content src=\"" + entryPoint + "\" />\n</widget>";
    +    }
    +
    +    // write the changes
    +    fs.writeFileSync(configFile, configContent, DEFAULT_ENCODING);
    +}
    +
    +function changeLoadTimeout(appPath, timeout) {
    +
    +    medicLog("Increasing url loading timeout for android to " + timeout);
    +
    +    var timeoutRegex           = /<preference\s*name\s *= \s*"?loadUrlTimeoutValue"?.*?((\/>)|(>.*?<\/\s*preference>))/i;
    --- End diff --
    
    Searching SGML-type languages with regex is gross.  Did you consider using a lib like ElementTree instead?  That would probably make your code a lot cleaner, to find elements via xpath.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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