Search in sources :

Example 1 with ServerConfiguration

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

the class NotificationTimerTask method requestForServer.

private void requestForServer(ServerConfiguration serverConfiguration, List<NotificationConfiguration> configs) {
    try {
        Map<String, ZonedDateTime> request = configs.stream().collect(Collectors.toMap(NotificationConfiguration::projectKey, NotificationTimerTask::getLastNotificationTime, MERGE_TIMES));
        NotificationChecker notificationChecker = checkerFactory.create(serverConfiguration);
        List<SonarQubeNotification> notifications = notificationChecker.request(request);
        for (SonarQubeNotification n : notifications) {
            Stream<NotificationConfiguration> matchingConfStream = configs.stream();
            if (n.projectKey() != null) {
                matchingConfStream = matchingConfStream.filter(c -> c.projectKey().equals(n.projectKey()));
            }
            matchingConfStream.forEach(c -> {
                c.listener().handle(n);
                c.lastNotificationTime().set(n.time());
            });
        }
    } catch (Exception e) {
        LOG.warn("Failed to request SonarQube events to " + serverConfiguration.getUrl(), e);
    }
}
Also used : Logger(org.slf4j.Logger) ZonedDateTime(java.time.ZonedDateTime) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) SonarQubeNotification(org.sonarsource.sonarlint.core.client.api.notifications.SonarQubeNotification) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) Collectors(java.util.stream.Collectors) BinaryOperator(java.util.function.BinaryOperator) ArrayList(java.util.ArrayList) List(java.util.List) Stream(java.util.stream.Stream) NotificationConfiguration(org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration) Map(java.util.Map) TimerTask(java.util.TimerTask) Collections(java.util.Collections) ZonedDateTime(java.time.ZonedDateTime) SonarQubeNotification(org.sonarsource.sonarlint.core.client.api.notifications.SonarQubeNotification) NotificationConfiguration(org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration)

Example 2 with ServerConfiguration

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

the class ConnectedModeTest method checkForUpdate.

@Test
public void checkForUpdate() throws Exception {
    updateGlobal();
    updateModule(PROJECT_KEY_JAVA);
    ServerConfiguration serverConfig = getServerConfig(true);
    StorageUpdateCheckResult result = engine.checkIfGlobalStorageNeedUpdate(serverConfig, null);
    assertThat(result.needUpdate()).isFalse();
    // restarting server should not lead to notify an update
    ORCHESTRATOR.restartServer();
    result = engine.checkIfGlobalStorageNeedUpdate(serverConfig, null);
    assertThat(result.needUpdate()).isFalse();
    // Change a global setting that is not in the whitelist
    setSettings(null, "sonar.foo", "bar");
    result = engine.checkIfGlobalStorageNeedUpdate(serverConfig, null);
    assertThat(result.needUpdate()).isFalse();
    // Change a global setting that *is* in the whitelist
    setSettingsMultiValue(null, "sonar.inclusions", "**/*");
    // Activate a new rule
    SearchWsResponse response = newAdminWsClient(ORCHESTRATOR).qualityProfiles().search(new SearchWsRequest().setLanguage("java"));
    String profileKey = response.getProfilesList().stream().filter(p -> p.getName().equals("SonarLint IT Java")).findFirst().get().getKey();
    ORCHESTRATOR.getServer().adminWsClient().post("api/qualityprofiles/activate_rule", "profile_key", profileKey, "rule_key", "squid:S1228");
    result = engine.checkIfGlobalStorageNeedUpdate(serverConfig, null);
    assertThat(result.needUpdate()).isTrue();
    assertThat(result.changelog()).containsOnly("Global settings updated", "Quality profile 'SonarLint IT Java' for language 'Java' updated");
    result = engine.checkIfModuleStorageNeedUpdate(serverConfig, PROJECT_KEY_JAVA, null);
    assertThat(result.needUpdate()).isFalse();
    // Change a project setting that is not in the whitelist
    setSettings(PROJECT_KEY_JAVA, "sonar.foo", "biz");
    result = engine.checkIfModuleStorageNeedUpdate(serverConfig, PROJECT_KEY_JAVA, null);
    assertThat(result.needUpdate()).isFalse();
    // Change a project setting that *is* in the whitelist
    setSettingsMultiValue(PROJECT_KEY_JAVA, "sonar.exclusions", "**/*.foo");
    result = engine.checkIfModuleStorageNeedUpdate(serverConfig, PROJECT_KEY_JAVA, null);
    assertThat(result.needUpdate()).isTrue();
    assertThat(result.changelog()).containsOnly("Project settings updated");
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) PermissionParameters(org.sonar.wsclient.permissions.PermissionParameters) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OrchestratorBuilder(com.sonar.orchestrator.OrchestratorBuilder) UnsupportedServerException(org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException) InetAddress(java.net.InetAddress) WsClient(org.sonarqube.ws.client.WsClient) MovedContextHandler(org.eclipse.jetty.server.handler.MovedContextHandler) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) Map(java.util.Map) After(org.junit.After) ClassRule(org.junit.ClassRule) Path(java.nio.file.Path) Server(org.eclipse.jetty.server.Server) ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine) StorageUpdateCheckResult(org.sonarsource.sonarlint.core.client.api.connected.StorageUpdateCheckResult) AfterClass(org.junit.AfterClass) RemoveGroupWsRequest(org.sonarqube.ws.client.permission.RemoveGroupWsRequest) NetworkUtils(com.sonar.orchestrator.util.NetworkUtils) FileLocation(com.sonar.orchestrator.locator.FileLocation) WsClientFactories(org.sonarqube.ws.client.WsClientFactories) SearchWsResponse(org.sonarqube.ws.QualityProfiles.SearchWsResponse) StandardCharsets(java.nio.charset.StandardCharsets) Configuration(com.sonar.orchestrator.config.Configuration) List(java.util.List) ExternalResource(org.junit.rules.ExternalResource) Assertions.fail(org.assertj.core.api.Assertions.fail) Assume.assumeTrue(org.junit.Assume.assumeTrue) SearchWsRequest(org.sonarqube.ws.client.qualityprofile.SearchWsRequest) Orchestrator(com.sonar.orchestrator.Orchestrator) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) QualityProfile(org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile) BeforeClass(org.junit.BeforeClass) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) HashMap(java.util.HashMap) PropertyDeleteQuery(org.sonar.wsclient.services.PropertyDeleteQuery) ConnectedGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration) ArrayList(java.util.ArrayList) HttpConnector(org.sonarqube.ws.client.HttpConnector) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) WsHelper(org.sonarsource.sonarlint.core.client.api.connected.WsHelper) ExpectedException(org.junit.rules.ExpectedException) State(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine.State) Nullable(javax.annotation.Nullable) Before(org.junit.Before) PropertyCreateQuery(org.sonar.wsclient.services.PropertyCreateQuery) MavenBuild(com.sonar.orchestrator.build.MavenBuild) Files(java.nio.file.Files) UserParameters(org.sonar.wsclient.user.UserParameters) PostRequest(org.sonarqube.ws.client.PostRequest) Assertions.tuple(org.assertj.core.api.Assertions.tuple) WsResponse(org.sonarqube.ws.client.WsResponse) SetRequest(org.sonarqube.ws.client.setting.SetRequest) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) WsHelperImpl(org.sonarsource.sonarlint.core.WsHelperImpl) File(java.io.File) ServerConnector(org.eclipse.jetty.server.ServerConnector) Rule(org.junit.Rule) Paths(java.nio.file.Paths) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults) WsRequest(org.sonarqube.ws.client.WsRequest) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) StorageUpdateCheckResult(org.sonarsource.sonarlint.core.client.api.connected.StorageUpdateCheckResult) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) SearchWsRequest(org.sonarqube.ws.client.qualityprofile.SearchWsRequest) SearchWsResponse(org.sonarqube.ws.QualityProfiles.SearchWsResponse) Test(org.junit.Test)

