use of org.sonarlint.intellij.analysis.VirtualFileTestPredicate in project sonarlint-intellij by SonarSource.
the class SonarLintSubmitter method filterAndgetByModule.
private Map<Module, Collection<VirtualFile>> filterAndgetByModule(Collection<VirtualFile> files, boolean checkExclusions) throws InvalidBindingException {
HashMultimap<Module, VirtualFile> filesByModule = HashMultimap.create();
SonarLintFacade sonarLintFacade = projectBindingManager.getFacade();
for (VirtualFile file : files) {
Module m = utils.findModuleForFile(file, myProject);
if (checkExclusions) {
LocalFileExclusions.Result result = localFileExclusions.checkExclusions(file, m);
if (result.isExcluded()) {
if (result.excludeReason() != null) {
logExclusion(file, "excluded: " + result.excludeReason());
}
continue;
}
} else {
if (!localFileExclusions.canAnalyze(file, m)) {
logExclusion(file, "can't be analyzed. Skipping it.");
continue;
}
}
filesByModule.put(m, file);
}
// Apply server file exclusions. This is an expensive operation, so we call the core only once per module.
if (checkExclusions) {
// Note: iterating over a copy of keys, because removal of last value removes the key,
// resulting in ConcurrentModificationException
List<Module> modules = new ArrayList<>(filesByModule.keySet());
for (Module module : modules) {
VirtualFileTestPredicate testPredicate = SonarLintUtils.get(module, VirtualFileTestPredicate.class);
Collection<VirtualFile> excluded = sonarLintFacade.getExcluded(filesByModule.get(module), testPredicate);
for (VirtualFile f : excluded) {
logExclusion(f, "not automatically analyzed due to exclusions configured in the SonarQube Server");
}
filesByModule.get(module).removeAll(excluded);
}
}
return filesByModule.asMap();
}
Aggregations