Search in sources :

Example 1 with TaskProgressMonitor

use of org.sonarlint.intellij.util.TaskProgressMonitor in project sonarlint-intellij by SonarSource.

the class SonarLintTask method analyze.

private List<AnalysisResults> analyze(Project project, ProgressIndicator indicator, AccumulatorIssueListener listener) {
    SonarLintAnalyzer analyzer = SonarLintUtils.get(project, SonarLintAnalyzer.class);
    indicator.setIndeterminate(true);
    int numModules = job.filesPerModule().keySet().size();
    String suffix = "";
    if (numModules > 1) {
        suffix = String.format(" in %d modules", numModules);
    }
    int numFiles = job.allFiles().size();
    if (numFiles > 1) {
        indicator.setText("Running SonarLint Analysis for " + numFiles + " files" + suffix);
    } else {
        indicator.setText("Running SonarLint Analysis for '" + getFileName(job.allFiles().iterator().next()) + "'");
    }
    LOGGER.info(indicator.getText());
    ProgressMonitor progressMonitor = new TaskProgressMonitor(indicator);
    List<AnalysisResults> results = new LinkedList<>();
    for (Map.Entry<Module, Collection<VirtualFile>> e : job.filesPerModule().entrySet()) {
        results.add(analyzer.analyzeModule(e.getKey(), e.getValue(), listener, progressMonitor));
        checkCanceled(indicator, myProject);
    }
    indicator.startNonCancelableSection();
    return results;
}
Also used : ProgressMonitor(org.sonarsource.sonarlint.core.client.api.common.ProgressMonitor) TaskProgressMonitor(org.sonarlint.intellij.util.TaskProgressMonitor) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults) Collection(java.util.Collection) TaskProgressMonitor(org.sonarlint.intellij.util.TaskProgressMonitor) Module(com.intellij.openapi.module.Module) Map(java.util.Map) LinkedList(java.util.LinkedList)

Example 2 with TaskProgressMonitor

use of org.sonarlint.intellij.util.TaskProgressMonitor in project sonarlint-intellij by SonarSource.

the class InformationFetchTask method run.

@Override
public void run(@NotNull ProgressIndicator indicator) {
    indicator.setText("Connecting to " + server.getHostUrl() + "...");
    indicator.setIndeterminate(false);
    try {
        ServerConfiguration serverConfiguration = SonarLintUtils.getServerConfiguration(server);
        indicator.setText("Checking support of notifications");
        notificationsSupported = SonarQubeNotifications.get().isSupported(serverConfiguration);
        WsHelper wsHelper = new WsHelperImpl();
        organizations = wsHelper.listOrganizations(serverConfiguration, new TaskProgressMonitor(indicator));
    } catch (UnsupportedServerException e) {
        organizations = Collections.emptyList();
    } catch (Exception e) {
        LOGGER.info("Failed to fetch information", e);
        exception = e;
    }
}
Also used : WsHelperImpl(org.sonarsource.sonarlint.core.WsHelperImpl) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) WsHelper(org.sonarsource.sonarlint.core.client.api.connected.WsHelper) TaskProgressMonitor(org.sonarlint.intellij.util.TaskProgressMonitor) UnsupportedServerException(org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException) UnsupportedServerException(org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException)

Example 3 with TaskProgressMonitor

use of org.sonarlint.intellij.util.TaskProgressMonitor in project sonarlint-intellij by SonarSource.

the class ServerDownloadProjectTask method run.

@Override
public void run(@NotNull ProgressIndicator indicator) {
    try {
        TaskProgressMonitor monitor = new TaskProgressMonitor(indicator);
        ServerConfiguration serverConfiguration = SonarLintUtils.getServerConfiguration(server);
        this.result = engine.downloadAllModules(serverConfiguration, monitor);
    } catch (Exception e) {
        LOGGER.info("Failed to download list of projects", e);
        this.exception = e;
    }
}
Also used : ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) TaskProgressMonitor(org.sonarlint.intellij.util.TaskProgressMonitor)

Example 4 with TaskProgressMonitor

use of org.sonarlint.intellij.util.TaskProgressMonitor 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

TaskProgressMonitor (org.sonarlint.intellij.util.TaskProgressMonitor)4 ServerConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration)3 RunnableAdapter (com.intellij.history.utils.RunnableAdapter)1 Module (com.intellij.openapi.module.Module)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 WsHelperImpl (org.sonarsource.sonarlint.core.WsHelperImpl)1 ProgressMonitor (org.sonarsource.sonarlint.core.client.api.common.ProgressMonitor)1 AnalysisResults (org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults)1 SonarAnalyzer (org.sonarsource.sonarlint.core.client.api.connected.SonarAnalyzer)1 UpdateResult (org.sonarsource.sonarlint.core.client.api.connected.UpdateResult)1 WsHelper (org.sonarsource.sonarlint.core.client.api.connected.WsHelper)1 CanceledException (org.sonarsource.sonarlint.core.client.api.exceptions.CanceledException)1 UnsupportedServerException (org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException)1