use of org.sonar.api.batch.sensor.code.internal.DefaultSignificantCode in project sonarqube by SonarSource.
the class DefaultSensorStorageTest method duplicateSignificantCode.
@Test(expected = UnsupportedOperationException.class)
public void duplicateSignificantCode() throws Exception {
InputFile inputFile = new TestInputFileBuilder("foo", "src/Foo.java").setModuleBaseDir(temp.newFolder().toPath()).build();
DefaultSignificantCode h = new DefaultSignificantCode(null).onFile(inputFile);
underTest.store(h);
underTest.store(h);
}
use of org.sonar.api.batch.sensor.code.internal.DefaultSignificantCode in project sonarqube by SonarSource.
the class DefaultSensorStorageTest method should_skip_significant_code_on_pull_request_when_file_status_is_SAME.
@Test
public void should_skip_significant_code_on_pull_request_when_file_status_is_SAME() {
DefaultInputFile file = new TestInputFileBuilder("foo", "src/Foo.php").setStatus(InputFile.Status.SAME).setContents("foo").build();
when(branchConfiguration.isPullRequest()).thenReturn(true);
underTest.store(new DefaultSignificantCode().onFile(file).addRange(file.selectLine(1)));
assertThat(reportWriter.hasComponentData(FileStructure.Domain.SGNIFICANT_CODE, file.scannerId())).isFalse();
}
use of org.sonar.api.batch.sensor.code.internal.DefaultSignificantCode in project sonarqube by SonarSource.
the class DefaultSensorStorage method store.
@Override
public void store(NewSignificantCode newSignificantCode) {
DefaultSignificantCode significantCode = (DefaultSignificantCode) newSignificantCode;
ScannerReportWriter writer = reportPublisher.getWriter();
DefaultInputFile inputFile = (DefaultInputFile) significantCode.inputFile();
if (shouldSkipStorage(inputFile)) {
return;
}
inputFile.setPublished(true);
int componentRef = inputFile.scannerId();
if (writer.hasComponentData(FileStructure.Domain.SGNIFICANT_CODE, componentRef)) {
throw new UnsupportedOperationException("Trying to save significant code information twice for the same file is not supported: " + significantCode.inputFile());
}
List<ScannerReport.LineSgnificantCode> protobuf = significantCode.significantCodePerLine().values().stream().map(range -> ScannerReport.LineSgnificantCode.newBuilder().setLine(range.start().line()).setStartOffset(range.start().lineOffset()).setEndOffset(range.end().lineOffset()).build()).collect(Collectors.toList());
writer.writeComponentSignificantCode(componentRef, protobuf);
}
use of org.sonar.api.batch.sensor.code.internal.DefaultSignificantCode in project sonarqube by SonarSource.
the class DefaultSensorStorageTest method should_save_significant_code.
@Test
public void should_save_significant_code() {
DefaultInputFile file = new TestInputFileBuilder("foo", "src/Foo.php").setContents("foo").build();
underTest.store(new DefaultSignificantCode().onFile(file).addRange(file.selectLine(1)));
assertThat(reportWriter.hasComponentData(FileStructure.Domain.SGNIFICANT_CODE, file.scannerId())).isTrue();
}
use of org.sonar.api.batch.sensor.code.internal.DefaultSignificantCode in project sonarqube by SonarSource.
the class InMemorySensorStorage method store.
@Override
public void store(NewSignificantCode newSignificantCode) {
DefaultSignificantCode significantCode = (DefaultSignificantCode) newSignificantCode;
String fileKey = significantCode.inputFile().key();
// Emulate duplicate storage check
if (significantCodePerComponent.containsKey(fileKey)) {
throw new UnsupportedOperationException("Trying to save significant code information twice for the same file is not supported: " + significantCode.inputFile());
}
significantCodePerComponent.put(fileKey, significantCode);
}
Aggregations