Search in sources :

Example 1 with DefaultQProfileDto

use of org.sonar.db.qualityprofile.DefaultQProfileDto in project sonarqube by SonarSource.

the class RegisterQualityProfiles method ensureBuiltInDefaultQPContainsRules.

/**
 * This method ensure that if a default built-in quality profile does not have any active rules but another built-in one for the same language
 * does have active rules, the last one will be the default one.
 *
 * @see <a href="https://jira.sonarsource.com/browse/SONAR-10363">SONAR-10363</a>
 */
private void ensureBuiltInDefaultQPContainsRules(DbSession dbSession) {
    Map<String, RulesProfileDto> rulesProfilesByLanguage = dbClient.qualityProfileDao().selectBuiltInRuleProfilesWithActiveRules(dbSession).stream().collect(toMap(RulesProfileDto::getLanguage, Function.identity(), (oldValue, newValue) -> oldValue));
    dbClient.qualityProfileDao().selectDefaultBuiltInProfilesWithoutActiveRules(dbSession, rulesProfilesByLanguage.keySet()).forEach(qp -> {
        RulesProfileDto rulesProfile = rulesProfilesByLanguage.get(qp.getLanguage());
        if (rulesProfile == null) {
            return;
        }
        QProfileDto qualityProfile = dbClient.qualityProfileDao().selectByRuleProfileUuid(dbSession, rulesProfile.getUuid());
        if (qualityProfile == null) {
            return;
        }
        Set<String> uuids = dbClient.defaultQProfileDao().selectExistingQProfileUuids(dbSession, Collections.singleton(qp.getKee()));
        dbClient.defaultQProfileDao().deleteByQProfileUuids(dbSession, uuids);
        dbClient.defaultQProfileDao().insertOrUpdate(dbSession, new DefaultQProfileDto().setQProfileUuid(qualityProfile.getKee()).setLanguage(qp.getLanguage()));
        LOGGER.info("Default built-in quality profile for language [{}] has been updated from [{}] to [{}] since previous default does not have active rules.", qp.getLanguage(), qp.getName(), rulesProfile.getName());
    });
    dbSession.commit();
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Multimap(com.google.common.collect.Multimap) Function(java.util.function.Function) DbSession(org.sonar.db.DbSession) DefaultQProfileDto(org.sonar.db.qualityprofile.DefaultQProfileDto) BuiltInQProfileInsert(org.sonar.server.qualityprofile.builtin.BuiltInQProfileInsert) BuiltInQProfileUpdate(org.sonar.server.qualityprofile.builtin.BuiltInQProfileUpdate) Loggers(org.sonar.api.utils.log.Loggers) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) RulesProfileDto(org.sonar.db.qualityprofile.RulesProfileDto) BuiltInQProfile(org.sonar.server.qualityprofile.builtin.BuiltInQProfile) MoreCollectors(org.sonar.core.util.stream.MoreCollectors) BuiltInQProfileRepository(org.sonar.server.qualityprofile.builtin.BuiltInQProfileRepository) Logger(org.sonar.api.utils.log.Logger) System2(org.sonar.api.utils.System2) Profiler(org.sonar.api.utils.log.Profiler) Startable(org.sonar.api.Startable) Collection(java.util.Collection) BuiltInQualityProfilesUpdateListener(org.sonar.server.qualityprofile.builtin.BuiltInQualityProfilesUpdateListener) Set(java.util.Set) QProfileName(org.sonar.server.qualityprofile.builtin.QProfileName) String.format(java.lang.String.format) DbClient(org.sonar.db.DbClient) NONE(org.sonar.server.qualityprofile.ActiveRuleInheritance.NONE) List(java.util.List) ServerSide(org.sonar.api.server.ServerSide) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) Collections(java.util.Collections) DefaultQProfileDto(org.sonar.db.qualityprofile.DefaultQProfileDto) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) DefaultQProfileDto(org.sonar.db.qualityprofile.DefaultQProfileDto) RulesProfileDto(org.sonar.db.qualityprofile.RulesProfileDto)

Example 2 with DefaultQProfileDto

use of org.sonar.db.qualityprofile.DefaultQProfileDto in project sonarqube by SonarSource.

the class BuiltInQProfileInsertImpl method createDefaultAndOrgQProfiles.

private void createDefaultAndOrgQProfiles(DbSession batchDbSession, BuiltInQProfile builtIn, RulesProfileDto rulesProfileDto) {
    Optional<String> qProfileUuid = dbClient.defaultQProfileDao().selectDefaultQProfileUuid(batchDbSession, builtIn.getLanguage());
    OrgQProfileDto dto = new OrgQProfileDto().setRulesProfileUuid(rulesProfileDto.getUuid()).setUuid(uuidFactory.create());
    if (builtIn.isDefault() && qProfileUuid.isEmpty()) {
        DefaultQProfileDto defaultQProfileDto = new DefaultQProfileDto().setQProfileUuid(dto.getUuid()).setLanguage(builtIn.getLanguage());
        dbClient.defaultQProfileDao().insert(batchDbSession, defaultQProfileDto);
    }
    dbClient.qualityProfileDao().insert(batchDbSession, dto);
}
Also used : DefaultQProfileDto(org.sonar.db.qualityprofile.DefaultQProfileDto) OrgQProfileDto(org.sonar.db.qualityprofile.OrgQProfileDto)

Aggregations

DefaultQProfileDto (org.sonar.db.qualityprofile.DefaultQProfileDto)2 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 Multimap (com.google.common.collect.Multimap)1 String.format (java.lang.String.format)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Startable (org.sonar.api.Startable)1 ServerSide (org.sonar.api.server.ServerSide)1 System2 (org.sonar.api.utils.System2)1 Logger (org.sonar.api.utils.log.Logger)1 Loggers (org.sonar.api.utils.log.Loggers)1 Profiler (org.sonar.api.utils.log.Profiler)1 MoreCollectors (org.sonar.core.util.stream.MoreCollectors)1 DbClient (org.sonar.db.DbClient)1 DbSession (org.sonar.db.DbSession)1