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 Optional<RemoteProject> getRemoteProject(String projectKey, IProgressMonitor monitor) { RemoteProject remoteProjectFromStorage = allProjectsByKey.get(projectKey); if (remoteProjectFromStorage != null) { return Optional.of(remoteProjectFromStorage); } else { WsHelper helper = new WsHelperImpl(); Optional<RemoteProject> project = helper.getProject(getConfig(), projectKey, new WrappedProgressMonitor(monitor, "Fetch project name")); if (project.isPresent()) { allProjectsByKey.put(projectKey, project.get()); } return project; } }
@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.listUserOrganizations(serverConfiguration, new TaskProgressMonitor(indicator)); } catch (UnsupportedServerException e) { organizations = Collections.emptyList(); } catch (Exception e) { LOGGER.info("Failed to fetch information", e); exception = e; } }
@Override public void run(@NotNull ProgressIndicator indicator) { indicator.setText("Connecting to " + server.getHostUrl() + "..."); indicator.setIndeterminate(false); try { ServerConfiguration serverConfiguration = SonarLintUtils.getServerConfiguration(server); indicator.setText("Searching organization"); WsHelper wsHelper = new WsHelperImpl(); organization = wsHelper.getOrganization(serverConfiguration, organizationKey, new TaskProgressMonitor(indicator)); } catch (Exception e) { LOGGER.info("Failed to fetch information", e); exception = e; } }
public static List<RemoteOrganization> listUserOrganizations(String url, String username, String password, IProgressMonitor monitor) { Builder builder = getConfigBuilderNoCredentials(url, null); if (StringUtils.isNotBlank(username) || StringUtils.isNotBlank(password)) { builder.credentials(username, password); } WsHelper helper = new WsHelperImpl(); return helper.listUserOrganizations(builder.build(), new WrappedProgressMonitor(monitor, "Fetch organizations")); }
@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; } }