Search in sources :

Example 1 with UnsupportedServerException

use of org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException in project sonarlint-core by SonarSource.

the class WsHelperImplTest method testListOrganizations.

@Test
public void testListOrganizations() {
    WsClientTestUtils.addStreamResponse(client, "api/organizations/search.protobuf?ps=500&p=1", "/orgs/orgsp1.pb");
    WsClientTestUtils.addStreamResponse(client, "api/organizations/search.protobuf?ps=500&p=2", "/orgs/orgsp2.pb");
    WsClientTestUtils.addStreamResponse(client, "api/organizations/search.protobuf?ps=500&p=3", "/orgs/orgsp3.pb");
    List<RemoteOrganization> orgs = WsHelperImpl.listOrganizations(client, serverChecker, new ProgressWrapper(null));
    assertThat(orgs).hasSize(4);
    verify(serverChecker).checkVersionAndStatus("6.3");
    when(serverChecker.checkVersionAndStatus("6.3")).thenThrow(UnsupportedServerException.class);
    try {
        WsHelperImpl.listOrganizations(client, serverChecker, new ProgressWrapper(null));
        fail("Expected exception");
    } catch (UnsupportedServerException e) {
    // Success
    }
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) RemoteOrganization(org.sonarsource.sonarlint.core.client.api.connected.RemoteOrganization) UnsupportedServerException(org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException) Test(org.junit.Test)

Example 2 with UnsupportedServerException

use of org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException in project sonarlint-core by SonarSource.

the class ServerVersionAndStatusChecker method checkVersionAndStatus.

/**
 * Checks SonarQube version against a provided minimum version
 * @return ServerInfos
 * @throws UnsupportedServerException if version &lt; minimum supported version
 * @throws IllegalStateException If server is not ready
 */
public ServerInfos checkVersionAndStatus(String minVersion) {
    ServerInfos serverStatus = fetchServerInfos();
    if (!"UP".equals(serverStatus.getStatus())) {
        throw new IllegalStateException(serverNotReady(serverStatus));
    }
    Version serverVersion = Version.create(serverStatus.getVersion());
    if (serverVersion.compareToIgnoreQualifier(Version.create(minVersion)) < 0) {
        throw new UnsupportedServerException(unsupportedVersion(serverStatus, minVersion));
    }
    return serverStatus;
}
Also used : Version(org.sonarsource.sonarlint.core.plugin.Version) ServerInfos(org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos) UnsupportedServerException(org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException)

Example 3 with UnsupportedServerException

use of org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException in project sonarlint-intellij by SonarSource.

the class InformationFetchTask method run.

@Override
public void run(@NotNull ProgressIndicator indicator) {
    indicator.setText("Connecting to " + server.getHostUrl() + "...");
    indicator.setIndeterminate(false);
    try {
        ServerConfiguration serverConfiguration = SonarLintUtils.getServerConfiguration(server);
        indicator.setText("Checking support of notifications");
        notificationsSupported = SonarQubeNotifications.get().isSupported(serverConfiguration);
        WsHelper wsHelper = new WsHelperImpl();
        organizations = wsHelper.listOrganizations(serverConfiguration, new TaskProgressMonitor(indicator));
    } catch (UnsupportedServerException e) {
        organizations = Collections.emptyList();
    } catch (Exception e) {
        LOGGER.info("Failed to fetch information", e);
        exception = e;
    }
}
Also used : WsHelperImpl(org.sonarsource.sonarlint.core.WsHelperImpl) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) WsHelper(org.sonarsource.sonarlint.core.client.api.connected.WsHelper) TaskProgressMonitor(org.sonarlint.intellij.util.TaskProgressMonitor) UnsupportedServerException(org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException) UnsupportedServerException(org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException)

Example 4 with UnsupportedServerException

use of org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException in project sonarlint-core by SonarSource.

the class WsHelperImpl method validateConnection.

static ValidationResult validateConnection(SonarLintWsClient client, @Nullable String organizationKey) {
    ServerVersionAndStatusChecker serverChecker = new ServerVersionAndStatusChecker(client);
    AuthenticationChecker authChecker = new AuthenticationChecker(client);
    try {
        ServerInfos serverStatus = serverChecker.checkVersionAndStatus();
        ValidationResult validateCredentials = authChecker.validateCredentials();
        if (validateCredentials.success() && organizationKey != null) {
            Version serverVersion = Version.create(serverStatus.getVersion());
            if (serverVersion.compareToIgnoreQualifier(Version.create(MIN_VERSION_FOR_ORGANIZATIONS)) < 0) {
                return new DefaultValidationResult(false, "No organization support for this server version: " + serverStatus.getVersion());
            }
            if (fetchOrganizations(client, organizationKey, new ProgressWrapper(null)).isEmpty()) {
                return new DefaultValidationResult(false, "No organizations found for key: " + organizationKey);
            }
        }
        return validateCredentials;
    } catch (UnsupportedServerException e) {
        return new DefaultValidationResult(false, e.getMessage());
    } catch (RuntimeException e) {
        throw SonarLintWrappedException.wrap(e);
    }
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) ServerVersionAndStatusChecker(org.sonarsource.sonarlint.core.container.connected.validate.ServerVersionAndStatusChecker) Version(org.sonarsource.sonarlint.core.plugin.Version) AuthenticationChecker(org.sonarsource.sonarlint.core.container.connected.validate.AuthenticationChecker) DefaultValidationResult(org.sonarsource.sonarlint.core.container.connected.validate.DefaultValidationResult) ServerInfos(org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos) ValidationResult(org.sonarsource.sonarlint.core.client.api.connected.ValidationResult) DefaultValidationResult(org.sonarsource.sonarlint.core.container.connected.validate.DefaultValidationResult) UnsupportedServerException(org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException)

Aggregations

UnsupportedServerException (org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException)4 Version (org.sonarsource.sonarlint.core.plugin.Version)2 ServerInfos (org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos)2 ProgressWrapper (org.sonarsource.sonarlint.core.util.ProgressWrapper)2 Test (org.junit.Test)1 TaskProgressMonitor (org.sonarlint.intellij.util.TaskProgressMonitor)1 WsHelperImpl (org.sonarsource.sonarlint.core.WsHelperImpl)1 RemoteOrganization (org.sonarsource.sonarlint.core.client.api.connected.RemoteOrganization)1 ServerConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration)1 ValidationResult (org.sonarsource.sonarlint.core.client.api.connected.ValidationResult)1 WsHelper (org.sonarsource.sonarlint.core.client.api.connected.WsHelper)1 AuthenticationChecker (org.sonarsource.sonarlint.core.container.connected.validate.AuthenticationChecker)1 DefaultValidationResult (org.sonarsource.sonarlint.core.container.connected.validate.DefaultValidationResult)1 ServerVersionAndStatusChecker (org.sonarsource.sonarlint.core.container.connected.validate.ServerVersionAndStatusChecker)1