Search in sources :

Example 16 with Rule

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

the class RulesProfileProvider method select.

private static RulesProfile select(QProfile qProfile, ActiveRules activeRules) {
    RulesProfile deprecatedProfile = new RulesProfile();
    deprecatedProfile.setName(qProfile.getName());
    deprecatedProfile.setLanguage(qProfile.getLanguage());
    for (org.sonar.api.batch.rule.ActiveRule activeRule : activeRules.findByLanguage(qProfile.getLanguage())) {
        Rule rule = Rule.create(activeRule.ruleKey().repository(), activeRule.ruleKey().rule());
        rule.setConfigKey(activeRule.internalKey());
        // SONAR-6706
        if (activeRule.templateRuleKey() != null) {
            rule.setTemplate(Rule.create(activeRule.ruleKey().repository(), activeRule.templateRuleKey()));
        }
        ActiveRule deprecatedActiveRule = deprecatedProfile.activateRule(rule, RulePriority.valueOf(activeRule.severity()));
        for (Map.Entry<String, String> param : activeRule.params().entrySet()) {
            rule.createParameter(param.getKey());
            deprecatedActiveRule.setParameter(param.getKey(), param.getValue());
        }
    }
    return deprecatedProfile;
}
Also used : RulesProfile(org.sonar.api.profiles.RulesProfile) ActiveRule(org.sonar.api.rules.ActiveRule) Rule(org.sonar.api.rules.Rule) ActiveRule(org.sonar.api.rules.ActiveRule) Map(java.util.Map)

Aggregations

Rule (org.sonar.api.rules.Rule)16 Test (org.junit.Test)11 ActiveRule (org.sonar.api.rules.ActiveRule)4 Matchers.anyString (org.mockito.Matchers.anyString)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 RuleFinder (org.sonar.api.rules.RuleFinder)3 Map (java.util.Map)2 RulesProfile (org.sonar.api.profiles.RulesProfile)2 RulePriority (org.sonar.api.rules.RulePriority)2 ValidationMessages (org.sonar.api.utils.ValidationMessages)2 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 SMInputCursor (org.codehaus.staxmate.in.SMInputCursor)1 MessageException (org.sonar.api.utils.MessageException)1 DbSession (org.sonar.db.DbSession)1 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)1 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)1