Example 3 with ServerConfiguration

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

the class ConnectedSonarLintEngineImpl method update.

@Override
public UpdateResult update(ServerConfiguration serverConfig, @Nullable ProgressMonitor monitor) {
    checkNotNull(serverConfig);
    setLogging(null);
    return withRwLock(() -> {
        stop(false);
        changeState(State.UPDATING);
        List<SonarAnalyzer> analyzers;
        try {
            analyzers = runInConnectedContainer(serverConfig, container -> container.update(new ProgressWrapper(monitor)));
        } finally {
            start();
        }
        return new UpdateResult(getHandler().getGlobalStorageStatus(), analyzers);
    });
}
Also used : LoggedErrorHandler(org.sonarsource.sonarlint.core.util.LoggedErrorHandler) LoggerFactory(org.slf4j.LoggerFactory) ModuleStorageStatus(org.sonarsource.sonarlint.core.client.api.connected.ModuleStorageStatus) GlobalUpdateRequiredException(org.sonarsource.sonarlint.core.client.api.exceptions.GlobalUpdateRequiredException) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ConnectedAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration) ServerIssue(org.sonarsource.sonarlint.core.client.api.connected.ServerIssue) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ConnectedGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration) RemoteModule(org.sonarsource.sonarlint.core.client.api.connected.RemoteModule) IssueListener(org.sonarsource.sonarlint.core.client.api.common.analysis.IssueListener) UpdateResult(org.sonarsource.sonarlint.core.client.api.connected.UpdateResult) Map(java.util.Map) StorageContainerHandler(org.sonarsource.sonarlint.core.container.storage.StorageContainerHandler) LoadedAnalyzer(org.sonarsource.sonarlint.core.client.api.connected.LoadedAnalyzer) SonarLintLogging(org.sonarsource.sonarlint.core.log.SonarLintLogging) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Nullable(javax.annotation.Nullable) ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine) StorageUpdateCheckResult(org.sonarsource.sonarlint.core.client.api.connected.StorageUpdateCheckResult) StorageContainer(org.sonarsource.sonarlint.core.container.storage.StorageContainer) ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) Logger(org.slf4j.Logger) StorageException(org.sonarsource.sonarlint.core.client.api.exceptions.StorageException) RuleDetails(org.sonarsource.sonarlint.core.client.api.common.RuleDetails) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) ProgressMonitor(org.sonarsource.sonarlint.core.client.api.common.ProgressMonitor) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) StateListener(org.sonarsource.sonarlint.core.client.api.connected.StateListener) List(java.util.List) ConnectedContainer(org.sonarsource.sonarlint.core.container.connected.ConnectedContainer) SonarLintWrappedException(org.sonarsource.sonarlint.core.client.api.exceptions.SonarLintWrappedException) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults) GlobalStorageStatus(org.sonarsource.sonarlint.core.client.api.connected.GlobalStorageStatus) LogOutput(org.sonarsource.sonarlint.core.client.api.common.LogOutput) SonarAnalyzer(org.sonarsource.sonarlint.core.client.api.connected.SonarAnalyzer) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) SonarAnalyzer(org.sonarsource.sonarlint.core.client.api.connected.SonarAnalyzer) UpdateResult(org.sonarsource.sonarlint.core.client.api.connected.UpdateResult)

