Search in sources :

Example 1 with VirtualFileTestPredicate

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalFileExclusions(org.sonarlint.intellij.analysis.LocalFileExclusions) ArrayList(java.util.ArrayList) VirtualFileTestPredicate(org.sonarlint.intellij.analysis.VirtualFileTestPredicate) Module(com.intellij.openapi.module.Module) SonarLintFacade(org.sonarlint.intellij.core.SonarLintFacade)

Aggregations

Module (com.intellij.openapi.module.Module)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ArrayList (java.util.ArrayList)1 LocalFileExclusions (org.sonarlint.intellij.analysis.LocalFileExclusions)1 VirtualFileTestPredicate (org.sonarlint.intellij.analysis.VirtualFileTestPredicate)1 SonarLintFacade (org.sonarlint.intellij.core.SonarLintFacade)1