]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9976 add editionBundled flag to several webServices
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Fri, 13 Oct 2017 15:04:12 +0000 (17:04 +0200)
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>
Mon, 23 Oct 2017 15:01:13 +0000 (08:01 -0700)
api/plugins/[available|updates]
api/system/upgrades

server/sonar-server/src/main/java/org/sonar/server/plugins/edition/EditionBundledPlugins.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/plugins/ws/PluginWSCommons.java
server/sonar-server/src/main/resources/org/sonar/server/platform/ws/example-upgrades_plugins.json
server/sonar-server/src/main/resources/org/sonar/server/plugins/ws/example-available_plugins.json
server/sonar-server/src/main/resources/org/sonar/server/plugins/ws/example-updates_plugins.json
server/sonar-server/src/test/java/org/sonar/server/platform/ws/UpgradesActionTest.java
server/sonar-server/src/test/java/org/sonar/server/plugins/ws/AvailableActionTest.java
server/sonar-server/src/test/java/org/sonar/server/plugins/ws/UpdatesActionTest.java
server/sonar-server/src/test/resources/org/sonar/server/plugins/ws/AvailableActionTest/properties_per_plugin.json [deleted file]

diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/edition/EditionBundledPlugins.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/edition/EditionBundledPlugins.java
new file mode 100644 (file)
index 0000000..362f027
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.plugins.edition;
+
+import java.util.Arrays;
+import org.sonar.updatecenter.common.Plugin;
+
+public final class EditionBundledPlugins {
+
+  private static final String SONARSOURCE_ORGANIZATION = "SonarSource";
+  private static final String[] SONARSOURCE_COMMERCIAL_LICENSES = {"SonarSource", "Commercial"};
+
+  private EditionBundledPlugins() {
+    // prevents instantiation
+  }
+
+  public static boolean isEditionBundled(Plugin plugin) {
+    return SONARSOURCE_ORGANIZATION.equalsIgnoreCase(plugin.getOrganization())
+      && Arrays.stream(SONARSOURCE_COMMERCIAL_LICENSES).anyMatch(s -> s.equalsIgnoreCase(plugin.getLicense()));
+  }
+}
index 44c362d6c45736c37313f1fb8fdfd4bf2f055517..82ee4b1a4728cf666334c3fd2604b7f100a66451 100644 (file)
@@ -49,33 +49,35 @@ import static com.google.common.collect.Iterables.filter;
 import static com.google.common.collect.Iterables.transform;
 import static java.lang.String.CASE_INSENSITIVE_ORDER;
 import static org.apache.commons.lang.StringUtils.isNotBlank;
