use of org.sonar.api.batch.fs.internal.DefaultInputFile 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.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class DefaultSensorStorage method store.
@Override
public void store(NewHighlighting newHighlighting) {
DefaultHighlighting highlighting = (DefaultHighlighting) newHighlighting;
ScannerReportWriter writer = reportPublisher.getWriter();
DefaultInputFile inputFile = (DefaultInputFile) highlighting.inputFile();
if (shouldSkipStorage(inputFile)) {
return;
}
inputFile.setPublished(true);
int componentRef = inputFile.scannerId();
if (writer.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, componentRef)) {
throw new UnsupportedOperationException("Trying to save highlighting twice for the same file is not supported: " + inputFile);
}
final ScannerReport.SyntaxHighlightingRule.Builder builder = ScannerReport.SyntaxHighlightingRule.newBuilder();
final ScannerReport.TextRange.Builder rangeBuilder = ScannerReport.TextRange.newBuilder();
writer.writeComponentSyntaxHighlighting(componentRef, highlighting.getSyntaxHighlightingRuleSet().stream().map(input -> {
builder.setRange(rangeBuilder.setStartLine(input.range().start().line()).setStartOffset(input.range().start().lineOffset()).setEndLine(input.range().end().line()).setEndOffset(input.range().end().lineOffset()).build());
builder.setType(ScannerReportUtils.toProtocolType(input.getTextType()));
return builder.build();
}).collect(toList()));
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class DefaultIssueLocation method at.
@Override
public DefaultIssueLocation at(TextRange location) {
checkState(this.component != null, "at() should be called after on()");
checkState(this.component.isFile(), "at() should be called only for an InputFile.");
DefaultInputFile file = (DefaultInputFile) this.component;
file.validate(location);
this.textRange = location;
return this;
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class ModuleCoverageAndDuplicationExclusionsTest method shouldNotExcludeFileBasedOnPattern.
@Test
public void shouldNotExcludeFileBasedOnPattern() {
DefaultInputFile file = TestInputFileBuilder.create("foo", new File(baseDir, "moduleA"), new File(baseDir, "moduleA/src/org/polop/File.php")).setProjectBaseDir(baseDir.toPath()).build();
coverageExclusions = new ModuleCoverageAndDuplicationExclusions(mockConfig("src/org/other/*", ""));
assertThat(coverageExclusions.isExcludedForCoverage(file)).isFalse();
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class ComponentsPublisherTest method publish_unchanged_components_even_in_prs.
@Test
public void publish_unchanged_components_even_in_prs() throws IOException {
when(branchConfiguration.isPullRequest()).thenReturn(true);
ProjectInfo projectInfo = mock(ProjectInfo.class);
when(projectInfo.getAnalysisDate()).thenReturn(DateUtils.parseDate("2012-12-12"));
Path baseDir = temp.newFolder().toPath();
ProjectDefinition rootDef = ProjectDefinition.create().setKey("foo").setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "1.0").setName("Root project").setDescription("Root description").setBaseDir(baseDir.toFile()).setWorkDir(temp.newFolder());
DefaultInputProject project = new DefaultInputProject(rootDef, 1);
InputComponentStore store = new InputComponentStore(branchConfiguration, sonarRuntime);
DefaultInputFile file = new TestInputFileBuilder("foo", "src/Foo.java", 5).setLines(2).setPublish(true).setStatus(InputFile.Status.ADDED).build();
store.put("foo", file);
DefaultInputFile file2 = new TestInputFileBuilder("foo", "src2/Foo2.java", 6).setPublish(true).setStatus(InputFile.Status.SAME).setLines(2).build();
store.put("foo", file2);
ComponentsPublisher publisher = new ComponentsPublisher(project, store);
publisher.publish(writer);
assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 5)).isTrue();
// do not skip, needed for computing overall coverage
assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 6)).isTrue();
}
Aggregations