Search in sources :

Example 1 with LoadedTemplateDto

use of org.sonar.db.loadedtemplate.LoadedTemplateDto in project sonarqube by SonarSource.

the class RegisterQualityProfiles method register.

private List<ActiveRuleChange> register(QProfileName name, Collection<RulesProfile> profiles, DbSession session) {
    LOGGER.info("Register profile " + name);
    List<ActiveRuleChange> changes = new ArrayList<>();
    QualityProfileDto profileDto = dbClient.qualityProfileDao().selectByNameAndLanguage(name.getName(), name.getLanguage(), session);
    if (profileDto != null) {
        changes.addAll(profileFactory.delete(session, profileDto.getKey(), true));
    }
    profileFactory.create(session, name);
    for (RulesProfile profile : profiles) {
        for (org.sonar.api.rules.ActiveRule activeRule : profile.getActiveRules()) {
            RuleKey ruleKey = RuleKey.of(activeRule.getRepositoryKey(), activeRule.getRuleKey());
            RuleActivation activation = new RuleActivation(ruleKey);
            activation.setSeverity(activeRule.getSeverity() != null ? activeRule.getSeverity().name() : null);
            for (ActiveRuleParam param : activeRule.getActiveRuleParams()) {
                activation.setParameter(param.getKey(), param.getValue());
            }
            changes.addAll(ruleActivator.activate(session, activation, name));
        }
    }
    LoadedTemplateDto template = new LoadedTemplateDto(templateKey(name), LoadedTemplateDto.QUALITY_PROFILE_TYPE);
    dbClient.loadedTemplateDao().insert(template, session);
    session.commit();
    return changes;
}
Also used : RulesProfile(org.sonar.api.profiles.RulesProfile) ActiveRuleParam(org.sonar.api.rules.ActiveRuleParam) RuleKey(org.sonar.api.rule.RuleKey) ArrayList(java.util.ArrayList) LoadedTemplateDto(org.sonar.db.loadedtemplate.LoadedTemplateDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 2 with LoadedTemplateDto

use of org.sonar.db.loadedtemplate.LoadedTemplateDto in project sonarqube by SonarSource.

the class RegisterQualityGatesTest method does_not_register_default_gate_if_already_executed.

@Test
public void does_not_register_default_gate_if_already_executed() {
    String templateType = "QUALITY_GATE";
    String templateName = "SonarQube way";
    dbClient.loadedTemplateDao().insert(new LoadedTemplateDto(templateName, templateType), dbSession);
    dbSession.commit();
    task.start();
    assertThat(dbClient.qualityGateDao().selectAll(dbSession)).isEmpty();
    verifyZeroInteractions(qualityGates);
}
Also used : LoadedTemplateDto(org.sonar.db.loadedtemplate.LoadedTemplateDto) Test(org.junit.Test)

Aggregations

LoadedTemplateDto (org.sonar.db.loadedtemplate.LoadedTemplateDto)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 RulesProfile (org.sonar.api.profiles.RulesProfile)1 RuleKey (org.sonar.api.rule.RuleKey)1 ActiveRuleParam (org.sonar.api.rules.ActiveRuleParam)1 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)1