Search in sources :

Example 1 with InstalledPluginsWsResponse

use of org.sonarqube.ws.Plugins.InstalledPluginsWsResponse in project sonarqube by SonarSource.

the class InstalledAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    String typeParam = request.param(PARAM_TYPE);
    SortedSet<ServerPlugin> installedPlugins = loadInstalledPlugins(typeParam);
    Map<String, PluginDto> dtosByKey;
    try (DbSession dbSession = dbClient.openSession(false)) {
        dtosByKey = dbClient.pluginDao().selectAll(dbSession).stream().collect(toMap(PluginDto::getKee, Function.identity()));
    }
    List<String> additionalFields = request.paramAsStrings(WebService.Param.FIELDS);
    Map<String, Plugin> updateCenterPlugins = (additionalFields == null || additionalFields.isEmpty()) ? emptyMap() : compatiblePluginsByKey(updateCenterMatrixFactory);
    List<PluginDetails> pluginList = new LinkedList<>();
    for (ServerPlugin installedPlugin : installedPlugins) {
        PluginInfo pluginInfo = installedPlugin.getPluginInfo();
        PluginDto pluginDto = dtosByKey.get(pluginInfo.getKey());
        Objects.requireNonNull(pluginDto, () -> format("Plugin %s is installed but not in DB", pluginInfo.getKey()));
        Plugin updateCenterPlugin = updateCenterPlugins.get(pluginInfo.getKey());
        pluginList.add(buildPluginDetails(installedPlugin, pluginInfo, pluginDto, updateCenterPlugin));
    }
    InstalledPluginsWsResponse wsResponse = InstalledPluginsWsResponse.newBuilder().addAllPlugins(pluginList).build();
    writeProtobuf(wsResponse, request, response);
}
Also used : InstalledPluginsWsResponse(org.sonarqube.ws.Plugins.InstalledPluginsWsResponse) ServerPlugin(org.sonar.server.plugins.ServerPlugin) LinkedList(java.util.LinkedList) DbSession(org.sonar.db.DbSession) PluginDto(org.sonar.db.plugin.PluginDto) PluginDetails(org.sonarqube.ws.Plugins.PluginDetails) PluginWSCommons.buildPluginDetails(org.sonar.server.plugins.ws.PluginWSCommons.buildPluginDetails) PluginInfo(org.sonar.core.platform.PluginInfo) ServerPlugin(org.sonar.server.plugins.ServerPlugin) Plugin(org.sonar.updatecenter.common.Plugin)

Aggregations

LinkedList (java.util.LinkedList)1 PluginInfo (org.sonar.core.platform.PluginInfo)1 DbSession (org.sonar.db.DbSession)1 PluginDto (org.sonar.db.plugin.PluginDto)1 ServerPlugin (org.sonar.server.plugins.ServerPlugin)1 PluginWSCommons.buildPluginDetails (org.sonar.server.plugins.ws.PluginWSCommons.buildPluginDetails)1 Plugin (org.sonar.updatecenter.common.Plugin)1 InstalledPluginsWsResponse (org.sonarqube.ws.Plugins.InstalledPluginsWsResponse)1 PluginDetails (org.sonarqube.ws.Plugins.PluginDetails)1