use of org.sonar.db.plugin.PluginDto in project sonarqube by SonarSource.
the class RegisterPluginsTest method update_removed_plugins.
@Test
public void update_removed_plugins() throws IOException {
// will be flagged as removed
dbClient.pluginDao().insert(dbTester.getSession(), new PluginDto().setUuid("a").setKee("java").setBasePluginKey(null).setFileHash("bd451e47a1aa76e73da0359cef63dd63").setType(Type.BUNDLED).setCreatedAt(1L).setUpdatedAt(1L));
// already flagged as removed
dbClient.pluginDao().insert(dbTester.getSession(), new PluginDto().setUuid("b").setKee("java2").setBasePluginKey(null).setFileHash("bd451e47a1aa76e73da0359cef63dd63").setType(Type.BUNDLED).setRemoved(true).setCreatedAt(1L).setUpdatedAt(1L));
dbClient.pluginDao().insert(dbTester.getSession(), new PluginDto().setUuid("c").setKee("csharp").setBasePluginKey(null).setFileHash("a20d785dbacb8f41a3b7392aa7d03b78").setType(Type.EXTERNAL).setCreatedAt(1L).setUpdatedAt(1L));
dbTester.commit();
addPlugin("csharp", PluginType.EXTERNAL, null);
register.start();
Map<String, PluginDto> pluginsByKey = selectAllPlugins();
assertThat(pluginsByKey).hasSize(3);
verify(pluginsByKey.get("java"), Type.BUNDLED, null, "bd451e47a1aa76e73da0359cef63dd63", true, 1L, now);
verify(pluginsByKey.get("java2"), Type.BUNDLED, null, "bd451e47a1aa76e73da0359cef63dd63", true, 1L, 1L);
verify(pluginsByKey.get("csharp"), Type.EXTERNAL, null, "a20d785dbacb8f41a3b7392aa7d03b78", false, 1L, 1L);
}
use of org.sonar.db.plugin.PluginDto in project sonarqube by SonarSource.
the class DetectPluginChange method anyChange.
private boolean anyChange() {
try (DbSession dbSession = dbClient.openSession(false)) {
Map<String, PluginDto> dbPluginsByKey = dbClient.pluginDao().selectAll(dbSession).stream().filter(p -> !p.isRemoved()).collect(Collectors.toMap(PluginDto::getKee, identity()));
Map<String, ServerPlugin> filePluginsByKey = serverPluginRepository.getPlugins().stream().collect(Collectors.toMap(p -> p.getPluginInfo().getKey(), p -> p));
if (!dbPluginsByKey.keySet().equals(filePluginsByKey.keySet())) {
return true;
}
for (ServerPlugin installed : filePluginsByKey.values()) {
PluginDto dbPlugin = dbPluginsByKey.get(installed.getPluginInfo().getKey());
if (changed(dbPlugin, installed)) {
return true;
}
}
}
return false;
}
use of org.sonar.db.plugin.PluginDto in project sonarqube by SonarSource.
the class RegisterPlugins method updateDB.
private void updateDB() {
long now = system.now();
try (DbSession dbSession = dbClient.openSession(false)) {
Map<String, PluginDto> allPreviousPluginsByKey = dbClient.pluginDao().selectAll(dbSession).stream().collect(Collectors.toMap(PluginDto::getKee, identity()));
for (ServerPlugin installed : serverPluginRepository.getPlugins()) {
PluginInfo info = installed.getPluginInfo();
PluginDto previousDto = allPreviousPluginsByKey.get(info.getKey());
if (previousDto == null) {
LOG.debug("Register new plugin {}", info.getKey());
PluginDto pluginDto = new PluginDto().setUuid(uuidFactory.create()).setKee(info.getKey()).setBasePluginKey(info.getBasePlugin()).setFileHash(installed.getJar().getMd5()).setType(toTypeDto(installed.getType())).setCreatedAt(now).setUpdatedAt(now);
dbClient.pluginDao().insert(dbSession, pluginDto);
} else if (!previousDto.getFileHash().equals(installed.getJar().getMd5()) || !previousDto.getType().equals(toTypeDto(installed.getType()))) {
LOG.debug("Update plugin {}", info.getKey());
previousDto.setBasePluginKey(info.getBasePlugin()).setFileHash(installed.getJar().getMd5()).setType(toTypeDto(installed.getType())).setUpdatedAt(now);
dbClient.pluginDao().update(dbSession, previousDto);
}
}
// keep uninstalled plugins with a 'removed' flag, because corresponding rules and active rules are also not deleted
for (PluginDto dto : allPreviousPluginsByKey.values()) {
if (dto.isRemoved()) {
continue;
}
if (serverPluginRepository.findPlugin(dto.getKee()).isEmpty()) {
dto.setRemoved(true).setUpdatedAt(now);
dbClient.pluginDao().update(dbSession, dto);
}
}
dbSession.commit();
}
}
use of org.sonar.db.plugin.PluginDto 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