Search in sources :

Example 1 with StorageUpdateCheckResult

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

the class ModuleStorageUpdateCheckerTest method removedProp.

@Test
public void removedProp() {
    when(storageReader.readModuleConfig(MODULE_KEY)).thenReturn(ModuleConfiguration.newBuilder().putProperties("sonar.cobol.license.secured", "value").build());
    StorageUpdateCheckResult result = checker.checkForUpdates(MODULE_KEY, new ProgressWrapper(null));
    assertThat(result.needUpdate()).isTrue();
    assertThat(result.changelog()).containsOnly("Project settings updated");
    assertThat(logTester.logs(LoggerLevel.DEBUG)).containsOnly("Property 'sonar.cobol.license.secured' removed");
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) StorageUpdateCheckResult(org.sonarsource.sonarlint.core.client.api.connected.StorageUpdateCheckResult) Test(org.junit.Test)

Example 2 with StorageUpdateCheckResult

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

the class ModuleStorageUpdateCheckerTest method changedProp.

@Test
public void changedProp() {
    when(storageReader.readModuleConfig(MODULE_KEY)).thenReturn(ModuleConfiguration.newBuilder().putProperties("sonar.inclusions", "old").build());
    when(moduleConfigurationDownloader.fetchModuleConfiguration(eq(SERVER_VERSION), eq(MODULE_KEY), any(GlobalProperties.class), any(ProgressWrapper.class))).thenReturn(ModuleConfiguration.newBuilder().putProperties("sonar.inclusions", "new").build());
    StorageUpdateCheckResult result = checker.checkForUpdates(MODULE_KEY, new ProgressWrapper(null));
    assertThat(result.needUpdate()).isTrue();
    assertThat(result.changelog()).containsOnly("Project settings updated");
    assertThat(logTester.logs(LoggerLevel.DEBUG)).containsOnly("Value of property 'sonar.inclusions' changed from 'old' to 'new'");
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) StorageUpdateCheckResult(org.sonarsource.sonarlint.core.client.api.connected.StorageUpdateCheckResult) GlobalProperties(org.sonarsource.sonarlint.core.proto.Sonarlint.GlobalProperties) Test(org.junit.Test)

Example 3 with StorageUpdateCheckResult

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

the class ModuleStorageUpdateCheckerTest method addedProp.

@Test
public void addedProp() {
    when(moduleConfigurationDownloader.fetchModuleConfiguration(eq(SERVER_VERSION), eq(MODULE_KEY), any(GlobalProperties.class), any(ProgressWrapper.class))).thenReturn(ModuleConfiguration.newBuilder().putProperties("sonar.issue.enforce.allFiles", "value").build());
    StorageUpdateCheckResult result = checker.checkForUpdates(MODULE_KEY, new ProgressWrapper(null));
    assertThat(result.needUpdate()).isTrue();
    assertThat(result.changelog()).containsOnly("Project settings updated");
    assertThat(logTester.logs(LoggerLevel.DEBUG)).containsOnly("Property 'sonar.issue.enforce.allFiles' added with value 'value'");
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) StorageUpdateCheckResult(org.sonarsource.sonarlint.core.client.api.connected.StorageUpdateCheckResult) GlobalProperties(org.sonarsource.sonarlint.core.proto.Sonarlint.GlobalProperties) Test(org.junit.Test)

Example 4 with StorageUpdateCheckResult

use of org.sonarsource.sonarlint.core.client.api.connected.StorageUpdateCheckResult 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 5 with StorageUpdateCheckResult

use of org.sonarsource.sonarlint.core.client.api.connected.StorageUpdateCheckResult 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)

Aggregations

StorageUpdateCheckResult (org.sonarsource.sonarlint.core.client.api.connected.StorageUpdateCheckResult)12 Test (org.junit.Test)11 ProgressWrapper (org.sonarsource.sonarlint.core.util.ProgressWrapper)9 ServerConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration)4 GlobalProperties (org.sonarsource.sonarlint.core.proto.Sonarlint.GlobalProperties)4 List (java.util.List)2 Map (java.util.Map)2 Nullable (javax.annotation.Nullable)2 SonarTest (org.sonarlint.intellij.SonarTest)2 AnalysisResults (org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults)2 ConnectedGlobalConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration)2 ConnectedSonarLintEngine (org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Orchestrator (com.sonar.orchestrator.Orchestrator)1 OrchestratorBuilder (com.sonar.orchestrator.OrchestratorBuilder)1 MavenBuild (com.sonar.orchestrator.build.MavenBuild)1 Configuration (com.sonar.orchestrator.config.Configuration)1 FileLocation (com.sonar.orchestrator.locator.FileLocation)1 NetworkUtils (com.sonar.orchestrator.util.NetworkUtils)1 File (java.io.File)1