Ejemplo n.º 1
0
  /** {@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;
  }
Ejemplo n.º 2
0
  /**
   * Runs all parsers and logs the results to the console.
   *
   * @throws IOException Signals that an I/O exception has occurred.
   */
  @Test
  public void testAllParsersOnOneFile() throws IOException {
    for (ParserDescription parser : ParserRegistry.getAvailableParsers()) {
      List<AbstractWarningsParser> parsers = ParserRegistry.getParsers(parser.getGroup());
      if (!(parsers.get(0) instanceof ViolationsAdapter)) {
        ParserRegistry parserRegistry = createRegistry(parsers);

        long start = System.currentTimeMillis();
        parserRegistry.parse(new File(""));
        long end = System.currentTimeMillis();
        System.out.println(parser.getName() + ": " + (end - start) + "ms"); // NOCHECKSTYLE NOPMD
      }
    }
  }