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));
}
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);
}
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);
}
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;
}
}
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);
}
}
Aggregations