Search in sources :

Example 6 with Plugin

use of org.sonar.updatecenter.common.Plugin in project sonarqube by SonarSource.

the class PluginDownloaderTest method download_from_redirect_url.

/**
   * SONAR-4685
   */
@Test
public void download_from_redirect_url() {
    Plugin test = Plugin.factory("plugintest");
    Release test10 = new Release(test, "1.0").setDownloadUrl("http://server/redirect?r=release&g=test&a=test&v=1.0&e=jar");
    test.addRelease(test10);
    when(updateCenter.findInstallablePlugins("foo", create("1.0"))).thenReturn(newArrayList(test10));
    pluginDownloader.start();
    pluginDownloader.download("foo", create("1.0"));
    // SONAR-4523: do not corrupt JAR files when restarting the server while a plugin is being downloaded.
    // The JAR file is downloaded in a temp file
    verify(httpDownloader).download(any(URI.class), argThat(new HasFileName("plugintest-1.0.jar.tmp")));
    assertThat(new File(downloadDir, "plugintest-1.0.jar")).exists();
    assertThat(new File(downloadDir, "plugintest-1.0.jar.tmp")).doesNotExist();
}
Also used : URI(java.net.URI) File(java.io.File) Release(org.sonar.updatecenter.common.Release) Plugin(org.sonar.updatecenter.common.Plugin) Test(org.junit.Test)

Example 7 with Plugin

use of org.sonar.updatecenter.common.Plugin in project sonarqube by SonarSource.

the class PluginDownloaderTest method download_common_transitive_dependency.

// SONAR-5011
@Test
public void download_common_transitive_dependency() {
    Plugin test1 = Plugin.factory("test1");
    Release test1R = new Release(test1, "1.0").setDownloadUrl("http://server/test1-1.0.jar");
    test1.addRelease(test1R);
    Plugin test2 = Plugin.factory("test2");
    Release test2R = new Release(test2, "1.0").setDownloadUrl("http://server/test2-1.0.jar");
    test2.addRelease(test2R);
    Plugin testDep = Plugin.factory("testdep");
    Release testDepR = new Release(testDep, "1.0").setDownloadUrl("http://server/testdep-1.0.jar");
    testDep.addRelease(testDepR);
    when(updateCenter.findInstallablePlugins("test1", create("1.0"))).thenReturn(newArrayList(test1R, testDepR));
    when(updateCenter.findInstallablePlugins("test2", create("1.0"))).thenReturn(newArrayList(test2R, testDepR));
    pluginDownloader.start();
    pluginDownloader.download("test1", create("1.0"));
    pluginDownloader.download("test2", create("1.0"));
    assertThat(new File(downloadDir, "test1-1.0.jar")).exists();
    assertThat(new File(downloadDir, "test2-1.0.jar")).exists();
    assertThat(new File(downloadDir, "testdep-1.0.jar")).exists();
}
Also used : File(java.io.File) Release(org.sonar.updatecenter.common.Release) Plugin(org.sonar.updatecenter.common.Plugin) Test(org.junit.Test)

Example 8 with Plugin

use of org.sonar.updatecenter.common.Plugin in project sonarqube by SonarSource.

the class PluginDownloaderTest method download_when_update_center_is_unavailable_with_no_exception_thrown.

@Test
public void download_when_update_center_is_unavailable_with_no_exception_thrown() {
    when(updateCenterMatrixFactory.getUpdateCenter(anyBoolean())).thenReturn(Optional.<UpdateCenter>absent());
    Plugin test = Plugin.factory("test");
    Release test10 = new Release(test, "1.0").setDownloadUrl("http://server/test-1.0.jar");
    test.addRelease(test10);
    pluginDownloader.start();
    pluginDownloader.download("foo", create("1.0"));
}
Also used : Release(org.sonar.updatecenter.common.Release) Plugin(org.sonar.updatecenter.common.Plugin) Test(org.junit.Test)

Example 9 with Plugin

use of org.sonar.updatecenter.common.Plugin in project sonarqube by SonarSource.

the class PendingActionTest method newUpdateCenter.

private UpdateCenter newUpdateCenter(String... pluginKeys) {
    UpdateCenter updateCenter = mock(UpdateCenter.class);
    when(updateCenterMatrixFactory.getUpdateCenter(false)).thenReturn(Optional.of(updateCenter));
    List<Plugin> plugins = new ArrayList<>();
    for (String pluginKey : pluginKeys) {
        plugins.add(Plugin.factory(pluginKey).setCategory("cat_1"));
    }
    when(updateCenter.findAllCompatiblePlugins()).thenReturn(plugins);
    return updateCenter;
}
Also used : UpdateCenter(org.sonar.updatecenter.common.UpdateCenter) ArrayList(java.util.ArrayList) Plugin(org.sonar.updatecenter.common.Plugin)

Example 10 with Plugin

use of org.sonar.updatecenter.common.Plugin in project sonarqube by SonarSource.

the class PendingAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    userSession.checkIsSystemAdministrator();
    ImmutableMap<String, Plugin> compatiblePluginsByKey = compatiblePluginsByKey(updateCenterMatrixFactory);
    JsonWriter jsonWriter = response.newJsonWriter();
    jsonWriter.beginObject();
    writePlugins(jsonWriter, compatiblePluginsByKey);
    jsonWriter.endObject();
    jsonWriter.close();
}
Also used : JsonWriter(org.sonar.api.utils.text.JsonWriter) Plugin(org.sonar.updatecenter.common.Plugin)

Aggregations

Plugin (org.sonar.updatecenter.common.Plugin)16 Release (org.sonar.updatecenter.common.Release)9 Test (org.junit.Test)7 File (java.io.File)5 URI (java.net.URI)4 SonarException (org.sonar.api.utils.SonarException)2 ArrayList (java.util.ArrayList)1 JsonWriter (org.sonar.api.utils.text.JsonWriter)1 PluginInfo (org.sonar.core.platform.PluginInfo)1 PluginUpdate (org.sonar.updatecenter.common.PluginUpdate)1 Sonar (org.sonar.updatecenter.common.Sonar)1 SonarUpdate (org.sonar.updatecenter.common.SonarUpdate)1 UpdateCenter (org.sonar.updatecenter.common.UpdateCenter)1