use of org.sonar.scanner.protocol.output.ScannerReportWriter in project sonarqube by SonarSource.
the class DefaultSensorStorage method store.
@Override
public void store(DefaultSymbolTable symbolTable) {
ScannerReportWriter writer = reportPublisher.getWriter();
DefaultInputFile inputFile = (DefaultInputFile) symbolTable.inputFile();
inputFile.setPublish(true);
int componentRef = inputFile.batchId();
if (writer.hasComponentData(FileStructure.Domain.SYMBOLS, componentRef)) {
throw new UnsupportedOperationException("Trying to save symbol table twice for the same file is not supported: " + symbolTable.inputFile().absolutePath());
}
final ScannerReport.Symbol.Builder builder = ScannerReport.Symbol.newBuilder();
final ScannerReport.TextRange.Builder rangeBuilder = ScannerReport.TextRange.newBuilder();
writer.writeComponentSymbols(componentRef, symbolTable.getReferencesBySymbol().entrySet().stream().map(input -> {
builder.clear();
rangeBuilder.clear();
TextRange declaration = input.getKey();
builder.setDeclaration(rangeBuilder.setStartLine(declaration.start().line()).setStartOffset(declaration.start().lineOffset()).setEndLine(declaration.end().line()).setEndOffset(declaration.end().lineOffset()).build());
for (TextRange reference : input.getValue()) {
builder.addReference(rangeBuilder.setStartLine(reference.start().line()).setStartOffset(reference.start().lineOffset()).setEndLine(reference.end().line()).setEndOffset(reference.end().lineOffset()).build());
}
return builder.build();
}).collect(Collectors.toList()));
}
use of org.sonar.scanner.protocol.output.ScannerReportWriter in project sonarqube by SonarSource.
the class DefaultSensorStorage method store.
@Override
public void store(DefaultHighlighting highlighting) {
ScannerReportWriter writer = reportPublisher.getWriter();
DefaultInputFile inputFile = (DefaultInputFile) highlighting.inputFile();
inputFile.setPublish(true);
int componentRef = inputFile.batchId();
if (writer.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, componentRef)) {
throw new UnsupportedOperationException("Trying to save highlighting twice for the same file is not supported: " + inputFile.absolutePath());
}
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.scanner.protocol.output.ScannerReportWriter in project sonarqube by SonarSource.
the class AnalysisContextReportPublisherTest method shouldNotDumpInIssuesMode.
@Test
public void shouldNotDumpInIssuesMode() throws Exception {
when(analysisMode.isIssues()).thenReturn(true);
ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder());
publisher.init(writer);
publisher.dumpModuleSettings(ProjectDefinition.create().setProperty("sonar.projectKey", "foo"));
assertThat(writer.getFileStructure().analysisLog()).doesNotExist();
}
use of org.sonar.scanner.protocol.output.ScannerReportWriter in project sonarqube by SonarSource.
the class CoveragePublisherTest method publishCoverage.
@Test
public void publishCoverage() throws Exception {
DefaultMeasure<String> utLineHits = new DefaultMeasure<String>().forMetric(CoreMetrics.COVERAGE_LINE_HITS_DATA).withValue("2=1;3=1;5=0;6=3");
when(measureCache.byMetric("foo:src/Foo.php", CoreMetrics.COVERAGE_LINE_HITS_DATA_KEY)).thenReturn((DefaultMeasure) utLineHits);
DefaultMeasure<String> conditionsByLine = new DefaultMeasure<String>().forMetric(CoreMetrics.CONDITIONS_BY_LINE).withValue("3=4");
when(measureCache.byMetric("foo:src/Foo.php", CoreMetrics.CONDITIONS_BY_LINE_KEY)).thenReturn((DefaultMeasure) conditionsByLine);
DefaultMeasure<String> coveredConditionsByUts = new DefaultMeasure<String>().forMetric(CoreMetrics.COVERED_CONDITIONS_BY_LINE).withValue("3=2");
when(measureCache.byMetric("foo:src/Foo.php", CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY)).thenReturn((DefaultMeasure) coveredConditionsByUts);
File outputDir = temp.newFolder();
ScannerReportWriter writer = new ScannerReportWriter(outputDir);
publisher.publish(writer);
try (CloseableIterator<LineCoverage> it = new ScannerReportReader(outputDir).readComponentCoverage(inputFile.batchId())) {
assertThat(it.next()).isEqualTo(LineCoverage.newBuilder().setLine(2).setHits(true).build());
assertThat(it.next()).isEqualTo(LineCoverage.newBuilder().setLine(3).setHits(true).setConditions(4).setCoveredConditions(2).build());
assertThat(it.next()).isEqualTo(LineCoverage.newBuilder().setLine(5).setHits(false).build());
}
}
use of org.sonar.scanner.protocol.output.ScannerReportWriter in project sonarqube by SonarSource.
the class MeasuresPublisherTest method prepare.
@Before
public void prepare() throws IOException {
String moduleKey = "foo";
inputModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder());
inputFile = new TestInputFileBuilder(moduleKey, "src/Foo.php").setPublish(true).build();
InputComponentStore componentCache = new InputComponentStore(new PathResolver());
componentCache.put(inputModule);
componentCache.put(inputFile);
measureCache = mock(MeasureCache.class);
when(measureCache.byComponentKey(anyString())).thenReturn(Collections.<DefaultMeasure<?>>emptyList());
publisher = new MeasuresPublisher(componentCache, measureCache, mock(TestPlanBuilder.class));
outputDir = temp.newFolder();
writer = new ScannerReportWriter(outputDir);
}
Aggregations