Search in sources :

Example 1 with CanceledException

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

Example 2 with CanceledException

use of org.sonarsource.sonarlint.core.client.api.exceptions.CanceledException in project sonarlint-intellij by SonarSource.

the class SonarLintTask method run.

@Override
public void run(ProgressIndicator indicator) {
    AccumulatorIssueListener listener = new AccumulatorIssueListener();
    try {
        checkCanceled(indicator, myProject);
        List<AnalysisResults> results = analyze(myProject, indicator, listener);
        // last chance to cancel (to avoid the possibility of having interrupt flag set)
        checkCanceled(indicator, myProject);
        LOGGER.info("SonarLint analysis done");
        indicator.setIndeterminate(false);
        indicator.setFraction(.9);
        List<Issue> issues = listener.getIssues();
        indicator.setText("Creating SonarLint issues: " + issues.size());
        List<ClientInputFile> allFailedAnalysisFiles = results.stream().flatMap(r -> r.failedAnalysisFiles().stream()).collect(Collectors.toList());
        processor.process(job, indicator, issues, allFailedAnalysisFiles);
    } catch (CanceledException e1) {
        console.info("Analysis canceled");
        return;
    } catch (Throwable e) {
        handleError(e, indicator);
    } finally {
        myProject.getMessageBus().syncPublisher(TaskListener.SONARLINT_TASK_TOPIC).ended(job);
    }
}
Also used : AccumulatorIssueListener(org.sonarlint.intellij.editor.AccumulatorIssueListener) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModalityState(com.intellij.openapi.application.ModalityState) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) Task(com.intellij.openapi.progress.Task) Map(java.util.Map) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) LinkedList(java.util.LinkedList) IssueProcessor(org.sonarlint.intellij.issue.IssueProcessor) SonarLintUtils(org.sonarlint.intellij.util.SonarLintUtils) TaskListener(org.sonarlint.intellij.messages.TaskListener) Collection(java.util.Collection) ProgressMonitor(org.sonarsource.sonarlint.core.client.api.common.ProgressMonitor) Collectors(java.util.stream.Collectors) SonarLintConsole(org.sonarlint.intellij.ui.SonarLintConsole) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults) CanceledException(org.sonarsource.sonarlint.core.client.api.exceptions.CanceledException) Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) ApplicationManager(com.intellij.openapi.application.ApplicationManager) TaskProgressMonitor(org.sonarlint.intellij.util.TaskProgressMonitor) CanceledException(org.sonarsource.sonarlint.core.client.api.exceptions.CanceledException) Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults) AccumulatorIssueListener(org.sonarlint.intellij.editor.AccumulatorIssueListener) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)

Aggregations

TaskProgressMonitor (org.sonarlint.intellij.util.TaskProgressMonitor)2 CanceledException (org.sonarsource.sonarlint.core.client.api.exceptions.CanceledException)2 RunnableAdapter (com.intellij.history.utils.RunnableAdapter)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ModalityState (com.intellij.openapi.application.ModalityState)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Module (com.intellij.openapi.module.Module)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 Project (com.intellij.openapi.project.Project)1 Messages (com.intellij.openapi.ui.Messages)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 AccumulatorIssueListener (org.sonarlint.intellij.editor.AccumulatorIssueListener)1 IssueProcessor (org.sonarlint.intellij.issue.IssueProcessor)1 TaskListener (org.sonarlint.intellij.messages.TaskListener)1