Search in sources :

Example 6 with ServerInfos

use of org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos 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)

Example 7 with ServerInfos

use of org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos in project sonarlint-core by SonarSource.

the class ServerVersionAndStatusChecker method validateStatusAndVersion.

public ValidationResult validateStatusAndVersion(String minVersion) {
    ServerInfos serverStatus = fetchServerInfos();
    if (!"UP".equals(serverStatus.getStatus())) {
        return new DefaultValidationResult(false, serverNotReady(serverStatus));
    }
    Version serverVersion = Version.create(serverStatus.getVersion());
    if (serverVersion.compareToIgnoreQualifier(Version.create(minVersion)) < 0) {
        return new DefaultValidationResult(false, unsupportedVersion(serverStatus, minVersion));
    }
    return new DefaultValidationResult(true, "Compatible and ready");
}
Also used : Version(org.sonarsource.sonarlint.core.plugin.Version) ServerInfos(org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos)

Example 8 with ServerInfos

use of org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos in project sonarlint-core by SonarSource.

the class ServerVersionAndStatusChecker method tryFromDeprecatedApi.

private ServerInfos tryFromDeprecatedApi(WsResponse originalReponse) {
    // Maybe a server version prior to 5.2. Fallback on deprecated api/server/version
    try (WsResponse responseFallback = wsClient.rawGet("api/server/version")) {
        if (!responseFallback.isSuccessful()) {
            // We prefer to report original error
            throw SonarLintWsClient.handleError(originalReponse);
        }
        String responseStr = responseFallback.content();
        ServerInfos.Builder builder = ServerInfos.newBuilder();
        builder.setStatus("UP");
        builder.setVersion(trimToEmpty(responseStr));
        return builder.build();
    }
}
Also used : WsResponse(org.sonarsource.sonarlint.core.util.ws.WsResponse) ServerInfos(org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos)

Aggregations

ServerInfos (org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos)8 Version (org.sonarsource.sonarlint.core.plugin.Version)3 SonarAnalyzer (org.sonarsource.sonarlint.core.client.api.connected.SonarAnalyzer)2 UnsupportedServerException (org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException)2 StorageStatus (org.sonarsource.sonarlint.core.proto.Sonarlint.StorageStatus)2 ProgressWrapper (org.sonarsource.sonarlint.core.util.ProgressWrapper)2 WsResponse (org.sonarsource.sonarlint.core.util.ws.WsResponse)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Path (java.nio.file.Path)1 Date (java.util.Date)1 Test (org.junit.Test)1 ValidationResult (org.sonarsource.sonarlint.core.client.api.connected.ValidationResult)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