Search in sources :

Example 1 with ActiveRuleParam

use of org.sonar.api.rules.ActiveRuleParam in project sonarqube by SonarSource.

the class QProfileExporters method toRuleActivation.

private static RuleActivation toRuleActivation(org.sonar.api.rules.ActiveRule activeRule) {
    RuleActivation ruleActivation = new RuleActivation(activeRule.getRule().ruleKey());
    ruleActivation.setSeverity(activeRule.getSeverity().name());
    for (ActiveRuleParam activeRuleParam : activeRule.getActiveRuleParams()) {
        ruleActivation.setParameter(activeRuleParam.getKey(), activeRuleParam.getValue());
    }
    return ruleActivation;
}
Also used : ActiveRuleParam(org.sonar.api.rules.ActiveRuleParam)

Example 2 with ActiveRuleParam

use of org.sonar.api.rules.ActiveRuleParam in project sonarqube by SonarSource.

the class XMLProfileSerializer method appendRuleParameters.

private static void appendRuleParameters(ActiveRule activeRule, Writer writer) throws IOException {
    if (activeRule.getActiveRuleParams() != null && !activeRule.getActiveRuleParams().isEmpty()) {
        writer.append("<parameters>");
        for (ActiveRuleParam activeRuleParam : activeRule.getActiveRuleParams()) {
            appendRuleParameter(writer, activeRuleParam);
        }
        writer.append("</parameters>");
    }
}
Also used : ActiveRuleParam(org.sonar.api.rules.ActiveRuleParam)

Example 3 with ActiveRuleParam

use of org.sonar.api.rules.ActiveRuleParam in project sonarqube by SonarSource.

the class QProfileReset method resetLanguage.

/**
   * Reset built-in profiles for the given language. Missing profiles are created and
   * existing ones are updated.
   */
public void resetLanguage(String language) {
    DbSession dbSession = db.openSession(false);
    try {
        ListMultimap<QProfileName, RulesProfile> profilesByName = loadDefinitionsGroupedByName(language);
        for (Map.Entry<QProfileName, Collection<RulesProfile>> entry : profilesByName.asMap().entrySet()) {
            QProfileName profileName = entry.getKey();
            QualityProfileDto profile = factory.getOrCreate(dbSession, profileName);
            List<RuleActivation> activations = Lists.newArrayList();
            for (RulesProfile def : entry.getValue()) {
                for (ActiveRule activeRule : def.getActiveRules()) {
                    RuleActivation activation = new RuleActivation(RuleKey.of(activeRule.getRepositoryKey(), activeRule.getRuleKey()));
                    activation.setSeverity(activeRule.getSeverity().name());
                    if (!activeRule.getActiveRuleParams().isEmpty()) {
                        for (ActiveRuleParam param : activeRule.getActiveRuleParams()) {
                            activation.setParameter(param.getParamKey(), param.getValue());
                        }
                    } else {
                        for (RuleParamDto param : db.ruleDao().selectRuleParamsByRuleKey(dbSession, activeRule.getRule().ruleKey())) {
                            activation.setParameter(param.getName(), param.getDefaultValue());
                        }
                    }
                    activations.add(activation);
                }
            }
            doReset(dbSession, profile, activations);
        }
    } finally {
        dbSession.close();
    }
}
Also used : RulesProfile(org.sonar.api.profiles.RulesProfile) ActiveRule(org.sonar.api.rules.ActiveRule) DbSession(org.sonar.db.DbSession) ActiveRuleParam(org.sonar.api.rules.ActiveRuleParam) Collection(java.util.Collection) RuleParamDto(org.sonar.db.rule.RuleParamDto) Map(java.util.Map) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 4 with ActiveRuleParam

use of org.sonar.api.rules.ActiveRuleParam 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)

Aggregations

ActiveRuleParam (org.sonar.api.rules.ActiveRuleParam)4 RulesProfile (org.sonar.api.profiles.RulesProfile)2 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Map (java.util.Map)1 RuleKey (org.sonar.api.rule.RuleKey)1 ActiveRule (org.sonar.api.rules.ActiveRule)1 DbSession (org.sonar.db.DbSession)1 LoadedTemplateDto (org.sonar.db.loadedtemplate.LoadedTemplateDto)1 RuleParamDto (org.sonar.db.rule.RuleParamDto)1