{"action":"created","comment":{"url":"https://api.github.com/repos/SonarSource/sonarlint-core/pulls/comments/59236291","id":59236291,"diff_hunk":"@@ -0,0 +1,154 @@\n+/*\n+ * SonarLint Core - Implementation\n+ * Copyright (C) 2009-2016 SonarSource SA\n+ * mailto:contact AT sonarsource DOT com\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU Lesser General Public\n+ * License as published by the Free Software Foundation; either\n+ * version 3 of the License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ * Lesser General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU Lesser General Public License\n+ * along with this program; if not, write to the Free Software Foundation,\n+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\n+ */\n+package org.sonarsource.sonarlint.core.container.connected.validate;\n+\n+import com.google.gson.Gson;\n+import org.apache.commons.lang.StringUtils;\n+import org.sonarqube.ws.client.WsResponse;\n+import org.sonarsource.sonarlint.core.client.api.connected.UnsupportedServerException;\n+import org.sonarsource.sonarlint.core.client.api.connected.ValidationResult;\n+import org.sonarsource.sonarlint.core.container.connected.CloseableWsResponse;\n+import org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient;\n+import org.sonarsource.sonarlint.core.plugin.Version;\n+import org.sonarsource.sonarlint.core.util.VersionUtils;\n+\n+import java.io.IOException;\n+import java.util.LinkedList;\n+import java.util.List;\n+import java.util.Properties;\n+import java.util.Scanner;\n+\n+public class PluginVersionChecker {\n+  public static final String WS_PATH = \"/api/plugins/installed\";\n+  public static final String WS_PATH_LTS = \"/deploy/plugins/index.txt\";\n+  public static final String MIN_VERSIONS_FILE = \"/plugins_min_versions.txt\";\n+\n+  private final SonarLintWsClient wsClient;\n+\n+  public PluginVersionChecker(SonarLintWsClient client) {\n+    this.wsClient = client;\n+  }\n+\n+  public ValidationResult validatePlugins(String serverVersion) {\n+    Version server = Version.create(serverVersion);\n+    Properties props = new Properties();\n+    try {\n+      props.load(this.getClass().getResourceAsStream(MIN_VERSIONS_FILE));\n+    } catch (IOException e) {\n+      throw new IllegalStateException(\"Failed to load minimum plugin versions\", e);\n+    }\n+\n+    List<InstalledPlugin> invalidPlugins;\n+    if (server.compareTo(Version.create(\"5.2\")) >= 0) {\n+      invalidPlugins = after52(props);\n+    } else {\n+      invalidPlugins = before52(props);\n+    }\n+\n+    if (!invalidPlugins.isEmpty()) {\n+      return new DefaultValidationResult(false, buildFailMessage(props, invalidPlugins));\n+    } else {\n+      return new DefaultValidationResult(true, \"Plugins meet required minimum versions\");\n+    }\n+  }\n+\n+  private List<InstalledPlugin> before52(Properties props) {\n+    List<InstalledPlugin> invalidPlugins = new LinkedList<>();\n+\n+    WsResponse response = wsClient.get(WS_PATH_LTS);\n+    String responseStr = response.content();\n+    try (Scanner scanner = new Scanner(responseStr)) {\n+      while (scanner.hasNextLine()) {\n+        String line = scanner.nextLine();\n+        String[] fields = StringUtils.split(line, \",\");\n+        String[] nameAndHash = StringUtils.split(fields[fields.length - 1], \"|\");\n+        String key = fields[0];\n+        String filename = nameAndHash[0];\n+        String version = VersionUtils.getJarVersion(filename);\n+\n+        if (version != null && props.containsKey(key) && !validate(props.getProperty(key), version)) {\n+          InstalledPlugin plugin = new InstalledPlugin();\n+          plugin.setKey(key);\n+          plugin.setName(key);\n+          plugin.setVersion(version);\n+          invalidPlugins.add(plugin);\n+        }\n+      }\n+    }\n+\n+    return invalidPlugins;\n+  }\n+\n+  private List<InstalledPlugin> after52(Properties props) {\n+    List<InstalledPlugin> invalidPlugins = new LinkedList<>();\n+    try (CloseableWsResponse response = wsClient.get(WS_PATH)) {\n+      InstalledPlugins installedPlugins = new Gson().fromJson(response.contentReader(), InstalledPlugins.class);\n+\n+      for (InstalledPlugin p : installedPlugins.plugins) {\n+        String key = p.getKey();\n+        if (props.containsKey(key) && !validate(props.getProperty(key), p.getVersion())) {\n+          invalidPlugins.add(p);\n+        }\n+      }\n+    }\n+\n+    return invalidPlugins;\n+  }\n+\n+  public void checkPlugins(String serverVersion) {\n+    ValidationResult result = validatePlugins(serverVersion);\n+    if (!result.success()) {\n+      throw new UnsupportedServerException(result.message());\n+    }\n+  }\n+\n+  private String buildFailMessage(Properties props, List<InstalledPlugin> failingPlugins) {","path":"core/src/main/java/org/sonarsource/sonarlint/core/container/connected/validate/PluginVersionChecker.java","position":122,"original_position":122,"commit_id":"30f19deb15b9556cc59d1ee4988ba3d472e68bc2","original_commit_id":"30f19deb15b9556cc59d1ee4988ba3d472e68bc2","user":{"login":"SonarTech","id":1842438,"avatar_url":"https://avatars.githubusercontent.com/u/1842438?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarTech","html_url":"https://github.com/SonarTech","followers_url":"https://api.github.com/users/SonarTech/followers","following_url":"https://api.github.com/users/SonarTech/following{/other_user}","gists_url":"https://api.github.com/users/SonarTech/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarTech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarTech/subscriptions","organizations_url":"https://api.github.com/users/SonarTech/orgs","repos_url":"https://api.github.com/users/SonarTech/repos","events_url":"https://api.github.com/users/SonarTech/events{/privacy}","received_events_url":"https://api.github.com/users/SonarTech/received_events","type":"User","site_admin":false},"body":"![MAJOR](https://raw.githubusercontent.com/SonarCommunity/sonar-github/master/images/severity-major.png) Make \"buildFailMessage\" a \"static\" method. [![rule](https://raw.githubusercontent.com/SonarCommunity/sonar-github/master/images/rule.png)](https://dory.sonarsource.com/coding_rules#rule_key=squid%3AS2325)\n","created_at":"2016-04-11T16:32:28Z","updated_at":"2016-04-11T16:32:28Z","html_url":"https://github.com/SonarSource/sonarlint-core/pull/23#discussion_r59236291","pull_request_url":"https://api.github.com/repos/SonarSource/sonarlint-core/pulls/23","_links":{"self":{"href":"https://api.github.com/repos/SonarSource/sonarlint-core/pulls/comments/59236291"},"html":{"href":"https://github.com/SonarSource/sonarlint-core/pull/23#discussion_r59236291"},"pull_request":{"href":"https://api.github.com/repos/SonarSource/sonarlint-core/pulls/23"}}},"pull_request":{"url":"https://api.github.com/repos/SonarSource/sonarlint-core/pulls/23","id":66022335,"html_url":"https://github.com/SonarSource/sonarlint-core/pull/23","diff_url":"https://github.com/SonarSource/sonarlint-core/pull/23.diff","patch_url":"https://github.com/SonarSource/sonarlint-core/pull/23.patch","issue_url":"https://api.github.com/repos/SonarSource/sonarlint-core/issues/23","number":23,"state":"open","locked":false,"title":"SLCORE-29 Check language plugins compatibility","user":{"login":"dbmeneses","id":12492673,"avatar_url":"https://avatars.githubusercontent.com/u/12492673?v=3","gravatar_id":"","url":"https://api.github.com/users/dbmeneses","html_url":"https://github.com/dbmeneses","followers_url":"https://api.github.com/users/dbmeneses/followers","following_url":"https://api.github.com/users/dbmeneses/following{/other_user}","gists_url":"https://api.github.com/users/dbmeneses/gists{/gist_id}","starred_url":"https://api.github.com/users/dbmeneses/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbmeneses/subscriptions","organizations_url":"https://api.github.com/users/dbmeneses/orgs","repos_url":"https://api.github.com/users/dbmeneses/repos","events_url":"https://api.github.com/users/dbmeneses/events{/privacy}","received_events_url":"https://api.github.com/users/dbmeneses/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-04-11T16:23:33Z","updated_at":"2016-04-11T16:32:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2594fd75cc35fe8e6702d366ff67270c83c27204","assignee":{"login":"henryju","id":281596,"avatar_url":"https://avatars.githubusercontent.com/u/281596?v=3","gravatar_id":"","url":"https://api.github.com/users/henryju","html_url":"https://github.com/henryju","followers_url":"https://api.github.com/users/henryju/followers","following_url":"https://api.github.com/users/henryju/following{/other_user}","gists_url":"https://api.github.com/users/henryju/gists{/gist_id}","starred_url":"https://api.github.com/users/henryju/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/henryju/subscriptions","organizations_url":"https://api.github.com/users/henryju/orgs","repos_url":"https://api.github.com/users/henryju/repos","events_url":"https://api.github.com/users/henryju/events{/privacy}","received_events_url":"https://api.github.com/users/henryju/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/SonarSource/sonarlint-core/pulls/23/commits","review_comments_url":"https://api.github.com/repos/SonarSource/sonarlint-core/pulls/23/comments","review_comment_url":"https://api.github.com/repos/SonarSource/sonarlint-core/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SonarSource/sonarlint-core/issues/23/comments","statuses_url":"https://api.github.com/repos/SonarSource/sonarlint-core/statuses/30f19deb15b9556cc59d1ee4988ba3d472e68bc2","head":{"label":"SonarSource:plugin_comp","ref":"plugin_comp","sha":"30f19deb15b9556cc59d1ee4988ba3d472e68bc2","user":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars.githubusercontent.com/u/545988?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"repo":{"id":50339428,"name":"sonarlint-core","full_name":"SonarSource/sonarlint-core","owner":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars.githubusercontent.com/u/545988?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SonarSource/sonarlint-core","description":"Core library to run SonarLint analysis","fork":false,"url":"https://api.github.com/repos/SonarSource/sonarlint-core","forks_url":"https://api.github.com/repos/SonarSource/sonarlint-core/forks","keys_url":"https://api.github.com/repos/SonarSource/sonarlint-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SonarSource/sonarlint-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SonarSource/sonarlint-core/teams","hooks_url":"https://api.github.com/repos/SonarSource/sonarlint-core/hooks","issue_events_url":"https://api.github.com/repos/SonarSource/sonarlint-core/issues/events{/number}","events_url":"https://api.github.com/repos/SonarSource/sonarlint-core/events","assignees_url":"https://api.github.com/repos/SonarSource/sonarlint-core/assignees{/user}","branches_url":"https://api.github.com/repos/SonarSource/sonarlint-core/branches{/branch}","tags_url":"https://api.github.com/repos/SonarSource/sonarlint-core/tags","blobs_url":"https://api.github.com/repos/SonarSource/sonarlint-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SonarSource/sonarlint-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SonarSource/sonarlint-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/SonarSource/sonarlint-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SonarSource/sonarlint-core/statuses/{sha}","languages_url":"https://api.github.com/repos/SonarSource/sonarlint-core/languages","stargazers_url":"https://api.github.com/repos/SonarSource/sonarlint-core/stargazers","contributors_url":"https://api.github.com/repos/SonarSource/sonarlint-core/contributors","subscribers_url":"https://api.github.com/repos/SonarSource/sonarlint-core/subscribers","subscription_url":"https://api.github.com/repos/SonarSource/sonarlint-core/subscription","commits_url":"https://api.github.com/repos/SonarSource/sonarlint-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/SonarSource/sonarlint-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/SonarSource/sonarlint-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/SonarSource/sonarlint-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/SonarSource/sonarlint-core/contents/{+path}","compare_url":"https://api.github.com/repos/SonarSource/sonarlint-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SonarSource/sonarlint-core/merges","archive_url":"https://api.github.com/repos/SonarSource/sonarlint-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SonarSource/sonarlint-core/downloads","issues_url":"https://api.github.com/repos/SonarSource/sonarlint-core/issues{/number}","pulls_url":"https://api.github.com/repos/SonarSource/sonarlint-core/pulls{/number}","milestones_url":"https://api.github.com/repos/SonarSource/sonarlint-core/milestones{/number}","notifications_url":"https://api.github.com/repos/SonarSource/sonarlint-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SonarSource/sonarlint-core/labels{/name}","releases_url":"https://api.github.com/repos/SonarSource/sonarlint-core/releases{/id}","deployments_url":"https://api.github.com/repos/SonarSource/sonarlint-core/deployments","created_at":"2016-01-25T09:15:04Z","updated_at":"2016-03-10T16:43:06Z","pushed_at":"2016-04-11T16:23:34Z","git_url":"git://github.com/SonarSource/sonarlint-core.git","ssh_url":"git@github.com:SonarSource/sonarlint-core.git","clone_url":"https://github.com/SonarSource/sonarlint-core.git","svn_url":"https://github.com/SonarSource/sonarlint-core","homepage":null,"size":17149,"stargazers_count":2,"watchers_count":2,"language":"PureBasic","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":2,"default_branch":"master"}},"base":{"label":"SonarSource:master","ref":"master","sha":"bf93409a69a152f7ec9414c25ce9f92fd6aadc7b","user":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars.githubusercontent.com/u/545988?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"repo":{"id":50339428,"name":"sonarlint-core","full_name":"SonarSource/sonarlint-core","owner":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars.githubusercontent.com/u/545988?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SonarSource/sonarlint-core","description":"Core library to run SonarLint analysis","fork":false,"url":"https://api.github.com/repos/SonarSource/sonarlint-core","forks_url":"https://api.github.com/repos/SonarSource/sonarlint-core/forks","keys_url":"https://api.github.com/repos/SonarSource/sonarlint-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SonarSource/sonarlint-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SonarSource/sonarlint-core/teams","hooks_url":"https://api.github.com/repos/SonarSource/sonarlint-core/hooks","issue_events_url":"https://api.github.com/repos/SonarSource/sonarlint-core/issues/events{/number}","events_url":"https://api.github.com/repos/SonarSource/sonarlint-core/events","assignees_url":"https://api.github.com/repos/SonarSource/sonarlint-core/assignees{/user}","branches_url":"https://api.github.com/repos/SonarSource/sonarlint-core/branches{/branch}","tags_url":"https://api.github.com/repos/SonarSource/sonarlint-core/tags","blobs_url":"https://api.github.com/repos/SonarSource/sonarlint-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SonarSource/sonarlint-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SonarSource/sonarlint-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/SonarSource/sonarlint-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SonarSource/sonarlint-core/statuses/{sha}","languages_url":"https://api.github.com/repos/SonarSource/sonarlint-core/languages","stargazers_url":"https://api.github.com/repos/SonarSource/sonarlint-core/stargazers","contributors_url":"https://api.github.com/repos/SonarSource/sonarlint-core/contributors","subscribers_url":"https://api.github.com/repos/SonarSource/sonarlint-core/subscribers","subscription_url":"https://api.github.com/repos/SonarSource/sonarlint-core/subscription","commits_url":"https://api.github.com/repos/SonarSource/sonarlint-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/SonarSource/sonarlint-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/SonarSource/sonarlint-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/SonarSource/sonarlint-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/SonarSource/sonarlint-core/contents/{+path}","compare_url":"https://api.github.com/repos/SonarSource/sonarlint-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SonarSource/sonarlint-core/merges","archive_url":"https://api.github.com/repos/SonarSource/sonarlint-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SonarSource/sonarlint-core/downloads","issues_url":"https://api.github.com/repos/SonarSource/sonarlint-core/issues{/number}","pulls_url":"https://api.github.com/repos/SonarSource/sonarlint-core/pulls{/number}","milestones_url":"https://api.github.com/repos/SonarSource/sonarlint-core/milestones{/number}","notifications_url":"https://api.github.com/repos/SonarSource/sonarlint-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SonarSource/sonarlint-core/labels{/name}","releases_url":"https://api.github.com/repos/SonarSource/sonarlint-core/releases{/id}","deployments_url":"https://api.github.com/repos/SonarSource/sonarlint-core/deployments","created_at":"2016-01-25T09:15:04Z","updated_at":"2016-03-10T16:43:06Z","pushed_at":"2016-04-11T16:23:34Z","git_url":"git://github.com/SonarSource/sonarlint-core.git","ssh_url":"git@github.com:SonarSource/sonarlint-core.git","clone_url":"https://github.com/SonarSource/sonarlint-core.git","svn_url":"https://github.com/SonarSource/sonarlint-core","homepage":null,"size":17149,"stargazers_count":2,"watchers_count":2,"language":"PureBasic","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SonarSource/sonarlint-core/pulls/23"},"html":{"href":"https://github.com/SonarSource/sonarlint-core/pull/23"},"issue":{"href":"https://api.github.com/repos/SonarSource/sonarlint-core/issues/23"},"comments":{"href":"https://api.github.com/repos/SonarSource/sonarlint-core/issues/23/comments"},"review_comments":{"href":"https://api.github.com/repos/SonarSource/sonarlint-core/pulls/23/comments"},"review_comment":{"href":"https://api.github.com/repos/SonarSource/sonarlint-core/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SonarSource/sonarlint-core/pulls/23/commits"},"statuses":{"href":"https://api.github.com/repos/SonarSource/sonarlint-core/statuses/30f19deb15b9556cc59d1ee4988ba3d472e68bc2"}}}}