Example 4 with ServerConfiguration

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

the class ConnectedSonarLintEngineImpl method checkIfModuleStorageNeedUpdate.

@Override
public StorageUpdateCheckResult checkIfModuleStorageNeedUpdate(ServerConfiguration serverConfig, String moduleKey, @Nullable ProgressMonitor monitor) {
    checkNotNull(serverConfig);
    checkNotNull(moduleKey);
    return withReadLock(() -> runInConnectedContainer(serverConfig, container -> container.checkForUpdate(moduleKey, new ProgressWrapper(monitor))));
}
Also used : LoggedErrorHandler(org.sonarsource.sonarlint.core.util.LoggedErrorHandler) LoggerFactory(org.slf4j.LoggerFactory) ModuleStorageStatus(org.sonarsource.sonarlint.core.client.api.connected.ModuleStorageStatus) GlobalUpdateRequiredException(org.sonarsource.sonarlint.core.client.api.exceptions.GlobalUpdateRequiredException) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ConnectedAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration) ServerIssue(org.sonarsource.sonarlint.core.client.api.connected.ServerIssue) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ConnectedGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration) RemoteModule(org.sonarsource.sonarlint.core.client.api.connected.RemoteModule) IssueListener(org.sonarsource.sonarlint.core.client.api.common.analysis.IssueListener) UpdateResult(org.sonarsource.sonarlint.core.client.api.connected.UpdateResult) Map(java.util.Map) StorageContainerHandler(org.sonarsource.sonarlint.core.container.storage.StorageContainerHandler) LoadedAnalyzer(org.sonarsource.sonarlint.core.client.api.connected.LoadedAnalyzer) SonarLintLogging(org.sonarsource.sonarlint.core.log.SonarLintLogging) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Nullable(javax.annotation.Nullable) ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine) StorageUpdateCheckResult(org.sonarsource.sonarlint.core.client.api.connected.StorageUpdateCheckResult) StorageContainer(org.sonarsource.sonarlint.core.container.storage.StorageContainer) ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) Logger(org.slf4j.Logger) StorageException(org.sonarsource.sonarlint.core.client.api.exceptions.StorageException) RuleDetails(org.sonarsource.sonarlint.core.client.api.common.RuleDetails) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) ProgressMonitor(org.sonarsource.sonarlint.core.client.api.common.ProgressMonitor) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) StateListener(org.sonarsource.sonarlint.core.client.api.connected.StateListener) List(java.util.List) ConnectedContainer(org.sonarsource.sonarlint.core.container.connected.ConnectedContainer) SonarLintWrappedException(org.sonarsource.sonarlint.core.client.api.exceptions.SonarLintWrappedException) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults) GlobalStorageStatus(org.sonarsource.sonarlint.core.client.api.connected.GlobalStorageStatus) LogOutput(org.sonarsource.sonarlint.core.client.api.common.LogOutput) SonarAnalyzer(org.sonarsource.sonarlint.core.client.api.connected.SonarAnalyzer) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper)

Example 5 with ServerConfiguration

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

the class ServerIssueTrackerTest method should_get_issues_from_engine_if_download_failed.

@Test
public void should_get_issues_from_engine_if_download_failed() {
    String moduleKey = "dummy module";
    String filePath = "dummy file";
    ConnectedSonarLintEngine engine = mock(ConnectedSonarLintEngine.class);
    ServerConfiguration serverConfiguration = mock(ServerConfiguration.class);
    ServerIssueTracker tracker = new ServerIssueTracker(mock(Logger.class), mock(Console.class), mock(CachingIssueTracker.class));
    when(engine.downloadServerIssues(serverConfiguration, moduleKey, filePath)).thenThrow(new DownloadException());
    tracker.update(serverConfiguration, engine, moduleKey, Collections.singleton(filePath));
    verify(engine).downloadServerIssues(serverConfiguration, moduleKey, filePath);
    verify(engine).getServerIssues(moduleKey, filePath);
    verifyNoMoreInteractions(engine);
}
Also used : ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) DownloadException(org.sonarsource.sonarlint.core.client.api.exceptions.DownloadException) ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine) Test(org.junit.Test)

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