use of org.sonar.core.util.CloseableIterator in project sonarqube by SonarSource.
the class SendIssueNotificationsStep method doExecute.
private void doExecute(NotificationStatistics notificationStatistics, Component project) {
long analysisDate = analysisMetadataHolder.getAnalysisDate();
Predicate<DefaultIssue> onCurrentAnalysis = i -> i.isNew() && i.creationDate().getTime() >= truncateToSeconds(analysisDate);
NewIssuesStatistics newIssuesStats = new NewIssuesStatistics(onCurrentAnalysis);
Map<String, UserDto> assigneesByUuid;
try (DbSession dbSession = dbClient.openSession(false)) {
Iterable<DefaultIssue> iterable = protoIssueCache::traverse;
Set<String> assigneeUuids = stream(iterable.spliterator(), false).map(DefaultIssue::assignee).filter(Objects::nonNull).collect(Collectors.toSet());
assigneesByUuid = dbClient.userDao().selectByUuids(dbSession, assigneeUuids).stream().collect(toMap(UserDto::getUuid, dto -> dto));
}
try (CloseableIterator<DefaultIssue> issues = protoIssueCache.traverse()) {
processIssues(newIssuesStats, issues, assigneesByUuid, notificationStatistics);
}
if (newIssuesStats.hasIssuesOnCurrentAnalysis()) {
sendNewIssuesNotification(newIssuesStats, project, assigneesByUuid, analysisDate, notificationStatistics);
sendMyNewIssuesNotification(newIssuesStats, project, assigneesByUuid, analysisDate, notificationStatistics);
}
}
use of org.sonar.core.util.CloseableIterator in project sonarqube by SonarSource.
the class FileSourceDataComputerTest method compute_builds_data_object_from_lines.
@Test
public void compute_builds_data_object_from_lines() {
int lineCount = 1 + new Random().nextInt(10);
int randomStartPoint = new Random().nextInt(500);
List<String> lines = IntStream.range(0, lineCount).mapToObj(i -> "line" + i).collect(toList());
List<String> expectedLineHashes = IntStream.range(0, 1 + new Random().nextInt(12)).mapToObj(i -> "str_" + i).collect(toList());
Changeset expectedChangeset = Changeset.newChangesetBuilder().setDate((long) new Random().nextInt(9_999)).build();
String expectedSrcHash = computeSrcHash(lines);
CloseableIterator<String> lineIterator = spy(CloseableIterator.from(lines.iterator()));
DbFileSources.Data.Builder expectedLineDataBuilder = DbFileSources.Data.newBuilder();
for (int i = 0; i < lines.size(); i++) {
expectedLineDataBuilder.addLinesBuilder().setSource(lines.get(i)).setLine(i + 1).setScmAuthor("reader_called_" + (randomStartPoint + i));
}
when(sourceLinesRepository.readLines(FILE)).thenReturn(lineIterator);
when(sourceLineReadersFactory.getLineReaders(FILE)).thenReturn(lineReaders);
when(sourceLinesHashRepository.getLineHashesComputerToPersist(FILE)).thenReturn(lineHashesComputer);
when(lineHashesComputer.getResult()).thenReturn(expectedLineHashes);
when(lineReaders.getLatestChangeWithRevision()).thenReturn(expectedChangeset);
// mocked implementation of LineReader.read to ensure changes done by it to the lineBuilder argument actually end
// up in the FileSourceDataComputer.Data object returned
doAnswer(new Answer() {
int i = 0;
@Override
public Object answer(InvocationOnMock invocation) {
DbFileSources.Line.Builder lineBuilder = invocation.getArgument(0);
lineBuilder.setScmAuthor("reader_called_" + (randomStartPoint + i++));
return null;
}
}).when(lineReaders).read(any(), any());
FileSourceDataComputer.Data data = underTest.compute(FILE, fileSourceDataWarnings);
assertThat(data.getLineHashes()).isEqualTo(expectedLineHashes);
assertThat(data.getSrcHash()).isEqualTo(expectedSrcHash);
assertThat(data.getLatestChangeWithRevision()).isSameAs(expectedChangeset);
assertThat(data.getLineData()).isEqualTo(expectedLineDataBuilder.build());
verify(lineIterator).close();
verify(lineReaders).close();
}
use of org.sonar.core.util.CloseableIterator in project sonarqube by SonarSource.
the class SourceLineReadersFactory method getLineReaders.
public LineReaders getLineReaders(Component component) {
List<LineReader> readers = new ArrayList<>();
List<CloseableIterator<?>> closeables = new ArrayList<>();
ScmLineReader scmLineReader = null;
int componentRef = component.getReportAttributes().getRef();
CloseableIterator<ScannerReport.LineCoverage> coverageIt = reportReader.readComponentCoverage(componentRef);
closeables.add(coverageIt);
readers.add(new CoverageLineReader(coverageIt));
Optional<ScmInfo> scmInfoOptional = scmInfoRepository.getScmInfo(component);
if (scmInfoOptional.isPresent()) {
scmLineReader = new ScmLineReader(scmInfoOptional.get());
readers.add(scmLineReader);
}
RangeOffsetConverter rangeOffsetConverter = new RangeOffsetConverter();
CloseableIterator<ScannerReport.SyntaxHighlightingRule> highlightingIt = reportReader.readComponentSyntaxHighlighting(componentRef);
closeables.add(highlightingIt);
readers.add(new HighlightingLineReader(component, highlightingIt, rangeOffsetConverter));
CloseableIterator<ScannerReport.Symbol> symbolsIt = reportReader.readComponentSymbols(componentRef);
closeables.add(symbolsIt);
readers.add(new SymbolsLineReader(component, symbolsIt, rangeOffsetConverter));
readers.add(new DuplicationLineReader(duplicationRepository.getDuplications(component)));
readers.add(new IsNewLineReader(newLinesRepository, component));
return new LineReadersImpl(readers, scmLineReader, closeables);
}
Aggregations