Search in sources :

Example 1 with QProfile

use of org.sonar.scanner.rule.QProfile 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 2 with QProfile

use of org.sonar.scanner.rule.QProfile in project sonarqube by SonarSource.

the class MetadataPublisher method publish.

@Override
public void publish(ScannerReportWriter writer) {
    DefaultInputModule rootProject = moduleHierarchy.root();
    ProjectDefinition rootDef = rootProject.definition();
    ScannerReport.Metadata.Builder builder = ScannerReport.Metadata.newBuilder().setAnalysisDate(projectAnalysisInfo.analysisDate().getTime()).setProjectKey(rootDef.getKey()).setCrossProjectDuplicationActivated(SonarCpdBlockIndex.isCrossProjectDuplicationEnabled(settings)).setRootComponentRef(rootProject.batchId());
    String organization = settings.getString(CoreProperties.PROJECT_ORGANIZATION_PROPERTY);
    if (organization != null) {
        builder.setOrganizationKey(organization);
    }
    String branch = rootDef.getBranch();
    if (branch != null) {
        builder.setBranch(branch);
    }
    for (QProfile qp : qProfiles.findAll()) {
        builder.getMutableQprofilesPerLanguage().put(qp.getLanguage(), ScannerReport.Metadata.QProfile.newBuilder().setKey(qp.getKey()).setLanguage(qp.getLanguage()).setName(qp.getName()).setRulesUpdatedAt(qp.getRulesUpdatedAt().getTime()).build());
    }
    writer.writeMetadata(builder.build());
}
Also used : DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) QProfile(org.sonar.scanner.rule.QProfile) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition)

Aggregations

QProfile (org.sonar.scanner.rule.QProfile)2 File (java.io.File)1 Date (java.util.Date)1 Test (org.junit.Test)1 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)1 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)1 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)1 ScannerReportReader (org.sonar.scanner.protocol.output.ScannerReportReader)1 ScannerReportWriter (org.sonar.scanner.protocol.output.ScannerReportWriter)1