Search in sources :

Example 1 with IssueManager

use of org.sonarlint.intellij.issue.IssueManager in project sonarlint-intellij by SonarSource.

the class SonarClearIssuesAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();
    ApplicationManager.getApplication().assertReadAccessAllowed();
    if (project != null) {
        IssueManager issueManager = SonarLintUtils.get(project, IssueManager.class);
        DaemonCodeAnalyzer codeAnalyzer = SonarLintUtils.get(project, DaemonCodeAnalyzer.class);
        AccessToken token = ReadAction.start();
        try {
            issueManager.clear();
            // run annotator to remove highlighting of issues
            FileEditorManager editorManager = FileEditorManager.getInstance(project);
            VirtualFile[] openFiles = editorManager.getOpenFiles();
            Collection<PsiFile> psiFiles = findFiles(project, openFiles);
            psiFiles.forEach(codeAnalyzer::restart);
        } finally {
            // closeable only introduced in 2016.2
            token.finish();
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) IssueManager(org.sonarlint.intellij.issue.IssueManager) AccessToken(com.intellij.openapi.application.AccessToken) DaemonCodeAnalyzer(com.intellij.codeInsight.daemon.DaemonCodeAnalyzer) PsiFile(com.intellij.psi.PsiFile)

Example 2 with IssueManager

use of org.sonarlint.intellij.issue.IssueManager in project sonarlint-intellij by SonarSource.

the class SonarLintToolWindowFactory method addIssuesTab.

private static void addIssuesTab(Project project, ToolWindow toolWindow) {
    ProjectBindingManager projectBindingManager = SonarLintUtils.get(project, ProjectBindingManager.class);
    IssueManager issueManager = SonarLintUtils.get(project, IssueManager.class);
    CurrentFileController scope = new CurrentFileController(project, issueManager);
    SonarLintIssuesPanel issuesPanel = new SonarLintIssuesPanel(project, projectBindingManager, scope);
    Content issuesContent = toolWindow.getContentManager().getFactory().createContent(issuesPanel, TAB_CURRENT_FILE, false);
    toolWindow.getContentManager().addDataProvider(issuesPanel);
    toolWindow.getContentManager().addContent(issuesContent);
}
Also used : IssueManager(org.sonarlint.intellij.issue.IssueManager) Content(com.intellij.ui.content.Content) ProjectBindingManager(org.sonarlint.intellij.core.ProjectBindingManager)

Example 3 with IssueManager

use of org.sonarlint.intellij.issue.IssueManager in project sonarlint-intellij by SonarSource.

the class SonarExternalAnnotator method collectInformation.

@Override
public AnnotationContext collectInformation(@NotNull PsiFile file) {
    Project project = file.getProject();
    IssueManager store = SonarLintUtils.get(project, IssueManager.class);
    return new AnnotationContext(store);
}
Also used : Project(com.intellij.openapi.project.Project) IssueManager(org.sonarlint.intellij.issue.IssueManager)

Example 4 with IssueManager

use of org.sonarlint.intellij.issue.IssueManager in project sonarlint-intellij by SonarSource.

the class SonarLintCheckinHandler method processResult.

private ReturnResult processResult(Collection<VirtualFile> affectedFiles) {
    AnalysisResultIssues analysisResultIssues = SonarLintUtils.get(project, AnalysisResultIssues.class);
    IssueManager issueManager = SonarLintUtils.get(project, IssueManager.class);
    Map<VirtualFile, Collection<LiveIssue>> map = affectedFiles.stream().collect(Collectors.toMap(Function.identity(), issueManager::getForFile));
    long numIssues = map.entrySet().stream().flatMap(e -> e.getValue().stream()).filter(i -> !i.isResolved()).count();
    analysisResultIssues.set(map, "SCM changed files");
    long numBlockerIssues = map.entrySet().stream().flatMap(e -> e.getValue().stream()).filter(i -> !i.isResolved()).filter(i -> "BLOCKER".equals(i.getSeverity())).count();
    if (numIssues == 0) {
        return ReturnResult.COMMIT;
    }
    long numFiles = map.keySet().size();
    String msg = createMessage(numFiles, numIssues, numBlockerIssues);
    if (ApplicationManager.getApplication().isHeadlessEnvironment()) {
        LOGGER.info(msg);
        return ReturnResult.CANCEL;
    }
    return showYesNoCancel(msg);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) UIUtil(com.intellij.util.ui.UIUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PairConsumer(com.intellij.util.PairConsumer) Function(java.util.function.Function) IssuesViewTabOpener(org.sonarlint.intellij.actions.IssuesViewTabOpener) CheckinHandler(com.intellij.openapi.vcs.checkin.CheckinHandler) Map(java.util.Map) SonarLintGlobalSettings(org.sonarlint.intellij.config.global.SonarLintGlobalSettings) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) Logger(com.intellij.openapi.diagnostic.Logger) BorderLayout(java.awt.BorderLayout) CommitExecutor(com.intellij.openapi.vcs.changes.CommitExecutor) JComponent(javax.swing.JComponent) IssueManager(org.sonarlint.intellij.issue.IssueManager) SonarLintUtils(org.sonarlint.intellij.util.SonarLintUtils) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) DumbService(com.intellij.openapi.project.DumbService) CheckinProjectPanel(com.intellij.openapi.vcs.CheckinProjectPanel) AnalysisCallback(org.sonarlint.intellij.analysis.AnalysisCallback) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) RefreshableOnComponent(com.intellij.openapi.vcs.ui.RefreshableOnComponent) NonFocusableCheckBox(com.intellij.ui.NonFocusableCheckBox) Nullable(org.jetbrains.annotations.Nullable) ServiceManager(com.intellij.openapi.components.ServiceManager) AnalysisResultIssues(org.sonarlint.intellij.issue.AnalysisResultIssues) JCheckBox(javax.swing.JCheckBox) ApplicationManager(com.intellij.openapi.application.ApplicationManager) LiveIssue(org.sonarlint.intellij.issue.LiveIssue) JPanel(javax.swing.JPanel) IssueManager(org.sonarlint.intellij.issue.IssueManager) Collection(java.util.Collection) AnalysisResultIssues(org.sonarlint.intellij.issue.AnalysisResultIssues)

