Search in sources :

Example 6 with Release

use of org.sonar.updatecenter.common.Release 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 7 with Release

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

the class PluginWSCommonsTest method writeUpdate_renders_key_name_and_description_of_requirements.

@Test
public void writeUpdate_renders_key_name_and_description_of_requirements() {
    PluginUpdate pluginUpdate = new PluginUpdate();
    pluginUpdate.setRelease(new Release(newPlugin(), version("1.0")).addOutgoingDependency(newRelease()));
    jsonWriter.beginObject();
    underTest.writeUpdate(jsonWriter, pluginUpdate);
    jsonWriter.endObject();
    jsonWriter.close();
    assertJson(response.outputAsString()).isSimilarTo("{" + "  \"update\": {" + "    \"requires\": [" + "      {" + "        \"key\": \"pkey\"," + "        \"name\": \"p_name\"," + "        \"description\": \"p_description\"" + "      }" + "   ]" + "  }" + "}");
}
Also used : PluginUpdate(org.sonar.updatecenter.common.PluginUpdate) Release(org.sonar.updatecenter.common.Release) Test(org.junit.Test)

Example 8 with Release

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

the class PluginDownloader method download.

public void download(String pluginKey, Version version) {
    Optional<UpdateCenter> updateCenter = updateCenterMatrixFactory.getUpdateCenter(true);
    if (updateCenter.isPresent()) {
        List<Release> installablePlugins = updateCenter.get().findInstallablePlugins(pluginKey, version);
        checkRequest(!installablePlugins.isEmpty(), "Error while downloading plugin '%s' with version '%s'. No compatible plugin found.", pluginKey, version.getName());
        for (Release release : installablePlugins) {
            try {
                downloadRelease(release);
            } catch (Exception e) {
                String message = String.format("Fail to download the plugin (%s, version %s) from %s (error is : %s)", release.getArtifact().getKey(), release.getVersion().getName(), release.getDownloadUrl(), e.getMessage());
                LOG.debug(message, e);
                throw new SonarException(message, e);
            }
        }
    }
}
Also used : UpdateCenter(org.sonar.updatecenter.common.UpdateCenter) SonarException(org.sonar.api.utils.SonarException) Release(org.sonar.updatecenter.common.Release) SonarException(org.sonar.api.utils.SonarException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 9 with Release

use of org.sonar.updatecenter.common.Release 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 10 with Release

use of org.sonar.updatecenter.common.Release 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)

Aggregations

Release (org.sonar.updatecenter.common.Release)14 Test (org.junit.Test)10 Plugin (org.sonar.updatecenter.common.Plugin)9 File (java.io.File)5 URI (java.net.URI)4 SonarException (org.sonar.api.utils.SonarException)3 Version (org.sonar.updatecenter.common.Version)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 WsTester (org.sonar.server.ws.WsTester)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