Search in sources :

Example 11 with ServerPlugin

use of org.sonar.server.plugins.ServerPlugin in project sonarqube by SonarSource.

the class RegisterPluginsTest method addPlugin.

private ServerPlugin addPlugin(String key, PluginType type, @Nullable String basePlugin) throws IOException {
    File file = createPluginFile(key);
    PluginFilesAndMd5.FileAndMd5 jar = new PluginFilesAndMd5.FileAndMd5(file);
    PluginInfo info = new PluginInfo(key).setBasePlugin(basePlugin).setJarFile(file);
    ServerPlugin serverPlugin = new ServerPlugin(info, type, null, jar, null, null);
    serverPluginRepository.addPlugin(serverPlugin);
    return serverPlugin;
}
Also used : PluginInfo(org.sonar.core.platform.PluginInfo) ServerPlugin(org.sonar.server.plugins.ServerPlugin) PluginFilesAndMd5(org.sonar.server.plugins.PluginFilesAndMd5) File(java.io.File)

Example 12 with ServerPlugin

use of org.sonar.server.plugins.ServerPlugin in project sonarqube by SonarSource.

the class InstalledActionTest method return_compression_fields_if_available.

@Test
public void return_compression_fields_if_available() throws Exception {
    ServerPlugin plugin = newInstalledPluginWithCompression(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").setDocumentationPath("static/documentation.md").setSonarLintSupported(true));
    when(serverPluginRepository.getPlugins()).thenReturn(singletonList(plugin));
    db.pluginDbTester().insertPlugin(p -> p.setKee(plugin.getPluginInfo().getKey()), p -> p.setType(Type.EXTERNAL), p -> p.setUpdatedAt(100L));
    String response = tester.newRequest().execute().getInput();
    verifyZeroInteractions(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," + "      \"documentationPath\": \"static/documentation.md\"," + "      \"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)

Example 13 with ServerPlugin

use of org.sonar.server.plugins.ServerPlugin in project sonarqube by SonarSource.

the class InstalledActionTest method newInstalledPluginWithCompression.

private ServerPlugin newInstalledPluginWithCompression(PluginInfo plugin) throws IOException {
    FileAndMd5 jar = new FileAndMd5(temp.newFile());
    FileAndMd5 compressedJar = new FileAndMd5(temp.newFile());
    return new ServerPlugin(plugin, PluginType.BUNDLED, null, jar, compressedJar, null);
}
Also used : FileAndMd5(org.sonar.server.plugins.PluginFilesAndMd5.FileAndMd5) ServerPlugin(org.sonar.server.plugins.ServerPlugin)

Example 14 with ServerPlugin

use of org.sonar.server.plugins.ServerPlugin in project sonarqube by SonarSource.

the class InstalledActionTest method commercial_plugins_from_SonarSource_has_flag_editionBundled_true_based_on_jar_info.

@Test
@UseDataProvider("editionBundledLicenseValues")
public void commercial_plugins_from_SonarSource_has_flag_editionBundled_true_based_on_jar_info(String license) throws Exception {
    String jarFilename = getClass().getSimpleName() + "/" + "some.jar";
    Random random = new Random();
    String organization = random.nextBoolean() ? "SonarSource" : "SONARSOURCE";
    String pluginKey = "plugKey";
    File jar = new File(getClass().getResource(jarFilename).toURI());
    when(serverPluginRepository.getPlugins()).thenReturn(asList(new ServerPlugin(new PluginInfo(pluginKey).setName("plugName").setVersion(Version.create("1.0")).setLicense(license).setOrganizationName(organization).setImplementationBuild("sou_rev_sha1"), PluginType.BUNDLED, null, new FileAndMd5(jar), new FileAndMd5(jar), null)));
    db.pluginDbTester().insertPlugin(p -> p.setKee(pluginKey), p -> p.setType(Type.BUNDLED), p -> p.setFileHash("abcdplugKey"), p -> p.setUpdatedAt(111111L));
    // ensure flag editionBundled is computed from jar info by enabling datacenter with other organization and license values
    UpdateCenter updateCenter = mock(UpdateCenter.class);
    when(updateCenterMatrixFactory.getUpdateCenter(false)).thenReturn(Optional.of(updateCenter));
    when(updateCenter.findAllCompatiblePlugins()).thenReturn(singletonList(Plugin.factory(pluginKey).setOrganization("foo").setLicense("bar").setCategory("cat_1")));
    String response = tester.newRequest().execute().getInput();
    verifyZeroInteractions(updateCenterMatrixFactory);
    assertJson(response).isSimilarTo("{" + "  \"plugins\":" + "  [" + "    {" + "      \"key\": \"plugKey\"," + "      \"name\": \"plugName\"," + "      \"license\": \"" + license + "\"," + "      \"organizationName\": \"" + organization + "\"," + "      \"editionBundled\": true" + "    }" + "  ]" + "}");
}
Also used : FileAndMd5(org.sonar.server.plugins.PluginFilesAndMd5.FileAndMd5) UpdateCenter(org.sonar.updatecenter.common.UpdateCenter) Random(java.util.Random) ServerPlugin(org.sonar.server.plugins.ServerPlugin) PluginInfo(org.sonar.core.platform.PluginInfo) File(java.io.File) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 15 with ServerPlugin

use of org.sonar.server.plugins.ServerPlugin in project sonarqube by SonarSource.

the class DownloadActionTest method return_jar_if_plugin_exists.

@Test
public void return_jar_if_plugin_exists() throws Exception {
    ServerPlugin plugin = newPlugin();
    when(serverPluginRepository.findPlugin(plugin.getPluginInfo().getKey())).thenReturn(Optional.of(plugin));
    TestResponse response = tester.newRequest().setParam("plugin", plugin.getPluginInfo().getKey()).execute();
    assertThat(response.getHeader("Sonar-MD5")).isEqualTo(plugin.getJar().getMd5());
    assertThat(response.getHeader("Sonar-Compression")).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)

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