Search in sources :

Example 6 with ServerPlugin

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

Example 7 with ServerPlugin

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());
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) ServerPlugin(org.sonar.server.plugins.ServerPlugin) Test(org.junit.Test)

Example 8 with ServerPlugin

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());
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) ServerPlugin(org.sonar.server.plugins.ServerPlugin) Test(org.junit.Test)

Example 9 with ServerPlugin

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);
}
Also used : FileAndMd5(org.sonar.server.plugins.PluginFilesAndMd5.FileAndMd5) PluginInfo(org.sonar.core.platform.PluginInfo) ServerPlugin(org.sonar.server.plugins.ServerPlugin) File(java.io.File)

Example 10 with ServerPlugin

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" + "    }" + "  ]" + "}");
}
Also used : ServerPlugin(org.sonar.server.plugins.ServerPlugin) PluginInfo(org.sonar.core.platform.PluginInfo) Test(org.junit.Test)

Aggregations

ServerPlugin (org.sonar.server.plugins.ServerPlugin)17 PluginInfo (org.sonar.core.platform.PluginInfo)9 Test (org.junit.Test)8 FileAndMd5 (org.sonar.server.plugins.PluginFilesAndMd5.FileAndMd5)6 TestResponse (org.sonar.server.ws.TestResponse)4 File (java.io.File)3 DbSession (org.sonar.db.DbSession)2 PluginDto (org.sonar.db.plugin.PluginDto)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 LinkedList (java.util.LinkedList)1 Random (java.util.Random)1 NotFoundException (org.sonar.server.exceptions.NotFoundException)1 PluginFilesAndMd5 (org.sonar.server.plugins.PluginFilesAndMd5)1 PluginWSCommons.buildPluginDetails (org.sonar.server.plugins.ws.PluginWSCommons.buildPluginDetails)1 Plugin (org.sonar.updatecenter.common.Plugin)1