/** {@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; }
/** * Iterates over the available parsers and parses the specified file with each parser. Returns all * found warnings. * * @param file the input stream * @param logger the logger to write to * @return all found warnings * @throws IOException Signals that an I/O exception has occurred. */ public Collection<FileAnnotation> parse(final File file, final PluginLogger logger) throws IOException { Set<FileAnnotation> allAnnotations = Sets.newHashSet(); for (WarningsParser parser : parsers) { Reader input = null; try { input = createReader(file); Collection<FileAnnotation> warnings = parser.parse(input); logger.log(String.format("%s : Found %d warnings.", parser.getName(), warnings.size())); allAnnotations.addAll(warnings); } finally { IOUtils.closeQuietly(input); } } return applyExcludeFilter(allAnnotations); }