Search in sources :

Example 11 with Plugin

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

the class PluginWSCommons method writePluginInfoList.

public void writePluginInfoList(JsonWriter json, Iterable<PluginInfo> plugins, Map<String, Plugin> compatiblePluginsByKey, String propertyName) {
    json.name(propertyName);
    json.beginArray();
    for (PluginInfo pluginInfo : copyOf(NAME_KEY_PLUGIN_METADATA_COMPARATOR, plugins)) {
        Plugin plugin = compatiblePluginsByKey.get(pluginInfo.getKey());
        writePluginInfo(json, pluginInfo, categoryOrNull(plugin));
    }
    json.endArray();
}
Also used : PluginInfo(org.sonar.core.platform.PluginInfo) Plugin(org.sonar.updatecenter.common.Plugin)

Example 12 with Plugin

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

the class PluginWSCommons method writePluginUpdate.

public void writePluginUpdate(JsonWriter json, PluginUpdate pluginUpdate) {
    Plugin plugin = pluginUpdate.getPlugin();
    json.beginObject();
    writePlugin(json, plugin);
    writeRelease(json, pluginUpdate.getRelease());
    writeUpdate(json, pluginUpdate);
    json.endObject();
}
Also used : Plugin(org.sonar.updatecenter.common.Plugin)

Example 13 with Plugin

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

the class PluginDownloaderTest method throw_exception_if_could_not_download.

@Test
public void throw_exception_if_could_not_download() {
    Plugin test = Plugin.factory("test");
    Release test10 = new Release(test, "1.0").setDownloadUrl("file://not_found");
    test.addRelease(test10);
    when(updateCenter.findInstallablePlugins("foo", create("1.0"))).thenReturn(newArrayList(test10));
    pluginDownloader.start();
    try {
        pluginDownloader.download("foo", create("1.0"));
        fail();
    } catch (SonarException e) {
    // ok
    }
}
Also used : SonarException(org.sonar.api.utils.SonarException) Release(org.sonar.updatecenter.common.Release) Plugin(org.sonar.updatecenter.common.Plugin) Test(org.junit.Test)

Example 14 with Plugin

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

the class PluginDownloaderTest method throw_exception_if_download_fail.

@Test
public void throw_exception_if_download_fail() {
    Plugin test = Plugin.factory("test");
    Release test10 = new Release(test, "1.0").setDownloadUrl("http://server/test-1.0.jar");
    test.addRelease(test10);
    when(updateCenter.findInstallablePlugins("foo", create("1.0"))).thenReturn(newArrayList(test10));
    doThrow(new RuntimeException()).when(httpDownloader).download(any(URI.class), any(File.class));
    pluginDownloader.start();
    try {
        pluginDownloader.download("foo", create("1.0"));
        fail();
    } catch (SonarException e) {
    // ok
    }
}
Also used : SonarException(org.sonar.api.utils.SonarException) 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 15 with Plugin

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

the class PluginDownloaderTest method download_from_url.

@Test
public void download_from_url() {
    Plugin test = Plugin.factory("test");
    Release test10 = new Release(test, "1.0").setDownloadUrl("http://server/test-1.0.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("test-1.0.jar.tmp")));
    assertThat(new File(downloadDir, "test-1.0.jar")).exists();
    assertThat(new File(downloadDir, "test-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)

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