Search in sources :

Example 16 with ServerConfiguration

use of org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration in project sonarlint-core by SonarSource.

the class ConnectedModeTest method generateToken.

@Test
public void generateToken() {
    WsHelper ws = new WsHelperImpl();
    ServerConfiguration serverConfig = getServerConfig(true);
    if (!ORCHESTRATOR.getServer().version().isGreaterThanOrEquals("5.4")) {
        exception.expect(UnsupportedServerException.class);
    }
    String token = ws.generateAuthenticationToken(serverConfig, "name", false);
    assertThat(token).isNotNull();
    token = ws.generateAuthenticationToken(serverConfig, "name", true);
    assertThat(token).isNotNull();
}
Also used : WsHelperImpl(org.sonarsource.sonarlint.core.WsHelperImpl) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) WsHelper(org.sonarsource.sonarlint.core.client.api.connected.WsHelper) Test(org.junit.Test)

Example 17 with ServerConfiguration

use of org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration in project sonarlint-core by SonarSource.

the class NotificationConfigurationTest method testGetters.

@Test
public void testGetters() {
    SonarQubeNotificationListener listener = mock(SonarQubeNotificationListener.class);
    LastNotificationTime lastNotificationTime = mock(LastNotificationTime.class);
    String projectKey = "key";
    ServerConfiguration serverConfiguration = mock(ServerConfiguration.class);
    NotificationConfiguration configuration = new NotificationConfiguration(listener, lastNotificationTime, projectKey, serverConfiguration);
    assertThat(configuration.lastNotificationTime()).isEqualTo(lastNotificationTime);
    assertThat(configuration.listener()).isEqualTo(listener);
    assertThat(configuration.projectKey()).isEqualTo(projectKey);
    assertThat(configuration.serverConfiguration()).isEqualTo(serverConfiguration);
}
Also used : LastNotificationTime(org.sonarsource.sonarlint.core.client.api.notifications.LastNotificationTime) SonarQubeNotificationListener(org.sonarsource.sonarlint.core.client.api.notifications.SonarQubeNotificationListener) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) Test(org.junit.Test)

Example 18 with ServerConfiguration

use of org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration in project sonarlint-intellij by SonarSource.

the class SonarQubeEventNotifications method createConfiguration.

private NotificationConfiguration createConfiguration(SonarLintProjectSettings settings, SonarQubeServer server) {
    String projectKey = settings.getProjectKey();
    ServerConfiguration serverConfiguration = SonarLintUtils.getServerConfiguration(server);
    return new NotificationConfiguration(eventListener, notificationTime, projectKey, serverConfiguration);
}
Also used : ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) NotificationConfiguration(org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration)

Example 19 with ServerConfiguration

use of org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration in project sonarlint-intellij by SonarSource.

the class UpdateChecker method checkForUpdate.

void checkForUpdate() {
    ConnectedSonarLintEngine engine;
    try {
        engine = projectBindingManager.getConnectedEngine();
    } catch (Exception e) {
        // happens if project is not bound, binding is invalid, storages are not updated, ...
        log.log("Couldn't get a connected engine to check for update: " + e.getMessage(), LogOutput.Level.DEBUG);
        return;
    }
    try {
        List<String> changelog = new ArrayList<>();
        ServerConfiguration serverConfiguration = SonarLintUtils.getServerConfiguration(projectBindingManager.getSonarQubeServer());
        log.log("Check for updates from server '" + projectBindingManager.getSonarQubeServer().getName() + "'...", LogOutput.Level.INFO);
        boolean hasGlobalUpdates = checkForGlobalUpdates(changelog, engine, serverConfiguration);
        log.log("Check for updates from server '" + projectBindingManager.getSonarQubeServer().getName() + "' for project '" + projectSettings.getProjectKey() + "'...", LogOutput.Level.INFO);
        checkForProjectUpdates(changelog, engine, serverConfiguration);
        if (!changelog.isEmpty()) {
            changelog.forEach(line -> log.log("  - " + line, LogOutput.Level.INFO));
            notifications.notifyServerHasUpdates(projectSettings.getServerId(), engine, projectBindingManager.getSonarQubeServer(), !hasGlobalUpdates);
        }
    } catch (Exception e) {
        log.log("There was an error while checking for updates: " + e.getMessage(), LogOutput.Level.WARN);
    }
}
Also used : ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) ArrayList(java.util.ArrayList) ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine)

Example 20 with ServerConfiguration

use of org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration in project sonarlint-intellij by SonarSource.

the class SonarLintUtils method getServerConfiguration.

public static ServerConfiguration getServerConfiguration(SonarQubeServer server, int connectTimeout, int readTimeout) {
    CertificateManager certificateManager = get(CertificateManager.class);
    SonarApplication sonarlint = get(SonarApplication.class);
    ServerConfiguration.Builder serverConfigBuilder = ServerConfiguration.builder().userAgent("SonarLint IntelliJ " + sonarlint.getVersion()).connectTimeoutMilliseconds(connectTimeout).readTimeoutMilliseconds(readTimeout).sslSocketFactory(certificateManager.getSslContext().getSocketFactory()).trustManager(certificateManager.getCustomTrustManager()).url(server.getHostUrl());
    if (!isBlank(server.getOrganizationKey())) {
        serverConfigBuilder.organizationKey(server.getOrganizationKey());
    }
    if (!isBlank(server.getToken())) {
        serverConfigBuilder.token(server.getToken());
    } else {
        serverConfigBuilder.credentials(server.getLogin(), server.getPassword());
    }
    if (server.enableProxy()) {
        configureProxy(server.getHostUrl(), serverConfigBuilder);
    }
    return serverConfigBuilder.build();
}
Also used : SonarApplication(org.sonarlint.intellij.SonarApplication) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) CertificateManager(com.intellij.util.net.ssl.CertificateManager)

Aggregations

ServerConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration)22 Test (org.junit.Test)10 ConnectedSonarLintEngine (org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine)6 List (java.util.List)4 Map (java.util.Map)4 WsHelperImpl (org.sonarsource.sonarlint.core.WsHelperImpl)4 WsHelper (org.sonarsource.sonarlint.core.client.api.connected.WsHelper)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 Nullable (javax.annotation.Nullable)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 SonarApplication (org.sonarlint.intellij.SonarApplication)3 TaskProgressMonitor (org.sonarlint.intellij.util.TaskProgressMonitor)3 AnalysisResults (org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults)3 ConnectedGlobalConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration)3 SonarAnalyzer (org.sonarsource.sonarlint.core.client.api.connected.SonarAnalyzer)3 StorageUpdateCheckResult (org.sonarsource.sonarlint.core.client.api.connected.StorageUpdateCheckResult)3 UpdateResult (org.sonarsource.sonarlint.core.client.api.connected.UpdateResult)3 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2