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); } }
@Override public void run(@NotNull ProgressIndicator indicator) { indicator.setText("Connecting to " + server.getHostUrl() + "..."); indicator.setIndeterminate(true); try { ServerConfiguration serverConfiguration = SonarLintUtils.getServerConfiguration(server); WsHelper wsHelper = new WsHelperImpl(); result = wsHelper.validateConnection(serverConfiguration); } catch (Exception e) { String msg = "Connection test failed"; LOGGER.info(msg, e); GlobalLogOutput.get().logError(msg, e); exception = e; } }