Search in sources :

Example 1 with Builder

use of org.sonar.scanner.protocol.output.ScannerReport.Changesets.Builder in project sonarqube by SonarSource.

the class DefaultBlameOutput method blameResult.

@Override
public synchronized void blameResult(InputFile file, List<BlameLine> lines) {
    Preconditions.checkNotNull(file);
    Preconditions.checkNotNull(lines);
    Preconditions.checkArgument(allFilesToBlame.contains(file), "It was not expected to blame file %s", file.relativePath());
    if (lines.size() != file.lines()) {
        LOG.debug("Ignoring blame result since provider returned {} blame lines but file {} has {} lines", lines.size(), file.relativePath(), file.lines());
        return;
    }
    Builder scmBuilder = ScannerReport.Changesets.newBuilder();
    DefaultInputFile inputFile = (DefaultInputFile) file;
    scmBuilder.setComponentRef(inputFile.batchId());
    Map<String, Integer> changesetsIdByRevision = new HashMap<>();
    int lineId = 1;
    for (BlameLine line : lines) {
        validateLine(line, lineId, file);
        Integer changesetId = changesetsIdByRevision.get(line.revision());
        if (changesetId == null) {
            addChangeset(scmBuilder, line);
            changesetId = scmBuilder.getChangesetCount() - 1;
            changesetsIdByRevision.put(line.revision(), changesetId);
        }
        scmBuilder.addChangesetIndexByLine(changesetId);
        lineId++;
    }
    writer.writeComponentChangesets(scmBuilder.build());
    allFilesToBlame.remove(file);
    count++;
    progressReport.message(count + "/" + total + " files analyzed");
}
Also used : BlameLine(org.sonar.api.batch.scm.BlameLine) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) HashMap(java.util.HashMap) Builder(org.sonar.scanner.protocol.output.ScannerReport.Changesets.Builder)

Example 2 with Builder

use of org.sonar.scanner.protocol.output.ScannerReport.Changesets.Builder in project sonarqube by SonarSource.

the class ScmPublisher method askToCopyDataFromPreviousAnalysis.

private static void askToCopyDataFromPreviousAnalysis(DefaultInputFile f, ScannerReportWriter writer) {
    Builder scmBuilder = ScannerReport.Changesets.newBuilder();
    scmBuilder.setComponentRef(f.batchId());
    scmBuilder.setCopyFromPrevious(true);
    writer.writeComponentChangesets(scmBuilder.build());
}
Also used : Builder(org.sonar.scanner.protocol.output.ScannerReport.Changesets.Builder)

Aggregations

Builder (org.sonar.scanner.protocol.output.ScannerReport.Changesets.Builder)2 HashMap (java.util.HashMap)1 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)1 BlameLine (org.sonar.api.batch.scm.BlameLine)1