Search in sources :

Example 1 with RulesProfile

use of org.sonar.api.profiles.RulesProfile in project sonarqube by SonarSource.

the class XooBasicProfile method createProfile.

@Override
public RulesProfile createProfile(ValidationMessages validation) {
    final RulesProfile profile = RulesProfile.create("Basic", Xoo.KEY);
    profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR);
    return profile;
}
Also used : RulesProfile(org.sonar.api.profiles.RulesProfile)

Example 2 with RulesProfile

use of org.sonar.api.profiles.RulesProfile in project sonarqube by SonarSource.

the class XooFakeImporter method importProfile.

@Override
public RulesProfile importProfile(Reader reader, ValidationMessages messages) {
    RulesProfile rulesProfile = RulesProfile.create();
    rulesProfile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, "x1"), RulePriority.CRITICAL);
    return rulesProfile;
}
Also used : RulesProfile(org.sonar.api.profiles.RulesProfile)

Example 3 with RulesProfile

use of org.sonar.api.profiles.RulesProfile in project sonarqube by SonarSource.

the class Xoo2BasicProfile method createProfile.

@Override
public RulesProfile createProfile(ValidationMessages messages) {
    RulesProfile profile = RulesProfile.create("Basic", Xoo2.KEY);
    // so UGLY
    profile.activateRule(Rule.create(XooRulesDefinition.XOO2_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR);
    return profile;
}
Also used : RulesProfile(org.sonar.api.profiles.RulesProfile)

Example 4 with RulesProfile

use of org.sonar.api.profiles.RulesProfile in project sonarqube by SonarSource.

the class QProfileExporters method wrap.

private RulesProfile wrap(QualityProfileDto profile) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        RulesProfile target = new RulesProfile(profile.getName(), profile.getLanguage());
        List<ActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByProfileKey(dbSession, profile.getKey());
        List<ActiveRuleParamDto> activeRuleParamDtos = dbClient.activeRuleDao().selectParamsByActiveRuleIds(dbSession, Lists.transform(activeRuleDtos, ActiveRuleDto::getId));
        ListMultimap<Integer, ActiveRuleParamDto> activeRuleParamsByActiveRuleId = FluentIterable.from(activeRuleParamDtos).index(ActiveRuleParamDto::getActiveRuleId);
        for (ActiveRuleDto activeRule : activeRuleDtos) {
            // TODO all rules should be loaded by using one query with all active rule keys as parameter
            Rule rule = ruleFinder.findByKey(activeRule.getKey().ruleKey());
            org.sonar.api.rules.ActiveRule wrappedActiveRule = target.activateRule(rule, RulePriority.valueOf(activeRule.getSeverityString()));
            List<ActiveRuleParamDto> paramDtos = activeRuleParamsByActiveRuleId.get(activeRule.getId());
            for (ActiveRuleParamDto activeRuleParamDto : paramDtos) {
                wrappedActiveRule.setParameter(activeRuleParamDto.getKey(), activeRuleParamDto.getValue());
            }
        }
        return target;
    }
}
Also used : DbSession(org.sonar.db.DbSession) RulesProfile(org.sonar.api.profiles.RulesProfile) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) Rule(org.sonar.api.rules.Rule) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto)

Example 5 with RulesProfile

use of org.sonar.api.profiles.RulesProfile in project sonarqube by SonarSource.

the class RegisterQualityProfiles method start.

public void start() {
    Profiler profiler = Profiler.create(Loggers.get(getClass())).startInfo("Register quality profiles");
    DbSession session = dbClient.openSession(false);
    try {
        List<ActiveRuleChange> changes = new ArrayList<>();
        ListMultimap<String, RulesProfile> profilesByLanguage = profilesByLanguage();
        for (String language : profilesByLanguage.keySet()) {
            List<RulesProfile> defs = profilesByLanguage.get(language);
            if (verifyLanguage(language, defs)) {
                changes.addAll(registerProfilesForLanguage(session, language, defs));
            }
        }
        activeRuleIndexer.index(changes);
        profiler.stopDebug();
    } finally {
        session.close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) Profiler(org.sonar.api.utils.log.Profiler) RulesProfile(org.sonar.api.profiles.RulesProfile) ArrayList(java.util.ArrayList)

Aggregations

RulesProfile (org.sonar.api.profiles.RulesProfile)19 Test (org.junit.Test)5 ValidationMessages (org.sonar.api.utils.ValidationMessages)4 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)4 ActiveRulesBuilder (org.sonar.api.batch.rule.internal.ActiveRulesBuilder)3 DbSession (org.sonar.db.DbSession)3 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)3 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ProfileDefinition (org.sonar.api.profiles.ProfileDefinition)2 ProfileImporter (org.sonar.api.profiles.ProfileImporter)2 RuleKey (org.sonar.api.rule.RuleKey)2 ActiveRule (org.sonar.api.rules.ActiveRule)2 ActiveRuleParam (org.sonar.api.rules.ActiveRuleParam)2 Rule (org.sonar.api.rules.Rule)2 RulesDefinition (org.sonar.api.server.rule.RulesDefinition)2 ActiveRuleDao (org.sonar.db.qualityprofile.ActiveRuleDao)2 ActiveRuleKey (org.sonar.db.qualityprofile.ActiveRuleKey)2 QualityProfileDao (org.sonar.db.qualityprofile.QualityProfileDao)2