use of org.sonar.server.plugins.ServerPlugin in project sonarqube by SonarSource.
the class GeneratePluginIndexTest method newInstalledPlugin.
private ServerPlugin newInstalledPlugin(String key, boolean supportSonarLint) throws IOException {
FileAndMd5 jar = new FileAndMd5(temp.newFile());
PluginInfo pluginInfo = new PluginInfo(key).setJarFile(jar.getFile()).setSonarLintSupported(supportSonarLint);
return new ServerPlugin(pluginInfo, BUNDLED, null, jar, null, null);
}
use of org.sonar.server.plugins.ServerPlugin in project sonarqube by SonarSource.
the class GeneratePluginIndexTest method shouldWriteIndex.
@Test
public void shouldWriteIndex() throws IOException {
ServerPlugin javaPlugin = newInstalledPlugin("java", true);
ServerPlugin gitPlugin = newInstalledPlugin("scmgit", false);
when(serverPluginRepository.getPlugins()).thenReturn(asList(javaPlugin, gitPlugin));
GeneratePluginIndex underTest = new GeneratePluginIndex(serverFileSystem, serverPluginRepository);
underTest.start();
List<String> lines = FileUtils.readLines(index);
assertThat(lines).containsExactly("java,true," + javaPlugin.getJar().getFile().getName() + "|" + javaPlugin.getJar().getMd5(), "scmgit,false," + gitPlugin.getJar().getFile().getName() + "|" + gitPlugin.getJar().getMd5());
underTest.stop();
}
use of org.sonar.server.plugins.ServerPlugin in project sonarqube by SonarSource.
the class GeneratePluginIndex method writeIndex.
private void writeIndex(File indexFile) {
try {
FileUtils.forceMkdir(indexFile.getParentFile());
try (Writer writer = new OutputStreamWriter(new FileOutputStream(indexFile), StandardCharsets.UTF_8)) {
for (ServerPlugin plugin : serverPluginRepository.getPlugins()) {
writer.append(toRow(plugin));
writer.append(CharUtils.LF);
}
writer.flush();
}
} catch (IOException e) {
throw new IllegalStateException("Unable to generate plugin index at " + indexFile, e);
}
}
use of org.sonar.server.plugins.ServerPlugin 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.server.plugins.ServerPlugin in project sonarqube by SonarSource.
the class DownloadAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String pluginKey = request.mandatoryParam(PLUGIN_PARAM);
Optional<ServerPlugin> file = pluginRepository.findPlugin(pluginKey);
if (!file.isPresent()) {
throw new NotFoundException("Plugin " + pluginKey + " not found");
}
FileAndMd5 downloadedFile;
FileAndMd5 compressedJar = file.get().getCompressed();
if (compressedJar != null && PACK200.equals(request.param(ACCEPT_COMPRESSIONS_PARAM))) {
response.stream().setMediaType("application/octet-stream");
response.setHeader("Sonar-Compression", PACK200);
response.setHeader("Sonar-UncompressedMD5", file.get().getJar().getMd5());
downloadedFile = compressedJar;
} else {
response.stream().setMediaType("application/java-archive");
downloadedFile = file.get().getJar();
}
response.setHeader("Sonar-MD5", downloadedFile.getMd5());
try (InputStream input = FileUtils.openInputStream(downloadedFile.getFile())) {
IOUtils.copyLarge(input, response.stream().output());
}
}
Aggregations