Search in sources :

Example 1 with AnalysisCallback

use of org.sonarlint.intellij.analysis.AnalysisCallback in project sonarlint-intellij by SonarSource.

the class SonarAnalyzeFilesAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();
    VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
    if (project == null || project.isDisposed() || files == null || files.length == 0) {
        return;
    }
    boolean hasProject = Arrays.stream(files).anyMatch(f -> f.getPath().equals(project.getBasePath()));
    if (hasProject && !SonarAnalyzeAllFilesAction.showWarning()) {
        return;
    }
    List<VirtualFile> fileList = Arrays.stream(files).flatMap(f -> {
        if (f.isDirectory()) {
            return VfsUtil.collectChildrenRecursively(f).stream();
        } else {
            return Stream.of(f);
        }
    }).distinct().collect(Collectors.toList());
    SonarLintSubmitter submitter = SonarLintUtils.get(project, SonarLintSubmitter.class);
    AnalysisCallback callback;
    if (SonarLintToolWindowFactory.TOOL_WINDOW_ID.equals(e.getPlace())) {
        callback = new ShowCurrentFileCallable(project);
    } else {
        callback = new ShowAnalysisResultsCallable(project, fileList, whatAnalyzed(fileList.size()));
    }
    submitter.submitFiles(fileList, TriggerType.ACTION, callback, executeBackground(e));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) SonarLintSubmitter(org.sonarlint.intellij.trigger.SonarLintSubmitter) AnalysisCallback(org.sonarlint.intellij.analysis.AnalysisCallback)

Example 2 with AnalysisCallback

use of org.sonarlint.intellij.analysis.AnalysisCallback in project sonarlint-intellij by SonarSource.

the class SonarAnalyzeAllFilesAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();
    if (project == null || ActionPlaces.PROJECT_VIEW_POPUP.equals(e.getPlace()) || !showWarning()) {
        return;
    }
    SonarLintSubmitter submitter = SonarLintUtils.get(project, SonarLintSubmitter.class);
    Collection<VirtualFile> allFiles = getAllFiles(project);
    AnalysisCallback callback = new ShowAnalysisResultsCallable(project, allFiles, "all project files");
    submitter.submitFiles(allFiles, TriggerType.ALL, callback, false);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) SonarLintSubmitter(org.sonarlint.intellij.trigger.SonarLintSubmitter) AnalysisCallback(org.sonarlint.intellij.analysis.AnalysisCallback)

Example 3 with AnalysisCallback

use of org.sonarlint.intellij.analysis.AnalysisCallback in project sonarlint-intellij by SonarSource.

the class SonarAnalyzeChangedFilesAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();
    if (project == null || ActionPlaces.PROJECT_VIEW_POPUP.equals(e.getPlace())) {
        return;
    }
    SonarLintSubmitter submitter = SonarLintUtils.get(project, SonarLintSubmitter.class);
    ChangeListManager changeListManager = ChangeListManager.getInstance(project);
    List<VirtualFile> affectedFiles = changeListManager.getAffectedFiles();
    AnalysisCallback callback = new ShowAnalysisResultsCallable(project, affectedFiles, "SCM changed files");
    submitter.submitFiles(affectedFiles, TriggerType.CHANGED_FILES, callback, false);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) SonarLintSubmitter(org.sonarlint.intellij.trigger.SonarLintSubmitter) AnalysisCallback(org.sonarlint.intellij.analysis.AnalysisCallback) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager)

Example 4 with AnalysisCallback

use of org.sonarlint.intellij.analysis.AnalysisCallback in project sonarlint-intellij by SonarSource.

the class SonarLintCheckinHandler method beforeCheckin.

@Override
public ReturnResult beforeCheckin(@Nullable CommitExecutor executor, PairConsumer<Object, Object> additionalDataConsumer) {
    if (checkBox != null && !checkBox.isSelected()) {
        return ReturnResult.COMMIT;
    }
    Collection<VirtualFile> affectedFiles = checkinPanel.getVirtualFiles();
    SonarLintSubmitter submitter = SonarLintUtils.get(project, SonarLintSubmitter.class);
    // this will block EDT (modal)
    try {
        AtomicBoolean error = new AtomicBoolean(false);
        AnalysisCallback callback = new AnalysisCallback() {

            @Override
            public void onSuccess(Set<VirtualFile> failedVirtualFiles) {
            // do nothing
            }

            @Override
            public void onError(Throwable e) {
                error.set(true);
            }
        };
        submitter.submitFilesModal(affectedFiles, TriggerType.CHECK_IN, callback);
        if (error.get()) {
            return ReturnResult.CANCEL;
        }
        return processResult(affectedFiles);
    } catch (Exception e) {
        handleError(e, affectedFiles.size());
        return ReturnResult.CANCEL;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Set(java.util.Set) AnalysisCallback(org.sonarlint.intellij.analysis.AnalysisCallback)

Example 5 with AnalysisCallback

use of org.sonarlint.intellij.analysis.AnalysisCallback 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)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 AnalysisCallback (org.sonarlint.intellij.analysis.AnalysisCallback)5 Project (com.intellij.openapi.project.Project)4 SonarLintSubmitter (org.sonarlint.intellij.trigger.SonarLintSubmitter)3 Set (java.util.Set)2 AccessToken (com.intellij.openapi.application.AccessToken)1 ReadAction (com.intellij.openapi.application.ReadAction)1 AbstractProjectComponent (com.intellij.openapi.components.AbstractProjectComponent)1 Logger (com.intellij.openapi.diagnostic.Logger)1 RangeMarker (com.intellij.openapi.editor.RangeMarker)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 ChangeListManager (com.intellij.openapi.vcs.changes.ChangeListManager)1 PsiFile (com.intellij.psi.PsiFile)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1