use of org.sonar.updatecenter.common.UpdateCenter 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.UpdateCenter in project sonarqube by SonarSource.
the class UpdatesAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkIsSystemAdministrator();
JsonWriter jsonWriter = response.newJsonWriter();
jsonWriter.beginObject();
Optional<UpdateCenter> updateCenter = updateCenterMatrixFactory.getUpdateCenter(DO_NOT_FORCE_REFRESH);
writePlugins(jsonWriter, updateCenter);
pluginWSCommons.writeUpdateCenterProperties(jsonWriter, updateCenter);
jsonWriter.endObject();
jsonWriter.close();
}
use of org.sonar.updatecenter.common.UpdateCenter in project sonarqube by SonarSource.
the class UpdateAction method findPluginUpdateByKey.
@Nonnull
private PluginUpdate findPluginUpdateByKey(String key) {
Optional<UpdateCenter> updateCenter = updateCenterFactory.getUpdateCenter(false);
PluginUpdate pluginUpdate = MISSING_PLUGIN;
if (updateCenter.isPresent()) {
pluginUpdate = Iterables.find(updateCenter.get().findPluginUpdates(), new PluginKeyPredicate(key), MISSING_PLUGIN);
}
if (pluginUpdate == MISSING_PLUGIN) {
throw new IllegalArgumentException(format("No plugin with key '%s' or plugin '%s' is already in latest compatible version", key, key));
}
return pluginUpdate;
}
use of org.sonar.updatecenter.common.UpdateCenter in project sonarqube by SonarSource.
the class UpdateCenterClientTest method downloadUpdateCenter.
@Test
public void downloadUpdateCenter() throws URISyntaxException {
when(reader.readString(new URI(BASE_URL), StandardCharsets.UTF_8)).thenReturn("publicVersions=2.2,2.3");
UpdateCenter plugins = underTest.getUpdateCenter().get();
verify(reader, times(1)).readString(new URI(BASE_URL), StandardCharsets.UTF_8);
assertThat(plugins.getSonar().getVersions()).containsOnly(Version.create("2.2"), Version.create("2.3"));
assertThat(underTest.getLastRefreshDate()).isNotNull();
}
Aggregations