All Downloads are FREE. Search and download functionalities are using the official Maven repository.

se.bjurr.violations.lib.parsers.ZPTLintParser Maven / Gradle / Ivy

package se.bjurr.violations.lib.parsers;

import static se.bjurr.violations.lib.model.SEVERITY.ERROR;
import static se.bjurr.violations.lib.model.Violation.violationBuilder;
import static se.bjurr.violations.lib.reports.Parser.ZPTLINT;
import static se.bjurr.violations.lib.util.ViolationParserUtils.getLines;

import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import se.bjurr.violations.lib.ViolationsLogger;
import se.bjurr.violations.lib.model.Violation;

public class ZPTLintParser implements ViolationsParser {

  @Override
  public Set parseReportOutput(
      final String string, final ViolationsLogger violationsLogger) throws Exception {
    final Set violations = new TreeSet<>();
    for (final List parts :
        getLines(string, "[ ]+Error in: (.*)  (.*)  , at line (\\d+).*")) {
      if (parts.size() < 3) {
        continue;
      }
      final Integer lineInFile = Integer.parseInt(parts.get(3));
      final String message = parts.get(2);
      final String fileName = parts.get(1);
      final Violation violation =
          violationBuilder() //
              .setParser(ZPTLINT) //
              .setFile(fileName) //
              .setMessage(message) //
              .setRule("ZPT") //
              .setSeverity(ERROR) //
              .setStartLine(lineInFile) //
              .build();
      violations.add(violation);
    }
    return violations;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy