/** * 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; } }
/** * Applies the exclude filter to the found annotations. * * @param allAnnotations all annotations * @return the filtered annotations if there is a filter defined */ private Set<FileAnnotation> applyExcludeFilter(final Set<FileAnnotation> allAnnotations) { Set<FileAnnotation> includedAnnotations; if (includePatterns.isEmpty()) { includedAnnotations = allAnnotations; } else { includedAnnotations = Sets.newHashSet(); for (FileAnnotation annotation : allAnnotations) { for (Pattern include : includePatterns) { if (include.matcher(annotation.getFileName()).matches()) { includedAnnotations.add(annotation); } } } } if (excludePatterns.isEmpty()) { return includedAnnotations; } else { Set<FileAnnotation> excludedAnnotations = Sets.newHashSet(includedAnnotations); for (FileAnnotation annotation : includedAnnotations) { for (Pattern exclude : excludePatterns) { if (exclude.matcher(annotation.getFileName()).matches()) { excludedAnnotations.remove(annotation); } } } return excludedAnnotations; } }
/** {@inheritDoc} */ @Override public BuildResult perform(final AbstractBuild<?, ?> build, final PluginLogger logger) throws InterruptedException, IOException { File logFile = build.getLogFile(); Set<String> validParsers = Sets.newHashSet(getParserNames()); ParserResult project; if (StringUtils.isNotBlank(getPattern())) { logger.log("Parsing warnings in files: " + getPattern()); FilesParser parser = new FilesParser( logger, getPattern(), new FileWarningsParser( validParsers, getDefaultEncoding(), getIncludePattern(), getExcludePattern()), isMavenBuild(build), isAntBuild(build)); project = build.getWorkspace().act(parser); } else { project = new ParserResult(build.getWorkspace()); } if (!ignoreConsole || StringUtils.isBlank(getPattern())) { logger.log("Parsing warnings in console log..."); ParserRegistry registry = new ParserRegistry( ParserRegistry.getParsers(validParsers), getDefaultEncoding(), getIncludePattern(), getExcludePattern()); Collection<FileAnnotation> warnings = registry.parse(logFile); if (!build.getWorkspace().isRemote()) { String workspace = build.getWorkspace().getRemote(); ModuleDetector detector = new ModuleDetector(new File(workspace)); for (FileAnnotation annotation : warnings) { String module = detector.guessModuleName(annotation.getFileName()); annotation.setModuleName(module); } } project.addAnnotations(warnings); } project = build.getWorkspace().act(new AnnotationsClassifier(project, getDefaultEncoding())); for (FileAnnotation annotation : project.getAnnotations()) { annotation.setPathName(build.getWorkspace().getRemote()); } WarningsResult result = new WarningsResult(build, getDefaultEncoding(), project); build.getActions().add(new WarningsResultAction(build, this, result)); return result; }