{"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/TACO/pulls/comments/47955960","id":47955960,"diff_hunk":"@@ -123,13 +124,98 @@ class Builder {\n             fs.mkdirSync(\"platforms\");\n         }\n \n+        return this.ensurePlatformAdded().then((addedPlatform) => {\n+            if (addedPlatform) {\n+                // Note that \"cordova platform add\" eventually calls \"cordova prepare\" internally, which is why we don't invoke prepare ourselves when we add the platform.\n+                return Q({});\n+            }\n+\n+            return this.update_platform();\n+        });\n+    }\n+\n+    /**\n+     * Adds the platform if it isn't already present, or removes and re-adds it if the project Cordova version changed, or config.xml has a saved platform version that differs from the installed one.\n+     * Returns true if the platform was added, false if not.\n+     */\n+    private ensurePlatformAdded(): Q.Promise<boolean> {\n         if (!fs.existsSync(path.join(\"platforms\", this.currentBuild.buildPlatform))) {\n             Logger.log(\"cordova platform add \" + this.currentBuild.buildPlatform);\n+\n             // Note that \"cordova platform add\" eventually calls \"cordova prepare\" internally, which is why we don't invoke prepare ourselves when we add the platform.\n-            return this.cordova.raw.platform(\"add\", this.currentBuild.buildPlatform);\n-        } else {\n-            return this.update_platform();\n+            return this.cordova.raw.platform(\"add\", this.currentBuild.buildPlatform).then(() => {\n+                return Q(true);\n+            });\n+        }\n+\n+        var xmlVersion: string = this.getConfigXmlPlatformVersion();\n+\n+        return this.getCurrentPlatformVersion().then((installedVersion: string) => {\n+            if (xmlVersion) {\n+                if (semver.neq(xmlVersion, installedVersion)) {\n+                    // There is a version of the platform specified in xonfig.xml, and it differs from the installed version\n+                    return true;\n+                } else {\n+                    // The version specified in config.xml is already installed, we don't need to re-add the platform\n+                    return false;\n+                }\n+            } else {\n+                // Check if the Cordova version has changed\n+                if (this.currentBuild[\"previousvcordova\"] && semver.neq(this.currentBuild[\"vcordova\"], this.currentBuild[\"previousvcordova\"])) {\n+                    // Cordova version has changed\n+                    return true;\n+                }\n+\n+                // Cordova version hasn't changed\n+                return false;\n+            }\n+        }, (err) => {\n+            // If we couldn't extract the platform's version, then remove and re-add it anyway, to be safe\n+            return true;\n+        }).then((mustReAdd: boolean) => {\n+            if (!mustReAdd) {\n+                return Q(false);\n+            } else {\n+                Logger.log(\"cordova platform remove \" + this.currentBuild.buildPlatform);\n+\n+                return this.cordova.raw.platform(\"remove\", this.currentBuild.buildPlatform).then(() => {\n+                    Logger.log(\"cordova platform add \" + this.currentBuild.buildPlatform);\n+\n+                    return this.cordova.raw.platform(\"add\", this.currentBuild.buildPlatform);\n+                }).then(() => {\n+                    return Q(true);\n+                });\n+            }\n+        });\n+    }\n+\n+    private getConfigXmlPlatformVersion(): string {\n+        var engines: {[key: string]: string} = utils.CordovaConfig.getCordovaConfig(this.currentBuild.appDir).engines();\n+\n+        if (engines[this.currentBuild.buildPlatform]) {\n+            return engines[this.currentBuild.buildPlatform];\n+        }\n+\n+        return \"\";\n+    }\n+\n+    private getCurrentPlatformVersion(): Q.Promise<string> {\n+        var deferred: Q.Deferred<string> = Q.defer<string>();\n+\n+        var resolvePlatformOutput: Function = (output: string) => {\n+            var versionRegexp: RegExp = new RegExp(util.format(\"%s (.*?)(?:,|$)\", this.currentBuild.buildPlatform), \"m\");\n+            var installedPlatformVersion: string = versionRegexp.exec(output)[1];","path":"src/taco-remote-lib/common/builder.ts","position":97,"original_position":97,"commit_id":"77ad8a97665df4f28a97c22e67a2e3a6bdf0419c","original_commit_id":"77ad8a97665df4f28a97c22e67a2e3a6bdf0419c","user":{"login":"guillaumejenkins","id":14299377,"avatar_url":"https://avatars.githubusercontent.com/u/14299377?v=3","gravatar_id":"","url":"https://api.github.com/users/guillaumejenkins","html_url":"https://github.com/guillaumejenkins","followers_url":"https://api.github.com/users/guillaumejenkins/followers","following_url":"https://api.github.com/users/guillaumejenkins/following{/other_user}","gists_url":"https://api.github.com/users/guillaumejenkins/gists{/gist_id}","starred_url":"https://api.github.com/users/guillaumejenkins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guillaumejenkins/subscriptions","organizations_url":"https://api.github.com/users/guillaumejenkins/orgs","repos_url":"https://api.github.com/users/guillaumejenkins/repos","events_url":"https://api.github.com/users/guillaumejenkins/events{/privacy}","received_events_url":"https://api.github.com/users/guillaumejenkins/received_events","type":"User","site_admin":false},"body":"Actually I'll change this to execute the version script in platformRoot/cordova/version, so none of this will be needed","created_at":"2015-12-17T20:20:59Z","updated_at":"2015-12-17T20:20:59Z","html_url":"https://github.com/Microsoft/TACO/pull/222#discussion_r47955960","pull_request_url":"https://api.github.com/repos/Microsoft/TACO/pulls/222","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TACO/pulls/comments/47955960"},"html":{"href":"https://github.com/Microsoft/TACO/pull/222#discussion_r47955960"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/TACO/pulls/222"}}},"pull_request":{"url":"https://api.github.com/repos/Microsoft/TACO/pulls/222","id":53901176,"html_url":"https://github.com/Microsoft/TACO/pull/222","diff_url":"https://github.com/Microsoft/TACO/pull/222.diff","patch_url":"https://github.com/Microsoft/TACO/pull/222.patch","issue_url":"https://api.github.com/repos/Microsoft/TACO/issues/222","number":222,"state":"open","locked":false,"title":"Remotebuild: Handle client Cordova version changes for incremental builds","user":{"login":"guillaumejenkins","id":14299377,"avatar_url":"https://avatars.githubusercontent.com/u/14299377?v=3","gravatar_id":"","url":"https://api.github.com/users/guillaumejenkins","html_url":"https://github.com/guillaumejenkins","followers_url":"https://api.github.com/users/guillaumejenkins/followers","following_url":"https://api.github.com/users/guillaumejenkins/following{/other_user}","gists_url":"https://api.github.com/users/guillaumejenkins/gists{/gist_id}","starred_url":"https://api.github.com/users/guillaumejenkins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guillaumejenkins/subscriptions","organizations_url":"https://api.github.com/users/guillaumejenkins/orgs","repos_url":"https://api.github.com/users/guillaumejenkins/repos","events_url":"https://api.github.com/users/guillaumejenkins/events{/privacy}","received_events_url":"https://api.github.com/users/guillaumejenkins/received_events","type":"User","site_admin":false},"body":"This is an early pull request for early feedback, I haven't tested thoroughly enough","created_at":"2015-12-16T21:30:02Z","updated_at":"2015-12-17T20:20:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5af28851bcc51df4fe00aae461c238ed1ebaddd1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/TACO/pulls/222/commits","review_comments_url":"https://api.github.com/repos/Microsoft/TACO/pulls/222/comments","review_comment_url":"https://api.github.com/repos/Microsoft/TACO/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Microsoft/TACO/issues/222/comments","statuses_url":"https://api.github.com/repos/Microsoft/TACO/statuses/77ad8a97665df4f28a97c22e67a2e3a6bdf0419c","head":{"label":"Microsoft:remote-handle-cordova-change","ref":"remote-handle-cordova-change","sha":"77ad8a97665df4f28a97c22e67a2e3a6bdf0419c","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":41325355,"name":"TACO","full_name":"Microsoft/TACO","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/TACO","description":"Tools for Apache Cordova","fork":false,"url":"https://api.github.com/repos/Microsoft/TACO","forks_url":"https://api.github.com/repos/Microsoft/TACO/forks","keys_url":"https://api.github.com/repos/Microsoft/TACO/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/TACO/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/TACO/teams","hooks_url":"https://api.github.com/repos/Microsoft/TACO/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/TACO/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/TACO/events","assignees_url":"https://api.github.com/repos/Microsoft/TACO/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/TACO/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/TACO/tags","blobs_url":"https://api.github.com/repos/Microsoft/TACO/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/TACO/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/TACO/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/TACO/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/TACO/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/TACO/languages","stargazers_url":"https://api.github.com/repos/Microsoft/TACO/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/TACO/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/TACO/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/TACO/subscription","commits_url":"https://api.github.com/repos/Microsoft/TACO/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/TACO/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/TACO/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/TACO/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/TACO/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/TACO/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/TACO/merges","archive_url":"https://api.github.com/repos/Microsoft/TACO/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/TACO/downloads","issues_url":"https://api.github.com/repos/Microsoft/TACO/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/TACO/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/TACO/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/TACO/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/TACO/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/TACO/releases{/id}","created_at":"2015-08-24T20:26:25Z","updated_at":"2015-12-16T16:10:45Z","pushed_at":"2015-12-17T18:17:47Z","git_url":"git://github.com/Microsoft/TACO.git","ssh_url":"git@github.com:Microsoft/TACO.git","clone_url":"https://github.com/Microsoft/TACO.git","svn_url":"https://github.com/Microsoft/TACO","homepage":null,"size":6849,"stargazers_count":121,"watchers_count":121,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":18,"mirror_url":null,"open_issues_count":9,"forks":18,"open_issues":9,"watchers":121,"default_branch":"master"}},"base":{"label":"Microsoft:master","ref":"master","sha":"c6e907edb2c9df6a609af675c9fae17cae7c5732","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":41325355,"name":"TACO","full_name":"Microsoft/TACO","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/TACO","description":"Tools for Apache Cordova","fork":false,"url":"https://api.github.com/repos/Microsoft/TACO","forks_url":"https://api.github.com/repos/Microsoft/TACO/forks","keys_url":"https://api.github.com/repos/Microsoft/TACO/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/TACO/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/TACO/teams","hooks_url":"https://api.github.com/repos/Microsoft/TACO/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/TACO/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/TACO/events","assignees_url":"https://api.github.com/repos/Microsoft/TACO/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/TACO/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/TACO/tags","blobs_url":"https://api.github.com/repos/Microsoft/TACO/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/TACO/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/TACO/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/TACO/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/TACO/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/TACO/languages","stargazers_url":"https://api.github.com/repos/Microsoft/TACO/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/TACO/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/TACO/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/TACO/subscription","commits_url":"https://api.github.com/repos/Microsoft/TACO/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/TACO/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/TACO/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/TACO/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/TACO/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/TACO/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/TACO/merges","archive_url":"https://api.github.com/repos/Microsoft/TACO/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/TACO/downloads","issues_url":"https://api.github.com/repos/Microsoft/TACO/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/TACO/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/TACO/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/TACO/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/TACO/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/TACO/releases{/id}","created_at":"2015-08-24T20:26:25Z","updated_at":"2015-12-16T16:10:45Z","pushed_at":"2015-12-17T18:17:47Z","git_url":"git://github.com/Microsoft/TACO.git","ssh_url":"git@github.com:Microsoft/TACO.git","clone_url":"https://github.com/Microsoft/TACO.git","svn_url":"https://github.com/Microsoft/TACO","homepage":null,"size":6849,"stargazers_count":121,"watchers_count":121,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":18,"mirror_url":null,"open_issues_count":9,"forks":18,"open_issues":9,"watchers":121,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TACO/pulls/222"},"html":{"href":"https://github.com/Microsoft/TACO/pull/222"},"issue":{"href":"https://api.github.com/repos/Microsoft/TACO/issues/222"},"comments":{"href":"https://api.github.com/repos/Microsoft/TACO/issues/222/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/TACO/pulls/222/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/TACO/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/TACO/pulls/222/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/TACO/statuses/77ad8a97665df4f28a97c22e67a2e3a6bdf0419c"}}}}