Example 5 with IssueManager

use of org.sonarlint.intellij.issue.IssueManager in project sonarlint-intellij by SonarSource.

the class ServerUpdateTask method analyzeOpenFiles.

private static void analyzeOpenFiles(Project project) {
    if (!project.isDisposed()) {
        SonarLintConsole console = SonarLintConsole.get(project);
        console.info("Clearing all issues because binding was updated");
        IssueManager store = SonarLintUtils.get(project, IssueManager.class);
        store.clear();
        SonarLintSubmitter submitter = SonarLintUtils.get(project, SonarLintSubmitter.class);
        submitter.submitOpenFilesAuto(TriggerType.BINDING_UPDATE);
    }
}
Also used : SonarLintSubmitter(org.sonarlint.intellij.trigger.SonarLintSubmitter) IssueManager(org.sonarlint.intellij.issue.IssueManager) SonarLintConsole(org.sonarlint.intellij.ui.SonarLintConsole)

Aggregations

IssueManager (org.sonarlint.intellij.issue.IssueManager)7 Project (com.intellij.openapi.project.Project)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 SonarLintConsole (org.sonarlint.intellij.ui.SonarLintConsole)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 FileUtil (com.intellij.openapi.util.io.FileUtil)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 Collections (java.util.Collections)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Before (org.junit.Before)2 Rule (org.junit.Rule)2 Test (org.junit.Test)2 TemporaryFolder (org.junit.rules.TemporaryFolder)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)2 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)2 Mock (org.mockito.Mock)2