public Optional<LineRange[]> getRangesPerLine(Component component) {
int numLines = component.getFileAttributes().getLines();
- Optional<CloseableIterator<LineSgnificantCode>> significantCode = reportReader.readComponentSignificantCode(component.getReportAttributes().getRef());
- return significantCode.map(s -> toArray(s, numLines));
+ Optional<CloseableIterator<LineSgnificantCode>> opt = reportReader.readComponentSignificantCode(component.getReportAttributes().getRef());
+ if (!opt.isPresent()) {
+ return Optional.empty();
+ }
+ try (CloseableIterator<LineSgnificantCode> significantCode = opt.get()) {
+ return Optional.of(toArray(significantCode, numLines));
+ }
}
private static LineRange[] toArray(CloseableIterator<LineSgnificantCode> lineRanges, int numLines) {
private List<String> createLineHashes(Component component, Optional<LineRange[]> significantCodePerLine) {
LineHashesComputer processor = createLineHashesProcessor(component.getFileAttributes().getLines(), significantCodePerLine);
- CloseableIterator<String> lines = sourceLinesRepository.readLines(component);
-
- while (lines.hasNext()) {
- processor.addLine(lines.next());
+ try (CloseableIterator<String> lines = sourceLinesRepository.readLines(component)) {
+ while (lines.hasNext()) {
+ processor.addLine(lines.next());
+ }
+ return processor.getResult();
}
-
- return processor.getResult();
}
public interface LineHashesComputer {
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
import org.sonar.ce.task.projectanalysis.batch.BatchReportReader;
import org.sonar.ce.task.step.ComputationStep;
+import org.sonar.core.util.CloseableIterator;
import org.sonar.core.util.UuidFactory;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.AnalysisPropertyDto;
+import org.sonar.scanner.protocol.output.ScannerReport;
import static org.sonar.core.config.CorePropertyDefinitions.SONAR_ANALYSIS;
@Override
public void execute(ComputationStep.Context context) {
- final List<AnalysisPropertyDto> analysisPropertyDtos = new ArrayList<>();
- reportReader.readContextProperties().forEachRemaining(
- contextProperty -> {
- String propertyKey = contextProperty.getKey();
- if (propertyKey.startsWith(SONAR_ANALYSIS) || propertyKey.startsWith(SONAR_PULL_REQUEST)) {
- analysisPropertyDtos.add(new AnalysisPropertyDto()
- .setUuid(uuidFactory.create())
- .setKey(propertyKey)
- .setValue(contextProperty.getValue())
- .setSnapshotUuid(analysisMetadataHolder.getUuid()));
- }
- });
+ List<AnalysisPropertyDto> analysisPropertyDtos = new ArrayList<>();
+ try (CloseableIterator<ScannerReport.ContextProperty> it = reportReader.readContextProperties()) {
+ it.forEachRemaining(
+ contextProperty -> {
+ String propertyKey = contextProperty.getKey();
+ if (propertyKey.startsWith(SONAR_ANALYSIS) || propertyKey.startsWith(SONAR_PULL_REQUEST)) {
+ analysisPropertyDtos.add(new AnalysisPropertyDto()
+ .setUuid(uuidFactory.create())
+ .setKey(propertyKey)
+ .setValue(contextProperty.getValue())
+ .setSnapshotUuid(analysisMetadataHolder.getUuid()));
+ }
+ });
+ }
analysisMetadataHolder.getScmRevisionId().ifPresent(scmRevisionId -> analysisPropertyDtos.add(new AnalysisPropertyDto()
.setUuid(uuidFactory.create())
import org.sonar.ce.task.log.CeTaskMessages;
import org.sonar.ce.task.projectanalysis.batch.BatchReportReader;
import org.sonar.ce.task.step.ComputationStep;
+import org.sonar.core.util.CloseableIterator;
+import org.sonar.scanner.protocol.output.ScannerReport;
/**
* Propagate analysis warnings from scanner report.
@Override
public void execute(Context context) {
Collection<CeTaskMessages.Message> warnings = new ArrayList<>();
- reportReader.readAnalysisWarnings().forEachRemaining(w -> warnings.add(new CeTaskMessages.Message(w.getText(), w.getTimestamp())));
+ try (CloseableIterator<ScannerReport.AnalysisWarning> it = reportReader.readAnalysisWarnings()) {
+ it.forEachRemaining(w -> warnings.add(new CeTaskMessages.Message(w.getText(), w.getTimestamp())));
+ }
if (!warnings.isEmpty()) {
ceTaskMessages.addAll(warnings);
}