Search in sources :

Example 1 with ModuleStorageStatus

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

the class StorageAnalyzerTest method testStaleModuleStorage.

@Test
public void testStaleModuleStorage() {
    when(globalReader.get()).thenReturn(mock(GlobalStorageStatus.class));
    ModuleStorageStatus moduleStatus = mock(ModuleStorageStatus.class);
    when(moduleStatus.isStale()).thenReturn(true);
    when(moduleReader.apply("module1")).thenReturn(moduleStatus);
    exception.expect(StorageException.class);
    exception.expectMessage("Stored data for module 'module1' is stale");
    analyzer.analyze(mock(StorageContainer.class), config, mock(IssueListener.class), new ProgressWrapper(null));
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) IssueListener(org.sonarsource.sonarlint.core.client.api.common.analysis.IssueListener) GlobalStorageStatus(org.sonarsource.sonarlint.core.client.api.connected.GlobalStorageStatus) ModuleStorageStatus(org.sonarsource.sonarlint.core.client.api.connected.ModuleStorageStatus) Test(org.junit.Test)

Example 2 with ModuleStorageStatus

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

the class SonarLintEngineManager method checkConnectedEngineStatus.

private static void checkConnectedEngineStatus(ConnectedSonarLintEngine engine, SonarLintProjectNotifications notifications, String serverId, String projectKey) throws InvalidBindingException {
    // Check if engine's global storage is OK
    ConnectedSonarLintEngine.State state = engine.getState();
    if (state != ConnectedSonarLintEngine.State.UPDATED) {
        if (state != ConnectedSonarLintEngine.State.NEED_UPDATE) {
            notifications.notifyServerNotUpdated();
        } else if (state != ConnectedSonarLintEngine.State.NEVER_UPDATED) {
            notifications.notifyServerStorageNeedsUpdate(serverId);
        }
        throw new InvalidBindingException("Server is not updated: " + serverId);
    }
    // Check if module's storage is OK. Global storage was updated and all project's binding that were open too,
    // but we might have now opened a new project with a different binding.
    ModuleStorageStatus moduleStorageStatus = engine.getModuleStorageStatus(projectKey);
    if (moduleStorageStatus == null) {
        notifications.notifyModuleInvalid();
        throw new InvalidBindingException("Project is bound to a module that doesn't exist: " + projectKey);
    } else if (moduleStorageStatus.isStale()) {
        notifications.notifyModuleStale();
        throw new InvalidBindingException("Stale module's storage: " + projectKey);
    }
}
Also used : InvalidBindingException(org.sonarlint.intellij.exception.InvalidBindingException) ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine) ModuleStorageStatus(org.sonarsource.sonarlint.core.client.api.connected.ModuleStorageStatus)

Aggregations

ModuleStorageStatus (org.sonarsource.sonarlint.core.client.api.connected.ModuleStorageStatus)2 Test (org.junit.Test)1 InvalidBindingException (org.sonarlint.intellij.exception.InvalidBindingException)1 IssueListener (org.sonarsource.sonarlint.core.client.api.common.analysis.IssueListener)1 ConnectedSonarLintEngine (org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine)1 GlobalStorageStatus (org.sonarsource.sonarlint.core.client.api.connected.GlobalStorageStatus)1 ProgressWrapper (org.sonarsource.sonarlint.core.util.ProgressWrapper)1