/** * Applies the exclude and include filters to the found annotations. * * @param allAnnotations all annotations * @return the filtered annotations if there is a filter defined */ private List<FileAnnotation> applyFilters(final List<FileAnnotation> allAnnotations) { List<FileAnnotation> includedAnnotations; if (includePatterns.isEmpty()) { includedAnnotations = allAnnotations; } else { includedAnnotations = new ArrayList<FileAnnotation>(); for (FileAnnotation annotation : allAnnotations) { for (Pattern include : includePatterns) { if (include.matcher(annotation.getFileName()).matches()) { includedAnnotations.add(annotation); } } } } if (excludePatterns.isEmpty()) { return includedAnnotations; } else { List<FileAnnotation> excludedAnnotations = new ArrayList<FileAnnotation>(includedAnnotations); for (FileAnnotation annotation : includedAnnotations) { for (Pattern exclude : excludePatterns) { if (exclude.matcher(annotation.getFileName()).matches()) { excludedAnnotations.remove(annotation); } } } return excludedAnnotations; } }
/** * Add RegEx patterns to include/exclude in the report. * * @param patterns RegEx patterns * @param pattern String of RegEx patterns */ private void addPatterns(final Set<Pattern> patterns, final String pattern) { if (StringUtils.isNotBlank(pattern)) { String[] split = StringUtils.split(pattern, ','); for (String singlePattern : split) { String trimmed = StringUtils.trim(singlePattern); String directoriesReplaced = StringUtils.replace(trimmed, "**", "*"); // NOCHECKSTYLE patterns.add( Pattern.compile(StringUtils.replace(directoriesReplaced, "*", ".*"))); // NOCHECKSTYLE } } }