Search in sources :

Example 1 with UpdateResult

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

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

the class ConnectedModeRequirementsTest method checkMinimalPluginVersionDuringGlobalUpdate.

@Test
public void checkMinimalPluginVersionDuringGlobalUpdate() throws IOException {
    UpdateResult update = engine.update(config(), null);
    assertThat(update.status().getLastUpdateDate()).isNotNull();
    assertThat(engine.getLoadedAnalyzers().stream().map(LoadedAnalyzer::key)).doesNotContain("javascript");
}
Also used : LoadedAnalyzer(org.sonarsource.sonarlint.core.client.api.connected.LoadedAnalyzer) UpdateResult(org.sonarsource.sonarlint.core.client.api.connected.UpdateResult) Test(org.junit.Test)

Example 3 with UpdateResult

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

the class ServerUpdateTask method run.

public void run(@NotNull ProgressIndicator indicator) {
    indicator.setText("Fetching data...");
    try {
        TaskProgressMonitor monitor = new TaskProgressMonitor(indicator);
        ServerConfiguration serverConfiguration = SonarLintUtils.getServerConfiguration(server);
        if (!onlyModules) {
            UpdateResult updateResult = engine.update(serverConfiguration, monitor);
            Collection<SonarAnalyzer> tooOld = updateResult.analyzers().stream().filter(SonarAnalyzer::sonarlintCompatible).filter(ServerUpdateTask::tooOld).collect(Collectors.toList());
            if (!tooOld.isEmpty()) {
                ApplicationManager.getApplication().invokeAndWait(() -> Messages.showWarningDialog(buildMinimumVersionFailMessage(tooOld), "Analyzers Not Loaded"), ModalityState.any());
            }
            log.log("Server binding '" + server.getName() + "' updated", LogOutput.Level.INFO);
        }
        updateModules(serverConfiguration, monitor);
    } catch (CanceledException e) {
        LOGGER.info("Update of server '" + server.getName() + "' was cancelled");
        log.log("Update of server '" + server.getName() + "' was cancelled", LogOutput.Level.INFO);
    } catch (Exception e) {
        LOGGER.info("Error updating from server '" + server.getName() + "'", e);
        final String msg = (e.getMessage() != null) ? e.getMessage() : ("Failed to update binding for server configuration '" + server.getName() + "'");
        ApplicationManager.getApplication().invokeAndWait(new RunnableAdapter() {

            @Override
            public void doRun() {
                Messages.showErrorDialog((Project) null, msg, "Update Failed");
            }
        }, ModalityState.any());
    }
}
Also used : CanceledException(org.sonarsource.sonarlint.core.client.api.exceptions.CanceledException) RunnableAdapter(com.intellij.history.utils.RunnableAdapter) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) SonarAnalyzer(org.sonarsource.sonarlint.core.client.api.connected.SonarAnalyzer) TaskProgressMonitor(org.sonarlint.intellij.util.TaskProgressMonitor) UpdateResult(org.sonarsource.sonarlint.core.client.api.connected.UpdateResult) CanceledException(org.sonarsource.sonarlint.core.client.api.exceptions.CanceledException)

Aggregations

UpdateResult (org.sonarsource.sonarlint.core.client.api.connected.UpdateResult)3 LoadedAnalyzer (org.sonarsource.sonarlint.core.client.api.connected.LoadedAnalyzer)2 ServerConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration)2 SonarAnalyzer (org.sonarsource.sonarlint.core.client.api.connected.SonarAnalyzer)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 RunnableAdapter (com.intellij.history.utils.RunnableAdapter)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Supplier (java.util.function.Supplier)1 Nullable (javax.annotation.Nullable)1 Test (org.junit.Test)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1