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
}
}
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 < 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;
}
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;
}
}
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);
}
}
Aggregations