use of org.sonar.api.batch.sensor.code.NewSignificantCode in project sonarqube by SonarSource.
the class DefaultSensorStorage method store.
@Override
public void store(NewSignificantCode newSignificantCode) {
DefaultSignificantCode significantCode = (DefaultSignificantCode) newSignificantCode;
ScannerReportWriter writer = reportPublisher.getWriter();
DefaultInputFile inputFile = (DefaultInputFile) significantCode.inputFile();
if (shouldSkipStorage(inputFile)) {
return;
}
inputFile.setPublished(true);
int componentRef = inputFile.scannerId();
if (writer.hasComponentData(FileStructure.Domain.SGNIFICANT_CODE, componentRef)) {
throw new UnsupportedOperationException("Trying to save significant code information twice for the same file is not supported: " + significantCode.inputFile());
}
List<ScannerReport.LineSgnificantCode> protobuf = significantCode.significantCodePerLine().values().stream().map(range -> ScannerReport.LineSgnificantCode.newBuilder().setLine(range.start().line()).setStartOffset(range.start().lineOffset()).setEndOffset(range.end().lineOffset()).build()).collect(Collectors.toList());
writer.writeComponentSignificantCode(componentRef, protobuf);
}
use of org.sonar.api.batch.sensor.code.NewSignificantCode in project sonarqube by SonarSource.
the class SignificantCodeSensor method processSignificantCodeFile.
private void processSignificantCodeFile(InputFile inputFile, SensorContext context) {
Path ioFile = inputFile.path();
Path significantCodeFile = ioFile.resolveSibling(ioFile.getFileName() + FILE_EXTENSION).toAbsolutePath();
if (Files.exists(significantCodeFile) && Files.isRegularFile(significantCodeFile)) {
LOG.debug("Processing " + significantCodeFile.toString());
try {
List<String> lines = Files.readAllLines(significantCodeFile, context.fileSystem().encoding());
NewSignificantCode significantCode = context.newSignificantCode().onFile(inputFile);
for (String line : lines) {
if (StringUtils.isBlank(line) || line.startsWith("#")) {
continue;
}
processLine(line, inputFile, significantCode);
}
significantCode.save();
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
}
Aggregations