use of org.sonar.core.hash.SourceLinesHashesComputer in project sonarqube by SonarSource.
the class FileMoveDetectionStep method getReportFileSourcesByKey.
private Map<String, File> getReportFileSourcesByKey(Map<String, Component> reportFilesByKey, Set<String> addedFileKeys) {
ImmutableMap.Builder<String, File> builder = ImmutableMap.builder();
for (String fileKey : addedFileKeys) {
// FIXME computation of sourceHash and lineHashes might be done multiple times for some files: here, in ComputeFileSourceData, in
// SourceHashRepository
Component component = reportFilesByKey.get(fileKey);
SourceLinesHashesComputer linesHashesComputer = new SourceLinesHashesComputer();
try (CloseableIterator<String> lineIterator = sourceLinesRepository.readLines(component)) {
while (lineIterator.hasNext()) {
String line = lineIterator.next();
linesHashesComputer.addLine(line);
}
}
builder.put(fileKey, new File(component.getReportAttributes().getPath(), linesHashesComputer.getLineHashes()));
}
return builder.build();
}
use of org.sonar.core.hash.SourceLinesHashesComputer in project sonarqube by SonarSource.
the class FileMoveDetectionStepTest method mockContentOfFileInDb.
private void mockContentOfFileInDb(String key, @Nullable String[] content) {
FileSourceDto dto = new FileSourceDto();
if (content != null) {
SourceLinesHashesComputer linesHashesComputer = new SourceLinesHashesComputer();
stream(content).forEach(linesHashesComputer::addLine);
dto.setLineHashes(on('\n').join(linesHashesComputer.getLineHashes()));
}
when(fileSourceDao.selectSourceByFileUuid(dbSession, componentUuidOf(key))).thenReturn(dto);
}
Aggregations