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()));
}
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());
}
Aggregations