Search in sources :

Example 71 with ClientInputFile

use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-intellij by SonarSource.

the class IssueProcessor method process.

public void process(final SonarLintJob job, ProgressIndicator indicator, final Collection<Issue> rawIssues, Collection<ClientInputFile> failedAnalysisFiles) {
    Map<VirtualFile, Collection<LiveIssue>> transformedIssues;
    long start = System.currentTimeMillis();
    AccessToken token = ReadAction.start();
    try {
        transformedIssues = transformIssues(rawIssues, job.allFiles(), failedAnalysisFiles);
        // this might be updated later after tracking with server issues
        manager.store(transformedIssues);
    } finally {
        // closeable only introduced in 2016.2
        token.finish();
    }
    String issueStr = rawIssues.size() == 1 ? "issue" : "issues";
    console.debug(String.format("Processed %d %s in %d ms", rawIssues.size(), issueStr, System.currentTimeMillis() - start));
    long issuesToShow = transformedIssues.entrySet().stream().mapToLong(e -> e.getValue().size()).sum();
    Collection<VirtualFile> filesWithIssues = transformedIssues.entrySet().stream().filter(e -> !e.getValue().isEmpty()).map(Map.Entry::getKey).collect(Collectors.toList());
    String end = issuesToShow == 1 ? " issue" : " issues";
    console.info("Found " + issuesToShow + end);
    if (!filesWithIssues.isEmpty() && shouldUpdateServerIssues(job.trigger())) {
        serverIssueUpdater.fetchAndMatchServerIssues(filesWithIssues, indicator, job.waitForServerIssues());
    }
    AnalysisCallback callback = job.callback();
    if (callback != null) {
        Set<VirtualFile> failedVirtualFiles = failedAnalysisFiles.stream().map(f -> (VirtualFile) f.getClientObject()).collect(Collectors.toSet());
        callback.onSuccess(failedVirtualFiles);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashMap(java.util.HashMap) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) IssueLocation(org.sonarsource.sonarlint.core.client.api.common.analysis.IssueLocation) ReadAction(com.intellij.openapi.application.ReadAction) ArrayList(java.util.ArrayList) AccessToken(com.intellij.openapi.application.AccessToken) Map(java.util.Map) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Logger(com.intellij.openapi.diagnostic.Logger) LinkedList(java.util.LinkedList) RangeMarker(com.intellij.openapi.editor.RangeMarker) AnalysisCallback(org.sonarlint.intellij.analysis.AnalysisCallback) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) AbstractProjectComponent(com.intellij.openapi.components.AbstractProjectComponent) SonarLintConsole(org.sonarlint.intellij.ui.SonarLintConsole) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) TriggerType(org.sonarlint.intellij.trigger.TriggerType) Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) SonarLintJob(org.sonarlint.intellij.analysis.SonarLintJob) Collections(java.util.Collections) ServerIssueUpdater(org.sonarlint.intellij.core.ServerIssueUpdater) AccessToken(com.intellij.openapi.application.AccessToken) Collection(java.util.Collection) AnalysisCallback(org.sonarlint.intellij.analysis.AnalysisCallback) HashMap(java.util.HashMap) Map(java.util.Map)

Example 72 with ClientInputFile

use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-intellij by SonarSource.

the class IssueTreeModelBuilderTest method mockIssuePointer.

private static LiveIssue mockIssuePointer(String path, int startOffset, String rule, String severity, @Nullable Long creationDate) {
    Issue issue = mock(Issue.class);
    PsiFile psiFile = mock(PsiFile.class);
    when(psiFile.isValid()).thenReturn(true);
    ClientInputFile f = mockFile(path);
    when(issue.getInputFile()).thenReturn(f);
    when(issue.getRuleKey()).thenReturn(rule);
    when(issue.getRuleName()).thenReturn(rule);
    when(issue.getSeverity()).thenReturn(severity);
    RangeMarker marker = mock(RangeMarker.class);
    when(marker.getStartOffset()).thenReturn(startOffset);
    LiveIssue ip = new LiveIssue(issue, psiFile);
    ip.setCreationDate(creationDate);
    return ip;
}
Also used : LiveIssue(org.sonarlint.intellij.issue.LiveIssue) Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) LiveIssue(org.sonarlint.intellij.issue.LiveIssue) PsiFile(com.intellij.psi.PsiFile) RangeMarker(com.intellij.openapi.editor.RangeMarker) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)

Aggregations

ClientInputFile (org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)72 Test (org.junit.Test)45 Issue (org.sonarsource.sonarlint.core.client.api.common.analysis.Issue)36 ArrayList (java.util.ArrayList)30 StandaloneAnalysisConfiguration (org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration)25 TestClientInputFile (org.sonarsource.sonarlint.core.TestClientInputFile)19 File (java.io.File)14 ConnectedAnalysisConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration)9 Path (java.nio.file.Path)8 HashMap (java.util.HashMap)7 AnalysisResults (org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults)7 LinkedList (java.util.LinkedList)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Collection (java.util.Collection)4 AccessToken (com.intellij.openapi.application.AccessToken)3 Logger (com.intellij.openapi.diagnostic.Logger)3 RangeMarker (com.intellij.openapi.editor.RangeMarker)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 Project (com.intellij.openapi.project.Project)3 PsiFile (com.intellij.psi.PsiFile)3