Search in sources :

Example 1 with SourceLinesHashesComputer

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();
}
Also used : SourceLinesHashesComputer(org.sonar.core.hash.SourceLinesHashesComputer) Component(org.sonar.server.computation.task.projectanalysis.component.Component) File(org.sonar.server.computation.task.projectanalysis.filemove.FileSimilarity.File) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with SourceLinesHashesComputer

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);
}
Also used : SourceLinesHashesComputer(org.sonar.core.hash.SourceLinesHashesComputer) FileSourceDto(org.sonar.db.source.FileSourceDto)

Aggregations

SourceLinesHashesComputer (org.sonar.core.hash.SourceLinesHashesComputer)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 FileSourceDto (org.sonar.db.source.FileSourceDto)1 Component (org.sonar.server.computation.task.projectanalysis.component.Component)1 File (org.sonar.server.computation.task.projectanalysis.filemove.FileSimilarity.File)1