public static IStatus testConnection(String url, @Nullable String organization, @Nullable String username, @Nullable String password) {
try {
Builder builder = getConfigBuilderNoCredentials(url, organization);
if (StringUtils.isNotBlank(username) || StringUtils.isNotBlank(password)) {
builder.credentials(username, password);
}
WsHelper helper = new WsHelperImpl();
ValidationResult testConnection = helper.validateConnection(builder.build());
if (testConnection.success()) {
return new Status(IStatus.OK, SonarLintCorePlugin.PLUGIN_ID, "Successfully connected!");
} else {
return new Status(IStatus.ERROR, SonarLintCorePlugin.PLUGIN_ID, testConnection.message());
}
} catch (Exception e) {
if (e.getCause() instanceof UnknownHostException) {
return new Status(IStatus.ERROR, SonarLintCorePlugin.PLUGIN_ID, "Unknown host: " + url);
}
SonarLintLogger.get().debug(e.getMessage(), e);
return new Status(IStatus.ERROR, SonarLintCorePlugin.PLUGIN_ID, e.getMessage(), e);
}
}