Search in sources :

Example 1 with JgitDifference

use of com.github.checkstyle.parser.JgitUtils.JgitDifference in project contribution by checkstyle.

the class CheckstyleTextParser method parseDifferenceFile.

/**
 * Compares the contents of the files located at {@code fielPath} at {@code baseReport} and
 * {@code patchReport}.
 *
 * @param diffReport
 *            container for parsed data.
 * @param filePath
 *            path for files.
 * @param baseReport
 *            path for base files.
 * @param patchReport
 *            path for patch files.
 * @throws IOException
 *             if there is a problem accessing a file.
 */
private static void parseDifferenceFile(DiffReport diffReport, String filePath, Path baseReport, Path patchReport) throws IOException {
    final File baseFile = new File(baseReport.toFile(), filePath);
    final File patchFile = new File(patchReport.toFile(), filePath);
    final Statistics statistics = diffReport.getStatistics();
    final Iterator<JgitDifference> iterator = JgitUtils.getDifferences(baseFile, patchFile);
    final List<CheckstyleRecord> records = new ArrayList<>();
    while (iterator.hasNext()) {
        final JgitDifference diff = iterator.next();
        final String xref;
        if (diff.getIndex() == BASE_REPORT_INDEX) {
            xref = baseFile.getPath();
        } else {
            xref = patchFile.getPath();
        }
        final CheckstyleRecord record = new CheckstyleRecord(diff.getIndex(), diff.getLineNo() + 1, 1, DEFAULT_SEVERITY, DEFAULT_SOURCE, diff.getLine(), xref);
        statistics.addSeverityRecord(DEFAULT_SEVERITY, diff.getIndex());
        statistics.addModuleRecord(DEFAULT_SOURCE, diff.getIndex());
        records.add(record);
    }
    diffReport.addRecords(records, filePath);
    statistics.incrementFileCount(BASE_REPORT_INDEX);
    statistics.incrementFileCount(PATCH_REPORT_INDEX);
}
Also used : CheckstyleRecord(com.github.checkstyle.data.CheckstyleRecord) ArrayList(java.util.ArrayList) File(java.io.File) Statistics(com.github.checkstyle.data.Statistics) JgitDifference(com.github.checkstyle.parser.JgitUtils.JgitDifference)

Aggregations

CheckstyleRecord (com.github.checkstyle.data.CheckstyleRecord)1 Statistics (com.github.checkstyle.data.Statistics)1 JgitDifference (com.github.checkstyle.parser.JgitUtils.JgitDifference)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1