Search in sources :

Example 1 with QualityProfile

use of org.sonar.server.qualityprofile.QualityProfile in project sonarqube by SonarSource.

the class UpdateQualityProfilesLastUsedDateStep method execute.

@Override
public void execute() {
    try (DbSession dbSession = dbClient.openSession(true)) {
        Component root = treeRootHolder.getRoot();
        Metric metric = metricRepository.getByKey(QUALITY_PROFILES_KEY);
        Set<QualityProfile> qualityProfiles = parseQualityProfiles(measureRepository.getRawMeasure(root, metric));
        if (qualityProfiles.isEmpty()) {
            return;
        }
        List<QualityProfileDto> dtos = dbClient.qualityProfileDao().selectByKeys(dbSession, qualityProfiles.stream().map(QualityProfile::getQpKey).collect(Collectors.toList()));
        dtos.addAll(getAncestors(dbSession, dtos));
        long analysisDate = analysisMetadataHolder.getAnalysisDate();
        dtos.forEach(dto -> {
            dto.setLastUsed(analysisDate);
            dbClient.qualityProfileDao().update(dbSession, dto);
        });
        dbSession.commit();
    }
}
Also used : DbSession(org.sonar.db.DbSession) Metric(org.sonar.server.computation.task.projectanalysis.metric.Metric) QualityProfile(org.sonar.server.qualityprofile.QualityProfile) Component(org.sonar.server.computation.task.projectanalysis.component.Component) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 2 with QualityProfile

use of org.sonar.server.qualityprofile.QualityProfile in project sonarqube by SonarSource.

the class ComputeQProfileMeasureStepTest method add_quality_profile_measure_on_project.

@Test
public void add_quality_profile_measure_on_project() throws Exception {
    treeRootHolder.setRoot(MULTI_MODULE_PROJECT);
    QualityProfile qpJava = createQProfile(QP_NAME_1, LANGUAGE_KEY_1);
    QualityProfile qpPhp = createQProfile(QP_NAME_2, LANGUAGE_KEY_2);
    analysisMetadataHolder.setQProfilesByLanguage(ImmutableMap.of(LANGUAGE_KEY_1, qpJava, LANGUAGE_KEY_2, qpPhp));
    underTest.execute();
    assertThat(measureRepository.getAddedRawMeasures(PROJECT_REF).get(QUALITY_PROFILES_KEY)).extracting("data").containsOnly(toJson(qpJava, qpPhp));
}
Also used : QualityProfile(org.sonar.server.qualityprofile.QualityProfile) Test(org.junit.Test)

Example 3 with QualityProfile

use of org.sonar.server.qualityprofile.QualityProfile in project sonarqube by SonarSource.

the class QualityProfileEventsStepTest method no_more_used_event_if_qp_no_more_listed.

@Test
public void no_more_used_event_if_qp_no_more_listed() {
    QualityProfile qp = qp(QP_NAME_1, LANGUAGE_KEY_1);
    mockMeasures(treeRootHolder.getRoot(), arrayOf(qp), null);
    Language language = mockLanguageInRepository(LANGUAGE_KEY_1);
    underTest.execute();
    verify(eventRepository).add(eq(treeRootHolder.getRoot()), eventArgumentCaptor.capture());
    verifyNoMoreInteractions(eventRepository);
    verifyEvent(eventArgumentCaptor.getValue(), "Stop using '" + qp.getQpName() + "' (" + language.getName() + ")", null);
}
Also used : AbstractLanguage(org.sonar.api.resources.AbstractLanguage) Language(org.sonar.api.resources.Language) QualityProfile(org.sonar.server.qualityprofile.QualityProfile) Test(org.junit.Test)

Example 4 with QualityProfile

use of org.sonar.server.qualityprofile.QualityProfile in project sonarqube by SonarSource.

the class QualityProfileEventsStepTest method no_more_used_event_uses_language_key_in_message_if_language_not_found.

@Test
public void no_more_used_event_uses_language_key_in_message_if_language_not_found() {
    QualityProfile qp = qp(QP_NAME_1, LANGUAGE_KEY_1);
    mockMeasures(treeRootHolder.getRoot(), arrayOf(qp), null);
    mockLanguageNotInRepository(LANGUAGE_KEY_1);
    underTest.execute();
    verify(eventRepository).add(eq(treeRootHolder.getRoot()), eventArgumentCaptor.capture());
    verifyNoMoreInteractions(eventRepository);
    verifyEvent(eventArgumentCaptor.getValue(), "Stop using '" + qp.getQpName() + "' (" + qp.getLanguageKey() + ")", null);
}
Also used : QualityProfile(org.sonar.server.qualityprofile.QualityProfile) Test(org.junit.Test)

Example 5 with QualityProfile

use of org.sonar.server.qualityprofile.QualityProfile in project sonarqube by SonarSource.

the class LoadReportAnalysisMetadataHolderStep method loadQualityProfiles.

private void loadQualityProfiles(ScannerReport.Metadata reportMetadata) {
    analysisMetadata.setQProfilesByLanguage(reportMetadata.getQprofilesPerLanguageMap().values().stream().collect(toMap(QProfile::getLanguage, qp -> new QualityProfile(qp.getKey(), qp.getName(), qp.getLanguage(), new Date(qp.getRulesUpdatedAt())))));
    analysisMetadata.setScannerPluginsByKey(reportMetadata.getPluginsByKeyMap().values().stream().collect(toMap(Plugin::getKey, p -> new ScannerPlugin(p.getKey(), getBasePluginKey(p), p.getUpdatedAt()))));
}
Also used : ScannerPlugin(org.sonar.ce.task.projectanalysis.analysis.ScannerPlugin) QualityProfile(org.sonar.server.qualityprofile.QualityProfile) QProfile(org.sonar.scanner.protocol.output.ScannerReport.Metadata.QProfile) Date(java.util.Date) Plugin(org.sonar.scanner.protocol.output.ScannerReport.Metadata.Plugin) ScannerPlugin(org.sonar.ce.task.projectanalysis.analysis.ScannerPlugin)

Aggregations

QualityProfile (org.sonar.server.qualityprofile.QualityProfile)25 Test (org.junit.Test)22 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)13 Date (java.util.Date)12 AbstractLanguage (org.sonar.api.resources.AbstractLanguage)6 Language (org.sonar.api.resources.Language)6 Component (org.sonar.ce.task.projectanalysis.component.Component)2 Event (org.sonar.ce.task.projectanalysis.event.Event)2 DbSession (org.sonar.db.DbSession)2 Component (org.sonar.server.computation.task.projectanalysis.component.Component)2 HashSet (java.util.HashSet)1 ExpectedException (org.junit.rules.ExpectedException)1 ScannerPlugin (org.sonar.ce.task.projectanalysis.analysis.ScannerPlugin)1 ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)1 Metric (org.sonar.ce.task.projectanalysis.metric.Metric)1 ComponentDto (org.sonar.db.component.ComponentDto)1 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)1 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)1 Plugin (org.sonar.scanner.protocol.output.ScannerReport.Metadata.Plugin)1 QProfile (org.sonar.scanner.protocol.output.ScannerReport.Metadata.QProfile)1