Search in sources :

Example 1 with Param

use of org.sonarqube.ws.Rules.Active.Param in project sonarqube by SonarSource.

the class DefaultActiveRulesLoader method readPage.

private static List<LoadedActiveRule> readPage(SearchResponse response) {
    List<LoadedActiveRule> loadedRules = new LinkedList<>();
    List<Rule> rulesList = response.getRulesList();
    Map<String, ActiveList> actives = response.getActives().getActives();
    for (Rule r : rulesList) {
        ActiveList activeList = actives.get(r.getKey());
        Active active = activeList.getActiveList(0);
        LoadedActiveRule loadedRule = new LoadedActiveRule();
        loadedRule.setRuleKey(RuleKey.parse(r.getKey()));
        loadedRule.setName(r.getName());
        loadedRule.setSeverity(active.getSeverity());
        loadedRule.setCreatedAt(dateToLong(parseDateTime(active.getCreatedAt())));
        loadedRule.setLanguage(r.getLang());
        loadedRule.setInternalKey(r.getInternalKey());
        if (r.hasTemplateKey()) {
            RuleKey templateRuleKey = RuleKey.parse(r.getTemplateKey());
            loadedRule.setTemplateRuleKey(templateRuleKey.rule());
        }
        Map<String, String> params = new HashMap<>();
        for (Rules.Rule.Param param : r.getParams().getParamsList()) {
            params.put(param.getKey(), param.getDefaultValue());
        }
        // overrides defaultValue if the key is the same
        for (Param param : active.getParamsList()) {
            params.put(param.getKey(), param.getValue());
        }
        loadedRule.setParams(params);
        loadedRules.add(loadedRule);
    }
    return loadedRules;
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) HashMap(java.util.HashMap) ActiveList(org.sonarqube.ws.Rules.ActiveList) LinkedList(java.util.LinkedList) Active(org.sonarqube.ws.Rules.Active) Param(org.sonarqube.ws.Rules.Active.Param) Rule(org.sonarqube.ws.Rules.Rule)

Aggregations

HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 RuleKey (org.sonar.api.rule.RuleKey)1 Active (org.sonarqube.ws.Rules.Active)1 Param (org.sonarqube.ws.Rules.Active.Param)1 ActiveList (org.sonarqube.ws.Rules.ActiveList)1 Rule (org.sonarqube.ws.Rules.Rule)1