+import static org.sonar.server.plugins.edition.EditionBundledPlugins.isEditionBundled;
 
 public class PluginWSCommons {
-  static final String PROPERTY_KEY = "key";
-  static final String PROPERTY_NAME = "name";
-  static final String PROPERTY_HASH = "hash";
-  static final String PROPERTY_FILENAME = "filename";
-  static final String PROPERTY_SONARLINT_SUPPORTED = "sonarLintSupported";
-  static final String PROPERTY_DESCRIPTION = "description";
-  static final String PROPERTY_LICENSE = "license";
-  static final String PROPERTY_VERSION = "version";
-  static final String PROPERTY_CATEGORY = "category";
-  static final String PROPERTY_ORGANIZATION_NAME = "organizationName";
-  static final String PROPERTY_ORGANIZATION_URL = "organizationUrl";
-  static final String PROPERTY_DATE = "date";
-  static final String PROPERTY_UPDATED_AT = "updatedAt";
-  static final String PROPERTY_STATUS = "status";
-  static final String PROPERTY_HOMEPAGE_URL = "homepageUrl";
-  static final String PROPERTY_ISSUE_TRACKER_URL = "issueTrackerUrl";
-  static final String OBJECT_ARTIFACT = "artifact";
-  static final String PROPERTY_URL = "url";
-  static final String PROPERTY_TERMS_AND_CONDITIONS_URL = "termsAndConditionsUrl";
-  static final String OBJECT_UPDATE = "update";
-  static final String OBJECT_RELEASE = "release";
-  static final String ARRAY_REQUIRES = "requires";
-  static final String PROPERTY_UPDATE_CENTER_REFRESH = "updateCenterRefresh";
-  static final String PROPERTY_IMPLEMENTATION_BUILD = "implementationBuild";
-  static final String PROPERTY_CHANGE_LOG_URL = "changeLogUrl";
+  private static final String PROPERTY_KEY = "key";
+  private static final String PROPERTY_NAME = "name";
+  private static final String PROPERTY_HASH = "hash";
+  private static final String PROPERTY_FILENAME = "filename";
+  private static final String PROPERTY_SONARLINT_SUPPORTED = "sonarLintSupported";
+  private static final String PROPERTY_DESCRIPTION = "description";
+  private static final String PROPERTY_LICENSE = "license";
+  private static final String PROPERTY_VERSION = "version";
+  private static final String PROPERTY_CATEGORY = "category";
+  private static final String PROPERTY_ORGANIZATION_NAME = "organizationName";
+  private static final String PROPERTY_ORGANIZATION_URL = "organizationUrl";
+  private static final String PROPERTY_DATE = "date";
+  private static final String PROPERTY_UPDATED_AT = "updatedAt";
+  private static final String PROPERTY_STATUS = "status";
+  private static final String PROPERTY_HOMEPAGE_URL = "homepageUrl";
+  private static final String PROPERTY_ISSUE_TRACKER_URL = "issueTrackerUrl";
+  private static final String PROPERTY_EDITION_BUNDLED = "editionBundled";
+  private static final String OBJECT_ARTIFACT = "artifact";
+  private static final String PROPERTY_URL = "url";
+  private static final String PROPERTY_TERMS_AND_CONDITIONS_URL = "termsAndConditionsUrl";
+  private static final String OBJECT_UPDATE = "update";
+  private static final String OBJECT_RELEASE = "release";
+  private static final String ARRAY_REQUIRES = "requires";
+  private static final String PROPERTY_UPDATE_CENTER_REFRESH = "updateCenterRefresh";
+  private static final String PROPERTY_IMPLEMENTATION_BUILD = "implementationBuild";
+  private static final String PROPERTY_CHANGE_LOG_URL = "changeLogUrl";
 
   public static final Ordering<PluginInfo> NAME_KEY_PLUGIN_METADATA_COMPARATOR = Ordering.natural()
     .onResultOf(PluginInfo::getName)
@@ -142,6 +144,7 @@ public class PluginWSCommons {
     jsonWriter.prop(PROPERTY_ORGANIZATION_URL, plugin.getOrganizationUrl());
     jsonWriter.prop(PROPERTY_HOMEPAGE_URL, plugin.getHomepageUrl());
     jsonWriter.prop(PROPERTY_ISSUE_TRACKER_URL, plugin.getIssueTrackerUrl());
+    jsonWriter.prop(PROPERTY_EDITION_BUNDLED, isEditionBundled(plugin));
   }
 
   public void writePluginUpdate(JsonWriter json, PluginUpdate pluginUpdate) {
index 9d0d7aa4ae8634f42cc676d7996ec742e0a8d261..7364af7a584e29482b413c92e80e9e457bde4d64 100644 (file)
@@ -16,6 +16,7 @@
             "license": "Commercial",
             "organizationName": "SonarSource",
             "organizationUrl": "http://www.sonarsource.com",
+            "editionBundled": true,
             "termsAndConditionsUrl": "http://dist.sonarsource.com/SonarSource_Terms_And_Conditions.pdf",
             "version": "2.8 (build 5498)"
           }
@@ -28,7 +29,8 @@
             "description": "Allows to add your own logo to the SonarQube UI.",
             "license": "GNU LGPL 3",
             "organizationName": "SonarSource",
-            "organizationUrl": "http://www.sonarsource.com"
+            "organizationUrl": "http://www.sonarsource.com",
+            "editionBundled": false
           }
         ]
       }
index 0d2077ab2e34fd451bd6b2cd5a28071c7f48267b..f6453bc3008dd8594732381589e9f9813a29ab10 100644 (file)
@@ -9,6 +9,7 @@
       "organizationName": "SonarSource",
       "organizationUrl": "http://www.sonarsource.com",
       "termsAndConditionsUrl": "http://dist.sonarsource.com/SonarSource_Terms_And_Conditions.pdf",
+      "editionBundled": true,
       "release": {
         "version": "3.2",
         "date": "2015-03-10"
@@ -26,6 +27,7 @@
       "license": "GNU LGPL 3",
       "organizationName": "SonarSource and Jerome Van Der Linden, Stephane Nicolas, Florian Roncari, Thomas Bores",
       "organizationUrl": "http://www.sonarsource.com",
+      "editionBundled": false,
       "release": {
         "version": "1.0",
         "date": "2014-03-31"
@@ -43,4 +45,4 @@
     }
   ],
   "updateCenterRefresh": "2015-04-24T16:08:36+0200"
