Search in sources :

Example 6 with UpdateCenter

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);
            }
        }
    }
}
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 7 with UpdateCenter

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();
}
Also used : UpdateCenter(org.sonar.updatecenter.common.UpdateCenter) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 8 with UpdateCenter

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;
}
Also used : UpdateCenter(org.sonar.updatecenter.common.UpdateCenter) PluginUpdate(org.sonar.updatecenter.common.PluginUpdate) Nonnull(javax.annotation.Nonnull)

Example 9 with UpdateCenter

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();
}
Also used : UpdateCenter(org.sonar.updatecenter.common.UpdateCenter) URI(java.net.URI) Test(org.junit.Test)

Aggregations

UpdateCenter (org.sonar.updatecenter.common.UpdateCenter)9 File (java.io.File)2 URI (java.net.URI)2 Test (org.junit.Test)2 JsonWriter (org.sonar.api.utils.text.JsonWriter)2 PluginUpdate (org.sonar.updatecenter.common.PluginUpdate)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1 Before (org.junit.Before)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1 HttpDownloader (org.sonar.api.utils.HttpDownloader)1 SonarException (org.sonar.api.utils.SonarException)1 PluginInfo (org.sonar.core.platform.PluginInfo)1 ServerFileSystem (org.sonar.server.platform.ServerFileSystem)1 Plugin (org.sonar.updatecenter.common.Plugin)1 Release (org.sonar.updatecenter.common.Release)1