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"));
}
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\"" + " }" + " ]" + " }" + "}");
}
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);
}
}
}
}
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
}
}
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
}
}
Aggregations