-}
\ No newline at end of file
+}
index cee849909a35e252ec7418f5379dc6662e697d3d..8adb9a7226a9ce42e1c88f89387c3a4b7da04b42 100644 (file)
@@ -9,6 +9,7 @@
       "organizationName": "SonarSource",
       "organizationUrl": "http://www.sonarsource.com",
       "termsAndConditionsUrl": "http://dist.sonarsource.com/SonarSource_Terms_And_Conditions.pdf",
+      "editionBundled": true,
       "updates": [
         {
           "release": {
@@ -40,6 +41,7 @@
       "license": "GNU LGPL 3",
       "organizationName": "SonarSource and Jerome Van Der Linden, Stephane Nicolas, Florian Roncari, Thomas Bores",
       "organizationUrl": "http://www.sonarsource.com",
+      "editionBundled": false,
       "updates": [
         {
           "release": {
index fe378375307d526099f07f56ff886491f1a9bf11..327d9af2d69706aaebfadc3d02d8981d100ab61b 100644 (file)
@@ -27,6 +27,7 @@ import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.server.plugins.UpdateCenterMatrixFactory;
 import org.sonar.server.plugins.ws.PluginWSCommons;
+import org.sonar.server.ws.WsActionTester;
 import org.sonar.server.ws.WsTester;
 import org.sonar.updatecenter.common.Plugin;
 import org.sonar.updatecenter.common.Release;
@@ -44,10 +45,9 @@ import static org.sonar.test.JsonAssert.assertJson;
 
 public class UpgradesActionTest {
   private static final String DUMMY_CONTROLLER_KEY = "dummy";
-  private static final String JSON_EMPTY_UPGRADE_LIST =
-    "{" +
-      "  \"upgrades\":" + "[]" +
-      "}";
+  private static final String JSON_EMPTY_UPGRADE_LIST = "{" +
+    "  \"upgrades\":" + "[]" +
+    "}";
   private static Release release;
 
   private UpdateCenterMatrixFactory updateCenterFactory = mock(UpdateCenterMatrixFactory.class);
@@ -141,6 +141,6 @@ public class UpgradesActionTest {
     underTest.handle(request, response);
 
     assertJson(response.outputAsString()).withStrictArrayOrder()
-      .isSimilarTo(getClass().getResource("example-upgrades_plugins.json"));
+      .isSimilarTo(new WsActionTester(underTest).getDef().responseExampleAsString());
   }
 }
index 05034b1397c5967f0a128af4c47f6c7836c0acdd..96b8b710567a872d853006f6c4be70e101e6be67 100644 (file)
@@ -27,6 +27,7 @@ import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.tester.UserSessionRule;
+import org.sonar.server.ws.WsActionTester;
 import org.sonar.server.ws.WsTester;
 import org.sonar.updatecenter.common.Plugin;
 import org.sonar.updatecenter.common.PluginUpdate;
@@ -86,6 +87,39 @@ public class AvailableActionTest extends AbstractUpdateCenterBasedPluginsWsActio
     assertThat(action.responseExample()).isNotNull();
   }
 
+  @Test
+  public void verify_example() throws Exception {
+    logInAsSystemAdministrator();
+    when(updateCenter.findAvailablePlugins()).thenReturn(of(
+      pluginUpdate(release(Plugin.factory("abap")
+        .setName("ABAP")
+        .setCategory("Languages")
+        .setDescription("Enable analysis and reporting on ABAP projects")
+        .setLicense("Commercial")
+        .setOrganization("SonarSource")
+        .setOrganizationUrl("http://www.sonarsource.com")
+        .setTermsConditionsUrl("http://dist.sonarsource.com/SonarSource_Terms_And_Conditions.pdf"),
+        "3.2")
+          .setDate(DateUtils.parseDate("2015-03-10")),
+        COMPATIBLE),
+      pluginUpdate(release(Plugin.factory("android")
+        .setName("Android")
+        .setCategory("Languages")
+        .setDescription("Import Android Lint reports.")
+        .setLicense("GNU LGPL 3")
+        .setOrganization("SonarSource and Jerome Van Der Linden, Stephane Nicolas, Florian Roncari, Thomas Bores")
+        .setOrganizationUrl("http://www.sonarsource.com"),
+        "1.0")
+          .setDate(DateUtils.parseDate("2014-03-31"))
+          .addOutgoingDependency(release(Plugin.factory("java").setName("Java").setDescription("SonarQube rule engine."), "0.3.6")),
+        COMPATIBLE)));
+
+    underTest.handle(request, response);
+
+    WsActionTester actionTester = new WsActionTester(underTest);
+    assertJson(response.outputAsString()).isSimilarTo(actionTester.getDef().responseExampleAsString());
+  }
+
   @Test
   public void request_fails_with_ForbiddenException_when_user_is_not_logged_in() throws Exception {
     expectedException.expect(ForbiddenException.class);
@@ -128,7 +162,43 @@ public class AvailableActionTest extends AbstractUpdateCenterBasedPluginsWsActio
 
     underTest.handle(request, response);
 
-    assertJson(response.outputAsString()).isSimilarTo(resource("properties_per_plugin.json"));
+    assertJson(response.outputAsString())
+      .isSimilarTo(
+        "{" +
+          "  \"plugins\": [" +
+          "    {" +
+          "      \"key\": \"pkey\"," +
+          "      \"name\": \"p_name\"," +
+          "      \"category\": \"p_category\"," +
+          "      \"description\": \"p_description\"," +
+          "      \"license\": \"p_license\"," +
+          "      \"termsAndConditionsUrl\": \"p_t_and_c_url\"," +
+          "      \"organizationName\": \"p_orga_name\"," +
+          "      \"organizationUrl\": \"p_orga_url\"," +
+          "      \"homepageUrl\": \"p_homepage_url\"," +
+          "      \"issueTrackerUrl\": \"p_issue_url\"," +
+          "      \"release\": {" +
+          "        \"version\": \"1.12.1\"," +
+          "        \"date\": \"2015-04-16\"" +
+          "      }," +
+          "      \"update\": {" +
+          "        \"status\": \"COMPATIBLE\"," +
+          "        \"requires\": [" +
+          "          {" +
+          "            \"key\": \"pkey1\"," +
+          "            \"name\": \"p_name_1\"" +
+          "          }," +
+          "          {" +
+          "            \"key\": \"pkey2\"," +
+          "            \"name\": \"p_name_2\"," +
+          "            \"description\": \"p_desc_2\"" +
+          "          }" +
+          "        ]" +
+          "      }" +
+          "    }" +
+          "  ]," +
+          "  \"updateCenterRefresh\": \"2015-04-24T16:08:36+0200\"" +
+          "}");
   }
 
   @Test
index 5dee3e9082da3dcc5a5c7cd89d14e3475af434c1..c3d39304e4eac70430350b378914774b86ae8d0f 100644 (file)
@@ -26,6 +26,7 @@ import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.tester.UserSessionRule;
+import org.sonar.server.ws.WsActionTester;
 import org.sonar.server.ws.WsTester;
 import org.sonar.updatecenter.common.Plugin;
 import org.sonar.updatecenter.common.Release;
@@ -135,7 +136,8 @@ public class UpdatesActionTest extends AbstractUpdateCenterBasedPluginsWsActionT
 
     underTest.handle(request, response);
 
-    assertJson(response.outputAsString()).isSimilarTo(getClass().getResource("example-updates_plugins.json"));
+    assertJson(response.outputAsString())
+      .isSimilarTo(new WsActionTester(underTest).getDef().responseExampleAsString());
   }
 
   @Test
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/plugins/ws/AvailableActionTest/properties_per_plugin.json b/server/sonar-server/src/test/resources/org/sonar/server/plugins/ws/AvailableActionTest/properties_per_plugin.json
deleted file mode 100644 (file)
index dc6002d..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-{
-  "plugins": [
-    {
-      "key": "pkey",
-      "name": "p_name",
-      "category": "p_category",
-      "description": "p_description",
-      "license": "p_license",
-      "termsAndConditionsUrl": "p_t_and_c_url",
-      "organizationName": "p_orga_name",
-      "organizationUrl": "p_orga_url",
-      "homepageUrl": "p_homepage_url",
-      "issueTrackerUrl": "p_issue_url",
-      "release": {
-        "version": "1.12.1",
-        "date": "2015-04-16"
-      },
-      "update": {
-        "status": "COMPATIBLE",
-        "requires": [
-          {
-            "key": "pkey1",
-            "name": "p_name_1"
-          },
-          {
-            "key": "pkey2",
-            "name": "p_name_2",
-            "description": "p_desc_2"
-          }
-        ]
-      }
-    }
-  ],
-  "updateCenterRefresh": "2015-04-24T16:08:36+0200"
-}