@Override public boolean test(String string) { return test(Paths.get(string)); } }
public FileExclusions(Set<String> fileExclusions, Set<String> directoryExclusions, Set<String> globPatterns) { this.fileExclusions = fileExclusions; this.directoryExclusions = directoryExclusions; this.matchers = parseGlobPatterns(globPatterns); }
public boolean test(Path path) { return testFileExclusions(path) || testDirectoryExclusions(path) || testGlob(path); }
private void loadGlobalExclusions(SonarLintGlobalSettings settings) { this.globalExclusions = new FileExclusions(new LinkedHashSet<>(settings.getFileExclusions())); }
private void loadProjectExclusions(SonarLintProjectSettings settings) { List<ExclusionItem> projectExclusionsItems = settings.getFileExclusions().stream() .map(ExclusionItem::parse) .filter(Objects::nonNull) .collect(Collectors.toList()); Set<String> projectFileExclusions = getExclusionsOfType(projectExclusionsItems, ExclusionItem.Type.FILE); Set<String> projectDirExclusions = getExclusionsOfType(projectExclusionsItems, ExclusionItem.Type.DIRECTORY); Set<String> projectGlobExclusions = getExclusionsOfType(projectExclusionsItems, ExclusionItem.Type.GLOB); this.projectExclusions = new FileExclusions(projectFileExclusions, projectDirExclusions, projectGlobExclusions); }
@Override public boolean test(String string) { return test(Paths.get(string)); } }
public boolean test(Path path) { return testFileExclusions(path) || testDirectoryExclusions(path) || testGlob(path); }
public FileExclusionsChecker(ISonarLintProject project) { SonarLintProjectConfiguration projectConfiguration = SonarLintCorePlugin.loadConfig(project); List<ExclusionItem> globalExclusionItems = PreferencesUtils.getGlobalExclusions(); List<ExclusionItem> projectExclusionItems = projectConfiguration.getFileExclusions(); Set<String> projectFileExclusions = getExclusionsOfType(projectExclusionItems, Type.FILE); Set<String> projectDirectoryExclusions = getExclusionsOfType(projectExclusionItems, Type.DIRECTORY); Set<String> projectGlobExclusions = getExclusionsOfType(projectExclusionItems, Type.GLOB); Set<String> globalGlobExclusions = getExclusionsOfType(globalExclusionItems, Type.GLOB); projectExclusions = new FileExclusions(projectFileExclusions, projectDirectoryExclusions, projectGlobExclusions); globalExclusions = new FileExclusions(globalGlobExclusions); }
public FileExclusions(Set<String> fileExclusions, Set<String> directoryExclusions, Set<String> globPatterns) { this.fileExclusions = fileExclusions; this.directoryExclusions = directoryExclusions; this.matchers = parseGlobPatterns(globPatterns); }
private boolean isExcludedByLocalConfiguration(ISonarLintFile file, boolean log) { String relativePath = file.getProjectRelativePath(); if (globalExclusions.test(relativePath)) { logIfNeeded(file, log, "global"); return true; } if (projectExclusions.test(relativePath)) { logIfNeeded(file, log, "project"); return true; } return false; }
/** * Checks if a file is excluded from analysis based on locally configured exclusions. * It will also exclude files that cannot be analysed with {@link #canAnalyze(VirtualFile, Module)}. */ public Result checkExclusions(VirtualFile file, @Nullable Module module) { Result result = canAnalyze(file, module); if (result.isExcluded()) { return result; } if (powerSaveModeCheck.getAsBoolean()) { return Result.excluded("power save mode is enabled"); } result = checkFileInSourceFolders(file, module); if (result.isExcluded) { return result; } String relativePath = appUtils.getRelativePathForAnalysis(module, file); if (relativePath == null) { return Result.excluded("Could not create a relative path"); } if (globalExclusions.test(relativePath)) { return Result.excluded("file matches exclusions defined in the SonarLint Global Settings"); } if (projectExclusions.test(relativePath)) { return Result.excluded("file matches exclusions defined in the SonarLint Project Settings"); } return Result.notExcluded(); }