Search in sources :

Example 6 with LineRange

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

the class SourceLinesHashRepositoryImplTest method should_generate_to_persist_if_needed.

@Test
public void should_generate_to_persist_if_needed() {
    List<String> lineHashes = Lists.newArrayList("line1", "line2", "line3");
    LineRange[] lineRanges = { new LineRange(0, 1), null, new LineRange(1, 5) };
    sourceLinesHashCache.computeIfAbsent(file, c -> lineHashes);
    // DB has line hashes without significant code and significant code is available in the report, so we need to generate new line hashes
    when(dbLineHashVersion.hasLineHashesWithoutSignificantCode(file)).thenReturn(true);
    when(significantCodeRepository.getRangesPerLine(file)).thenReturn(Optional.of(lineRanges));
    LineHashesComputer hashesComputer = underTest.getLineHashesComputerToPersist(file);
    assertThat(hashesComputer).isInstanceOf(SignificantCodeLineHashesComputer.class);
}
Also used : LineHashesComputer(org.sonar.ce.task.projectanalysis.source.SourceLinesHashRepositoryImpl.LineHashesComputer) SourceLineHashesComputer(org.sonar.core.hash.SourceLineHashesComputer) SignificantCodeLineHashesComputer(org.sonar.ce.task.projectanalysis.source.SourceLinesHashRepositoryImpl.SignificantCodeLineHashesComputer) CachedLineHashesComputer(org.sonar.ce.task.projectanalysis.source.SourceLinesHashRepositoryImpl.CachedLineHashesComputer) LineRange(org.sonar.core.hash.LineRange) Test(org.junit.Test)

Example 7 with LineRange

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

the class SignificantCodeRepositoryTest method translate_offset_for_each_line.

@Test
public void translate_offset_for_each_line() {
    Component component = createComponent(1);
    List<ScannerReport.LineSgnificantCode> significantCode = new ArrayList<>();
    significantCode.add(createLineSignificantCode(1, 1, 2));
    reportReader.putSignificantCode(component.getReportAttributes().getRef(), significantCode);
    assertThat(underTest.getRangesPerLine(component)).isNotEmpty();
    LineRange[] lines = underTest.getRangesPerLine(component).get();
    assertThat(lines).hasSize(1);
    assertThat(lines[0].startOffset()).isOne();
    assertThat(lines[0].endOffset()).isEqualTo(2);
}
Also used : ArrayList(java.util.ArrayList) Component(org.sonar.ce.task.projectanalysis.component.Component) LineRange(org.sonar.core.hash.LineRange) LineSgnificantCode(org.sonar.scanner.protocol.output.ScannerReport.LineSgnificantCode) Test(org.junit.Test)

Example 8 with LineRange

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

the class SignificantCodeRepositoryTest method return_null_for_lines_without_information.

@Test
public void return_null_for_lines_without_information() {
    Component component = createComponent(5);
    List<ScannerReport.LineSgnificantCode> significantCode = new ArrayList<>();
    // line 3 and 5 missing
    significantCode.add(createLineSignificantCode(1, 1, 2));
    significantCode.add(createLineSignificantCode(2, 1, 2));
    significantCode.add(createLineSignificantCode(4, 1, 2));
    reportReader.putSignificantCode(component.getReportAttributes().getRef(), significantCode);
    assertThat(underTest.getRangesPerLine(component)).isNotEmpty();
    LineRange[] lines = underTest.getRangesPerLine(component).get();
    assertThat(lines).hasSize(5);
    assertThat(lines[0]).isNotNull();
    assertThat(lines[1]).isNotNull();
    assertThat(lines[2]).isNull();
    assertThat(lines[3]).isNotNull();
    assertThat(lines[4]).isNull();
}
Also used : ArrayList(java.util.ArrayList) Component(org.sonar.ce.task.projectanalysis.component.Component) LineRange(org.sonar.core.hash.LineRange) LineSgnificantCode(org.sonar.scanner.protocol.output.ScannerReport.LineSgnificantCode) Test(org.junit.Test)

Aggregations

LineRange (org.sonar.core.hash.LineRange)8 Test (org.junit.Test)7 SignificantCodeLineHashesComputer (org.sonar.ce.task.projectanalysis.source.SourceLinesHashRepositoryImpl.SignificantCodeLineHashesComputer)3 SourceLineHashesComputer (org.sonar.core.hash.SourceLineHashesComputer)3 LineSgnificantCode (org.sonar.scanner.protocol.output.ScannerReport.LineSgnificantCode)3 ArrayList (java.util.ArrayList)2 Component (org.sonar.ce.task.projectanalysis.component.Component)2 CachedLineHashesComputer (org.sonar.ce.task.projectanalysis.source.SourceLinesHashRepositoryImpl.CachedLineHashesComputer)2 LineHashesComputer (org.sonar.ce.task.projectanalysis.source.SourceLinesHashRepositoryImpl.LineHashesComputer)2