Search in sources :

Example 6 with ScannerReportWriter

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();
}
Also used : ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) Test(org.junit.Test)

Example 7 with ScannerReportWriter

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());
    }
}
Also used : ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) DefaultMeasure(org.sonar.api.batch.sensor.measure.internal.DefaultMeasure) LineCoverage(org.sonar.scanner.protocol.output.ScannerReport.LineCoverage) Matchers.anyString(org.mockito.Matchers.anyString) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Test(org.junit.Test)

Example 8 with ScannerReportWriter

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);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) InputComponentStore(org.sonar.scanner.scan.filesystem.InputComponentStore) MeasureCache(org.sonar.scanner.scan.measure.MeasureCache) PathResolver(org.sonar.api.scan.filesystem.PathResolver) Matchers.anyString(org.mockito.Matchers.anyString) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) Before(org.junit.Before)

Example 9 with ScannerReportWriter

use of org.sonar.scanner.protocol.output.ScannerReportWriter in project sonarqube by SonarSource.

the class MetadataPublisherTest method write_metadata.

@Test
public void write_metadata() throws Exception {
    settings.setProperty(CoreProperties.CPD_CROSS_PROJECT, "true");
    Date date = new Date();
    when(qProfiles.findAll()).thenReturn(asList(new QProfile().setKey("q1").setName("Q1").setLanguage("java").setRulesUpdatedAt(date)));
    File outputDir = temp.newFolder();
    ScannerReportWriter writer = new ScannerReportWriter(outputDir);
    underTest.publish(writer);
    ScannerReportReader reader = new ScannerReportReader(outputDir);
    ScannerReport.Metadata metadata = reader.readMetadata();
    assertThat(metadata.getAnalysisDate()).isEqualTo(1234567L);
    assertThat(metadata.getProjectKey()).isEqualTo("foo");
    assertThat(metadata.getProjectKey()).isEqualTo("foo");
    assertThat(metadata.getCrossProjectDuplicationActivated()).isTrue();
    assertThat(metadata.getQprofilesPerLanguage()).containsOnly(entry("java", org.sonar.scanner.protocol.output.ScannerReport.Metadata.QProfile.newBuilder().setKey("q1").setName("Q1").setLanguage("java").setRulesUpdatedAt(date.getTime()).build()));
}
Also used : ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) File(java.io.File) Date(java.util.Date) QProfile(org.sonar.scanner.rule.QProfile) Test(org.junit.Test)

Example 10 with ScannerReportWriter

use of org.sonar.scanner.protocol.output.ScannerReportWriter in project sonarqube by SonarSource.

the class MetadataPublisherTest method write_project_branch.

@Test
public void write_project_branch() throws Exception {
    settings.setProperty(CoreProperties.CPD_CROSS_PROJECT, "true");
    settings.setProperty(CoreProperties.PROJECT_BRANCH_PROPERTY, "myBranch");
    projectDef.properties().put(CoreProperties.PROJECT_BRANCH_PROPERTY, "myBranch");
    projectDef.setKey("foo");
    File outputDir = temp.newFolder();
    ScannerReportWriter writer = new ScannerReportWriter(outputDir);
    underTest.publish(writer);
    ScannerReportReader reader = new ScannerReportReader(outputDir);
    ScannerReport.Metadata metadata = reader.readMetadata();
    assertThat(metadata.getAnalysisDate()).isEqualTo(1234567L);
    assertThat(metadata.getProjectKey()).isEqualTo("foo");
    assertThat(metadata.getBranch()).isEqualTo("myBranch");
    // Cross project duplication disabled on branches
    assertThat(metadata.getCrossProjectDuplicationActivated()).isFalse();
}
Also used : ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) File(java.io.File) Test(org.junit.Test)

Aggregations

ScannerReportWriter (org.sonar.scanner.protocol.output.ScannerReportWriter)24 Test (org.junit.Test)14 File (java.io.File)9 Before (org.junit.Before)7 ScannerReportReader (org.sonar.scanner.protocol.output.ScannerReportReader)6 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)5 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)4 PathResolver (org.sonar.api.scan.filesystem.PathResolver)3 InputComponentStore (org.sonar.scanner.scan.filesystem.InputComponentStore)3 Matchers.anyString (org.mockito.Matchers.anyString)2 InputFile (org.sonar.api.batch.fs.InputFile)2 TextRange (org.sonar.api.batch.fs.TextRange)2 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)2 MapSettings (org.sonar.api.config.MapSettings)2 ReportPublisher (org.sonar.scanner.report.ReportPublisher)2 MeasureCache (org.sonar.scanner.scan.measure.MeasureCache)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)1