Search in sources :

Example 6 with ScannerReportReader

use of org.sonar.scanner.protocol.output.ScannerReportReader 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 7 with ScannerReportReader

use of org.sonar.scanner.protocol.output.ScannerReportReader 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)

Example 8 with ScannerReportReader

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

the class MetadataPublisherTest method write_project_organization.

@Test
public void write_project_organization() throws Exception {
    settings.setProperty(CoreProperties.PROJECT_ORGANIZATION_PROPERTY, "SonarSource");
    File outputDir = temp.newFolder();
    ScannerReportWriter writer = new ScannerReportWriter(outputDir);
    underTest.publish(writer);
    ScannerReportReader reader = new ScannerReportReader(outputDir);
    ScannerReport.Metadata metadata = reader.readMetadata();
    assertThat(metadata.getOrganizationKey()).isEqualTo("SonarSource");
}
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)

Example 9 with ScannerReportReader

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

the class ComponentsPublisher method publish.

@Override
public void publish(ScannerReportWriter writer) {
    this.reader = new ScannerReportReader(writer.getFileStructure().root());
    this.writer = writer;
    recursiveWriteComponent((DefaultInputComponent) moduleHierarchy.root());
}
Also used : ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader)

Example 10 with ScannerReportReader

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

the class TaskResult method scanTaskCompleted.

@Override
public void scanTaskCompleted(ProjectScanContainer container) {
    LOG.info("Store analysis results in memory for later assertions in medium test");
    for (TrackedIssue issue : container.getComponentByType(IssueCache.class).all()) {
        issues.add(issue);
    }
    ReportPublisher reportPublisher = container.getComponentByType(ReportPublisher.class);
    reader = new ScannerReportReader(reportPublisher.getReportDir());
    if (!container.getComponentByType(AnalysisMode.class).isIssues()) {
        Metadata readMetadata = getReportReader().readMetadata();
        int rootComponentRef = readMetadata.getRootComponentRef();
        storeReportComponents(rootComponentRef, null, readMetadata.getBranch());
    }
    storeFs(container);
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) ReportPublisher(org.sonar.scanner.report.ReportPublisher) ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) Metadata(org.sonar.scanner.protocol.output.ScannerReport.Metadata) IssueCache(org.sonar.scanner.issue.IssueCache)

Aggregations

ScannerReportReader (org.sonar.scanner.protocol.output.ScannerReportReader)15 Test (org.junit.Test)9 File (java.io.File)7 ScannerReportWriter (org.sonar.scanner.protocol.output.ScannerReportWriter)6 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)5 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)4 Component (org.sonar.scanner.protocol.output.ScannerReport.Component)4 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)3 DefaultInputDir (org.sonar.api.batch.fs.internal.DefaultInputDir)3 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)3 InputModuleHierarchy (org.sonar.api.batch.fs.internal.InputModuleHierarchy)3 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)3 ProjectAnalysisInfo (org.sonar.scanner.ProjectAnalysisInfo)3 ComponentsPublisher (org.sonar.scanner.report.ComponentsPublisher)3 Matchers.anyString (org.mockito.Matchers.anyString)2 DefaultMeasure (org.sonar.api.batch.sensor.measure.internal.DefaultMeasure)2 ReportPublisher (org.sonar.scanner.report.ReportPublisher)2 Date (java.util.Date)1 Before (org.junit.Before)1 InputComponent (org.sonar.api.batch.fs.InputComponent)1