Search in sources :

Example 1 with Statistics

use of com.github.checkstyle.data.Statistics 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)

Example 2 with Statistics

use of com.github.checkstyle.data.Statistics in project contribution by checkstyle.

the class CheckstyleTextParser method parseDifferenceSingle.

/**
 * Adds the next file in the {@code reader} as a difference as there is no matching file in the
 * other side.
 *
 * @param diffReport
 *            container for parsed data.
 * @param reader
 *            reader for file list.
 * @param path
 *            path for files.
 * @param index
 *            internal index of the parsed file.
 */
private static void parseDifferenceSingle(DiffReport diffReport, StringListIterator reader, Path path, int index) {
    final int otherIndex;
    if (index == BASE_REPORT_INDEX) {
        otherIndex = PATCH_REPORT_INDEX;
    } else {
        otherIndex = BASE_REPORT_INDEX;
    }
    final String filePath = reader.next();
    final String xref = new File(path.toFile(), filePath).getPath();
    final Statistics statistics = diffReport.getStatistics();
    final List<CheckstyleRecord> records = new ArrayList<>();
    final CheckstyleRecord record = new CheckstyleRecord(otherIndex, 1, 1, DEFAULT_SEVERITY, DEFAULT_SOURCE, "File not found.", xref);
    statistics.addSeverityRecord(DEFAULT_SEVERITY, otherIndex);
    statistics.addModuleRecord(DEFAULT_SOURCE, otherIndex);
    records.add(record);
    diffReport.addRecords(records, filePath);
    statistics.incrementFileCount(index);
}
Also used : CheckstyleRecord(com.github.checkstyle.data.CheckstyleRecord) ArrayList(java.util.ArrayList) File(java.io.File) Statistics(com.github.checkstyle.data.Statistics)

Aggregations

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