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);
}
Aggregations