Search in sources :

Example 1 with SourceHashComputer

use of org.sonar.core.hash.SourceHashComputer in project sonarqube by SonarSource.

the class SourceHashRepositoryImplTest method getRawSourceHash_returns_hash_of_lines_from_SourceLinesRepository.

@Test
public void getRawSourceHash_returns_hash_of_lines_from_SourceLinesRepository() {
    sourceLinesRepository.addLines(FILE_REF, SOME_LINES);
    String rawSourceHash = underTest.getRawSourceHash(FILE_COMPONENT);
    SourceHashComputer sourceHashComputer = new SourceHashComputer();
    for (int i = 0; i < SOME_LINES.length; i++) {
        sourceHashComputer.addLine(SOME_LINES[i], i < (SOME_LINES.length - 1));
    }
    assertThat(rawSourceHash).isEqualTo(sourceHashComputer.getHash());
}
Also used : SourceHashComputer(org.sonar.core.hash.SourceHashComputer) Test(org.junit.Test)

Example 2 with SourceHashComputer

use of org.sonar.core.hash.SourceHashComputer in project sonarqube by SonarSource.

the class ScmInfoRepositoryImplTest method computeSourceHash.

private static String computeSourceHash(int lineCount) {
    SourceHashComputer sourceHashComputer = new SourceHashComputer();
    Iterator<String> lines = generateLines(lineCount).iterator();
    while (lines.hasNext()) {
        sourceHashComputer.addLine(lines.next(), lines.hasNext());
    }
    return sourceHashComputer.getHash();
}
Also used : SourceHashComputer(org.sonar.core.hash.SourceHashComputer)

Example 3 with SourceHashComputer

use of org.sonar.core.hash.SourceHashComputer in project sonarqube by SonarSource.

the class FileSourceDataComputerTest method computeSrcHash.

private static String computeSrcHash(List<String> lines) {
    SourceHashComputer computer = new SourceHashComputer();
    Iterator<String> iterator = lines.iterator();
    while (iterator.hasNext()) {
        computer.addLine(iterator.next(), iterator.hasNext());
    }
    return computer.getHash();
}
Also used : SourceHashComputer(org.sonar.core.hash.SourceHashComputer)

Example 4 with SourceHashComputer

use of org.sonar.core.hash.SourceHashComputer in project sonarqube by SonarSource.

the class SourceHashRepositoryImpl method computeRawSourceHash.

private String computeRawSourceHash(Component file) {
    SourceHashComputer sourceHashComputer = new SourceHashComputer();
    CloseableIterator<String> linesIterator = sourceLinesRepository.readLines(file);
    try {
        while (linesIterator.hasNext()) {
            sourceHashComputer.addLine(linesIterator.next(), linesIterator.hasNext());
        }
        return sourceHashComputer.getHash();
    } finally {
        linesIterator.close();
    }
}
Also used : SourceHashComputer(org.sonar.core.hash.SourceHashComputer)

Example 5 with SourceHashComputer

use of org.sonar.core.hash.SourceHashComputer in project sonarqube by SonarSource.

the class SourceHashRepositoryImplTest method getRawSourceHash_returns_hash_of_lines_from_SourceLinesRepository.

@Test
public void getRawSourceHash_returns_hash_of_lines_from_SourceLinesRepository() {
    sourceLinesRepository.addLines(FILE_REF, SOME_LINES);
    String rawSourceHash = underTest.getRawSourceHash(FILE_COMPONENT);
    SourceHashComputer sourceHashComputer = new SourceHashComputer();
    for (int i = 0; i < SOME_LINES.length; i++) {
        sourceHashComputer.addLine(SOME_LINES[i], i < (SOME_LINES.length - 1));
    }
    assertThat(rawSourceHash).isEqualTo(sourceHashComputer.getHash());
}
Also used : SourceHashComputer(org.sonar.core.hash.SourceHashComputer) Test(org.junit.Test)

Aggregations

SourceHashComputer (org.sonar.core.hash.SourceHashComputer)6 Test (org.junit.Test)2