use of org.sonar.server.plugins.ServerPlugin 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);
}
use of org.sonar.server.plugins.ServerPlugin in project sonarqube by SonarSource.
the class DownloadActionTest method return_compressed_jar_if_client_accepts_pack200.
@Test
public void return_compressed_jar_if_client_accepts_pack200() throws Exception {
ServerPlugin plugin = newCompressedPlugin();
when(serverPluginRepository.findPlugin(plugin.getPluginInfo().getKey())).thenReturn(Optional.of(plugin));
TestResponse response = tester.newRequest().setParam("plugin", plugin.getPluginInfo().getKey()).setParam("acceptCompressions", "pack200").execute();
assertThat(response.getHeader("Sonar-MD5")).isEqualTo(plugin.getCompressed().getMd5());
assertThat(response.getHeader("Sonar-UncompressedMD5")).isEqualTo(plugin.getJar().getMd5());
assertThat(response.getHeader("Sonar-Compression")).isEqualTo("pack200");
assertThat(response.getMediaType()).isEqualTo("application/octet-stream");
verifySameContent(response, plugin.getCompressed().getFile());
}
use of org.sonar.server.plugins.ServerPlugin in project sonarqube by SonarSource.
the class DownloadActionTest method return_uncompressed_jar_if_client_requests_unsupported_compression.
@Test
public void return_uncompressed_jar_if_client_requests_unsupported_compression() throws Exception {
ServerPlugin plugin = newCompressedPlugin();
when(serverPluginRepository.findPlugin(plugin.getPluginInfo().getKey())).thenReturn(Optional.of(plugin));
TestResponse response = tester.newRequest().setParam("plugin", plugin.getPluginInfo().getKey()).setParam("acceptCompressions", "zip").execute();
assertThat(response.getHeader("Sonar-MD5")).isEqualTo(plugin.getJar().getMd5());
assertThat(response.getHeader("Sonar-Compression")).isNull();
assertThat(response.getHeader("Sonar-UncompressedMD5")).isNull();
assertThat(response.getMediaType()).isEqualTo("application/java-archive");
verifySameContent(response, plugin.getJar().getFile());
}
use of org.sonar.server.plugins.ServerPlugin in project sonarqube by SonarSource.
the class InstalledActionTest method plugin.
private ServerPlugin plugin(String key, String name) throws IOException {
File file = temp.newFile();
PluginInfo info = new PluginInfo(key).setName(name).setVersion(Version.create("1.0"));
info.setJarFile(file);
return new ServerPlugin(info, PluginType.BUNDLED, null, new FileAndMd5(file), null, null);
}
use of org.sonar.server.plugins.ServerPlugin in project sonarqube by SonarSource.
the class InstalledActionTest method return_default_fields.
@Test
public void return_default_fields() throws Exception {
ServerPlugin plugin = newInstalledPlugin(new PluginInfo("foo").setName("plugName").setDescription("desc_it").setVersion(Version.create("1.0")).setLicense("license_hey").setOrganizationName("org_name").setOrganizationUrl("org_url").setHomepageUrl("homepage_url").setIssueTrackerUrl("issueTracker_url").setImplementationBuild("sou_rev_sha1").setSonarLintSupported(true));
when(serverPluginRepository.getPlugins()).thenReturn(singletonList(plugin));
db.pluginDbTester().insertPlugin(p -> p.setKee(plugin.getPluginInfo().getKey()), p -> p.setType(Type.valueOf(plugin.getType().name())), p -> p.setUpdatedAt(100L));
String response = tester.newRequest().execute().getInput();
verifyNoMoreInteractions(updateCenterMatrixFactory);
assertJson(response).isSimilarTo("{" + " \"plugins\":" + " [" + " {" + " \"key\": \"foo\"," + " \"name\": \"plugName\"," + " \"description\": \"desc_it\"," + " \"version\": \"1.0\"," + " \"license\": \"license_hey\"," + " \"organizationName\": \"org_name\"," + " \"organizationUrl\": \"org_url\",\n" + " \"editionBundled\": false," + " \"homepageUrl\": \"homepage_url\"," + " \"issueTrackerUrl\": \"issueTracker_url\"," + " \"implementationBuild\": \"sou_rev_sha1\"," + " \"sonarLintSupported\": true," + " \"filename\": \"" + plugin.getJar().getFile().getName() + "\"," + " \"hash\": \"" + plugin.getJar().getMd5() + "\"," + " \"updatedAt\": 100" + " }" + " ]" + "}");
}
Aggregations