From cb0937144b627e3167a363270db86b5950e1c2fc Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Tue, 10 May 2016 19:09:47 +0200 Subject: [PATCH] SONAR-7591 Make category an optional field in WS api/plugins/installed --- .../server/plugins/ws/InstalledAction.java | 27 +++++++-- .../plugins/ws/InstalledActionTest.java | 57 ++++++++++++++++--- .../org/sonar/api/server/ws/WebService.java | 2 +- 3 files changed, 72 insertions(+), 14 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/InstalledAction.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/InstalledAction.java index a888d7e35a2..4c1034713b6 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/InstalledAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/InstalledAction.java @@ -19,9 +19,11 @@ */ package org.sonar.server.plugins.ws; -import com.google.common.collect.ImmutableMap; import com.google.common.io.Resources; import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; import java.util.SortedSet; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; @@ -33,6 +35,8 @@ import org.sonar.server.plugins.UpdateCenterMatrixFactory; import org.sonar.updatecenter.common.Plugin; import static com.google.common.collect.ImmutableSortedSet.copyOf; +import static java.lang.String.format; +import static java.util.Collections.singleton; import static org.sonar.server.plugins.ws.PluginWSCommons.NAME_KEY_PLUGIN_METADATA_COMPARATOR; import static org.sonar.server.plugins.ws.PluginWSCommons.compatiblePluginsByKey; @@ -41,6 +45,7 @@ import static org.sonar.server.plugins.ws.PluginWSCommons.compatiblePluginsByKey */ public class InstalledAction implements PluginsWsAction { private static final String ARRAY_PLUGINS = "plugins"; + private static final String FIELD_CATEGORY = "category"; private final ServerPluginRepository pluginRepository; private final PluginWSCommons pluginWSCommons; @@ -54,11 +59,18 @@ public class InstalledAction implements PluginsWsAction { @Override public void define(WebService.NewController controller) { - controller.createAction("installed") + WebService.NewAction action = controller.createAction("installed") .setDescription("Get the list of all the plugins installed on the SonarQube instance, sorted by plugin name") .setSince("5.2") .setHandler(this) .setResponseExample(Resources.getResource(this.getClass(), "example-installed_plugins.json")); + + action.createFieldsParam(singleton("category")) + .setDescription(format("Comma-separated list of the additional fields to be returned in response. No additional field is returned by default. Possible values are:" + + "