Search in sources :

Example 1 with ScannerPlugin

use of org.sonar.scanner.bootstrap.ScannerPlugin in project sonarqube by SonarSource.

the class MetadataPublisherTest method write_metadata.

@Test
public void write_metadata() throws Exception {
    Date date = new Date();
    when(qProfiles.findAll()).thenReturn(Collections.singletonList(new QProfile("q1", "Q1", "java", date)));
    when(pluginRepository.getPluginsByKey()).thenReturn(ImmutableMap.of("java", new ScannerPlugin("java", 12345L, null), "php", new ScannerPlugin("php", 45678L, null)));
    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("root");
    assertThat(metadata.getModulesProjectRelativePathByKeyMap()).containsOnly(entry("module", "modulePath"), entry("root", ""));
    assertThat(metadata.getProjectVersion()).isEmpty();
    assertThat(metadata.getNotAnalyzedFilesByLanguageCount()).isZero();
    assertThat(metadata.getQprofilesPerLanguageMap()).containsOnly(entry("java", org.sonar.scanner.protocol.output.ScannerReport.Metadata.QProfile.newBuilder().setKey("q1").setName("Q1").setLanguage("java").setRulesUpdatedAt(date.getTime()).build()));
    assertThat(metadata.getPluginsByKey()).containsOnly(entry("java", org.sonar.scanner.protocol.output.ScannerReport.Metadata.Plugin.newBuilder().setKey("java").setUpdatedAt(12345).build()), entry("php", org.sonar.scanner.protocol.output.ScannerReport.Metadata.Plugin.newBuilder().setKey("php").setUpdatedAt(45678).build()));
}
Also used : ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) ScannerPlugin(org.sonar.scanner.bootstrap.ScannerPlugin) 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 ScannerPlugin

use of org.sonar.scanner.bootstrap.ScannerPlugin in project sonarqube by SonarSource.

the class MetadataPublisher method publish.

@Override
public void publish(ScannerReportWriter writer) {
    AbstractProjectOrModule rootProject = moduleHierarchy.root();
    ScannerReport.Metadata.Builder builder = ScannerReport.Metadata.newBuilder().setAnalysisDate(projectInfo.getAnalysisDate().getTime()).setProjectKey(rootProject.key()).setCrossProjectDuplicationActivated(cpdSettings.isCrossProjectDuplicationEnabled()).setRootComponentRef(rootProject.scannerId());
    projectInfo.getProjectVersion().ifPresent(builder::setProjectVersion);
    projectInfo.getBuildString().ifPresent(builder::setBuildString);
    if (branchConfiguration.branchName() != null) {
        addBranchInformation(builder);
    }
    addScmInformation(builder);
    addNotAnalyzedFileCountsByLanguage(builder);
    for (QProfile qp : qProfiles.findAll()) {
        builder.putQprofilesPerLanguage(qp.getLanguage(), ScannerReport.Metadata.QProfile.newBuilder().setKey(qp.getKey()).setLanguage(qp.getLanguage()).setName(qp.getName()).setRulesUpdatedAt(qp.getRulesUpdatedAt().getTime()).build());
    }
    for (Entry<String, ScannerPlugin> pluginEntry : pluginRepository.getPluginsByKey().entrySet()) {
        builder.putPluginsByKey(pluginEntry.getKey(), ScannerReport.Metadata.Plugin.newBuilder().setKey(pluginEntry.getKey()).setUpdatedAt(pluginEntry.getValue().getUpdatedAt()).build());
    }
    addModulesRelativePaths(builder);
    writer.writeMetadata(builder.build());
}
Also used : ScannerPlugin(org.sonar.scanner.bootstrap.ScannerPlugin) AbstractProjectOrModule(org.sonar.api.batch.fs.internal.AbstractProjectOrModule) QProfile(org.sonar.scanner.rule.QProfile)

Aggregations

ScannerPlugin (org.sonar.scanner.bootstrap.ScannerPlugin)2 QProfile (org.sonar.scanner.rule.QProfile)2 File (java.io.File)1 Date (java.util.Date)1 Test (org.junit.Test)1 AbstractProjectOrModule (org.sonar.api.batch.fs.internal.AbstractProjectOrModule)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