{"action":"created","comment":{"url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/pulls/comments/61621039","id":61621039,"diff_hunk":"@@ -247,15 +241,72 @@ public void run(@NotNull ProgressIndicator indicator) {\n \n   }\n \n-  private String parseDeployOutputToModule(String jsonOutput)\n+  // Just to return two strings.\n+  static private class VersionService {\n+    public String version = null;\n+    public String service = null;\n+  }\n+\n+  private VersionService parseDeployOutputToModule(String jsonOutput)\n       throws JsonParseException {\n-    Type deployOutputType = new TypeToken<Map<String, String>>() {}.getType();\n-    Map<String, String> deployOutput = new Gson().fromJson(jsonOutput, deployOutputType);\n+    VersionService versionService = new VersionService();\n+\n+    /* An example JSON output of gcloud app deloy:\n+        {\n+          \"configs\": [],\n+          \"versions\": [\n+            {\n+              \"id\": \"20160429t112518\",\n+              \"last_deployed_time\": null,\n+              \"project\": \"springboot-maven-project\",\n+              \"service\": \"default\",\n+              \"traffic_split\": null,\n+              \"version\": null\n+            }\n+          ]\n+        }\n+    */\n \n-    if(deployOutput == null || deployOutput.keySet().size() != 1) {\n-      throw new AssertionError(\"Expected a single module output from flex deployment.\");\n+    JsonReader reader = new JsonReader(new StringReader(jsonOutput));\n+    try {\n+      reader.beginObject(); // Top-level is a single object.\n+\n+      // Look for \"versions\" in the top-level object.\n+      while (reader.hasNext()) {\n+        String name = reader.nextName();\n+\n+        if (\"versions\".equals(name) && reader.peek() != JsonToken.NULL) {\n+          reader.beginArray(); // \"versions\" should be an array.\n+          // We hope the array has an element.\n+          if (reader.hasNext()) {\n+            reader.beginObject(); // An element in \"versions\" should be an object.\n+\n+            // Look for \"id\" and \"service\" inside the element.\n+            while (reader.hasNext()) {\n+              String nested_name = reader.nextName();\n+              if (\"id\".equals(nested_name)) {\n+                versionService.version = reader.nextString(); // \"id\" found. (String)\n+              } else if (\"service\".equals(nested_name)) {\n+                versionService.service = reader.nextString(); // \"service\" found. (String)\n+              } else {\n+                reader.skipValue(); // Skip a value if not \"id\".\n+              }\n+            }\n+            reader.endObject();","path":"google-cloud-tools-plugin/src/com/google/cloud/tools/intellij/appengine/cloud/AppEngineDeployAction.java","position":180,"original_position":180,"commit_id":"a61a4d8d9bfe389db94b0d54cb688c543656bb25","original_commit_id":"a61a4d8d9bfe389db94b0d54cb688c543656bb25","user":{"login":"chanseokoh","id":10523105,"avatar_url":"https://avatars.githubusercontent.com/u/10523105?v=3","gravatar_id":"","url":"https://api.github.com/users/chanseokoh","html_url":"https://github.com/chanseokoh","followers_url":"https://api.github.com/users/chanseokoh/followers","following_url":"https://api.github.com/users/chanseokoh/following{/other_user}","gists_url":"https://api.github.com/users/chanseokoh/gists{/gist_id}","starred_url":"https://api.github.com/users/chanseokoh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chanseokoh/subscriptions","organizations_url":"https://api.github.com/users/chanseokoh/orgs","repos_url":"https://api.github.com/users/chanseokoh/repos","events_url":"https://api.github.com/users/chanseokoh/events{/privacy}","received_events_url":"https://api.github.com/users/chanseokoh/received_events","type":"User","site_admin":false},"body":"I feel like this will fail if \"versions\" contain multiple elements. I will need to fix this.","created_at":"2016-04-29T18:06:06Z","updated_at":"2016-04-29T18:06:06Z","html_url":"https://github.com/GoogleCloudPlatform/gcloud-intellij/pull/660#discussion_r61621039","pull_request_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/pulls/660","_links":{"self":{"href":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/pulls/comments/61621039"},"html":{"href":"https://github.com/GoogleCloudPlatform/gcloud-intellij/pull/660#discussion_r61621039"},"pull_request":{"href":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/pulls/660"}}},"pull_request":{"url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/pulls/660","id":68408536,"html_url":"https://github.com/GoogleCloudPlatform/gcloud-intellij/pull/660","diff_url":"https://github.com/GoogleCloudPlatform/gcloud-intellij/pull/660.diff","patch_url":"https://github.com/GoogleCloudPlatform/gcloud-intellij/pull/660.patch","issue_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/issues/660","number":660,"state":"open","locked":false,"title":"Parse version/service and remove generateVersion()","user":{"login":"chanseokoh","id":10523105,"avatar_url":"https://avatars.githubusercontent.com/u/10523105?v=3","gravatar_id":"","url":"https://api.github.com/users/chanseokoh","html_url":"https://github.com/chanseokoh","followers_url":"https://api.github.com/users/chanseokoh/followers","following_url":"https://api.github.com/users/chanseokoh/following{/other_user}","gists_url":"https://api.github.com/users/chanseokoh/gists{/gist_id}","starred_url":"https://api.github.com/users/chanseokoh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chanseokoh/subscriptions","organizations_url":"https://api.github.com/users/chanseokoh/orgs","repos_url":"https://api.github.com/users/chanseokoh/repos","events_url":"https://api.github.com/users/chanseokoh/events{/privacy}","received_events_url":"https://api.github.com/users/chanseokoh/received_events","type":"User","site_admin":false},"body":"See #655.\r\n\r\nNote that this should not be merged until the internal #120830848 makes to public.\r\n\r\nThis PR\r\n- removes generateVersion()\r\n- parses the JSON output by `gcloud` to get version and service info (this is a bit ugly)\r\n\r\nUnlike JavaScript, parsing JSON in Java was a bit of a pain. Because we don't know the exact format/type of the JSON output and it may change in the future, I took an approach of manually going over each JSON element to try best to extract the version/service info. I wonder if there is a nicer way.\r\n\r\nAn example output:\r\n```json\r\n        {\r\n          \"configs\": [],\r\n          \"versions\": [\r\n            {\r\n              \"id\": \"20160429t112518\",\r\n              \"last_deployed_time\": null,\r\n              \"project\": \"springboot-maven-project\",\r\n              \"service\": \"default\",\r\n              \"traffic_split\": null,\r\n              \"version\": null\r\n            }\r\n          ]\r\n        }\r\n```\r\n\r\nProbably, I should move `parseDeployOutputToModule()` to the `AppEngineHelper` class and write a test.\r\n\r\nTried basic testing, and undeploying (stopping) works correctly.","created_at":"2016-04-29T17:49:34Z","updated_at":"2016-04-29T18:06:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"428e7e5fd695ba3499553b27efe0a92ef2d4ed98","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/pulls/660/commits","review_comments_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/pulls/660/comments","review_comment_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/pulls/comments{/number}","comments_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/issues/660/comments","statuses_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/statuses/a61a4d8d9bfe389db94b0d54cb688c543656bb25","head":{"label":"GoogleCloudPlatform:parse-version-service","ref":"parse-version-service","sha":"a61a4d8d9bfe389db94b0d54cb688c543656bb25","user":{"login":"GoogleCloudPlatform","id":2810941,"avatar_url":"https://avatars.githubusercontent.com/u/2810941?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCloudPlatform","html_url":"https://github.com/GoogleCloudPlatform","followers_url":"https://api.github.com/users/GoogleCloudPlatform/followers","following_url":"https://api.github.com/users/GoogleCloudPlatform/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCloudPlatform/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCloudPlatform/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCloudPlatform/subscriptions","organizations_url":"https://api.github.com/users/GoogleCloudPlatform/orgs","repos_url":"https://api.github.com/users/GoogleCloudPlatform/repos","events_url":"https://api.github.com/users/GoogleCloudPlatform/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCloudPlatform/received_events","type":"Organization","site_admin":false},"repo":{"id":38834157,"name":"gcloud-intellij","full_name":"GoogleCloudPlatform/gcloud-intellij","owner":{"login":"GoogleCloudPlatform","id":2810941,"avatar_url":"https://avatars.githubusercontent.com/u/2810941?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCloudPlatform","html_url":"https://github.com/GoogleCloudPlatform","followers_url":"https://api.github.com/users/GoogleCloudPlatform/followers","following_url":"https://api.github.com/users/GoogleCloudPlatform/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCloudPlatform/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCloudPlatform/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCloudPlatform/subscriptions","organizations_url":"https://api.github.com/users/GoogleCloudPlatform/orgs","repos_url":"https://api.github.com/users/GoogleCloudPlatform/repos","events_url":"https://api.github.com/users/GoogleCloudPlatform/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCloudPlatform/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/GoogleCloudPlatform/gcloud-intellij","description":"Plugin to support the Google Cloud Platform in IntelliJ IDEA.","fork":false,"url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij","forks_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/forks","keys_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/teams","hooks_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/hooks","issue_events_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/issues/events{/number}","events_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/events","assignees_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/assignees{/user}","branches_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/branches{/branch}","tags_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/tags","blobs_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/git/refs{/sha}","trees_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/statuses/{sha}","languages_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/languages","stargazers_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/stargazers","contributors_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/contributors","subscribers_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/subscribers","subscription_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/subscription","commits_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/commits{/sha}","git_commits_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/git/commits{/sha}","comments_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/comments{/number}","issue_comment_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/issues/comments{/number}","contents_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/contents/{+path}","compare_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/merges","archive_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/downloads","issues_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/issues{/number}","pulls_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/pulls{/number}","milestones_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/milestones{/number}","notifications_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/labels{/name}","releases_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/releases{/id}","deployments_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/deployments","created_at":"2015-07-09T17:08:59Z","updated_at":"2016-04-25T20:49:47Z","pushed_at":"2016-04-29T17:55:31Z","git_url":"git://github.com/GoogleCloudPlatform/gcloud-intellij.git","ssh_url":"git@github.com:GoogleCloudPlatform/gcloud-intellij.git","clone_url":"https://github.com/GoogleCloudPlatform/gcloud-intellij.git","svn_url":"https://github.com/GoogleCloudPlatform/gcloud-intellij","homepage":"","size":19437,"stargazers_count":23,"watchers_count":23,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":7,"mirror_url":null,"open_issues_count":50,"forks":7,"open_issues":50,"watchers":23,"default_branch":"master"}},"base":{"label":"GoogleCloudPlatform:master","ref":"master","sha":"04d680e8c4ad1fcb9d4d5a12f94880e54f39409a","user":{"login":"GoogleCloudPlatform","id":2810941,"avatar_url":"https://avatars.githubusercontent.com/u/2810941?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCloudPlatform","html_url":"https://github.com/GoogleCloudPlatform","followers_url":"https://api.github.com/users/GoogleCloudPlatform/followers","following_url":"https://api.github.com/users/GoogleCloudPlatform/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCloudPlatform/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCloudPlatform/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCloudPlatform/subscriptions","organizations_url":"https://api.github.com/users/GoogleCloudPlatform/orgs","repos_url":"https://api.github.com/users/GoogleCloudPlatform/repos","events_url":"https://api.github.com/users/GoogleCloudPlatform/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCloudPlatform/received_events","type":"Organization","site_admin":false},"repo":{"id":38834157,"name":"gcloud-intellij","full_name":"GoogleCloudPlatform/gcloud-intellij","owner":{"login":"GoogleCloudPlatform","id":2810941,"avatar_url":"https://avatars.githubusercontent.com/u/2810941?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCloudPlatform","html_url":"https://github.com/GoogleCloudPlatform","followers_url":"https://api.github.com/users/GoogleCloudPlatform/followers","following_url":"https://api.github.com/users/GoogleCloudPlatform/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCloudPlatform/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCloudPlatform/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCloudPlatform/subscriptions","organizations_url":"https://api.github.com/users/GoogleCloudPlatform/orgs","repos_url":"https://api.github.com/users/GoogleCloudPlatform/repos","events_url":"https://api.github.com/users/GoogleCloudPlatform/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCloudPlatform/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/GoogleCloudPlatform/gcloud-intellij","description":"Plugin to support the Google Cloud Platform in IntelliJ IDEA.","fork":false,"url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij","forks_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/forks","keys_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/teams","hooks_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/hooks","issue_events_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/issues/events{/number}","events_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/events","assignees_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/assignees{/user}","branches_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/branches{/branch}","tags_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/tags","blobs_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/git/refs{/sha}","trees_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/statuses/{sha}","languages_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/languages","stargazers_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/stargazers","contributors_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/contributors","subscribers_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/subscribers","subscription_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/subscription","commits_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/commits{/sha}","git_commits_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/git/commits{/sha}","comments_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/comments{/number}","issue_comment_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/issues/comments{/number}","contents_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/contents/{+path}","compare_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/merges","archive_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/downloads","issues_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/issues{/number}","pulls_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/pulls{/number}","milestones_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/milestones{/number}","notifications_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/labels{/name}","releases_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/releases{/id}","deployments_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/deployments","created_at":"2015-07-09T17:08:59Z","updated_at":"2016-04-25T20:49:47Z","pushed_at":"2016-04-29T17:55:31Z","git_url":"git://github.com/GoogleCloudPlatform/gcloud-intellij.git","ssh_url":"git@github.com:GoogleCloudPlatform/gcloud-intellij.git","clone_url":"https://github.com/GoogleCloudPlatform/gcloud-intellij.git","svn_url":"https://github.com/GoogleCloudPlatform/gcloud-intellij","homepage":"","size":19437,"stargazers_count":23,"watchers_count":23,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":7,"mirror_url":null,"open_issues_count":50,"forks":7,"open_issues":50,"watchers":23,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/pulls/660"},"html":{"href":"https://github.com/GoogleCloudPlatform/gcloud-intellij/pull/660"},"issue":{"href":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/issues/660"},"comments":{"href":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/issues/660/comments"},"review_comments":{"href":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/pulls/660/comments"},"review_comment":{"href":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/pulls/660/commits"},"statuses":{"href":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-intellij/statuses/a61a4d8d9bfe389db94b0d54cb688c543656bb25"}}}}