use of org.sonar.api.batch.rule.LoadedActiveRule 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(DateUtils.dateToLong(DateUtils.parseDateTime(active.getCreatedAt())));
loadedRule.setUpdatedAt(DateUtils.dateToLong(DateUtils.parseDateTime(active.getUpdatedAt())));
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);
loadedRule.setDeprecatedKeys(r.getDeprecatedKeys().getDeprecatedKeyList().stream().map(RuleKey::parse).collect(Collectors.toSet()));
loadedRules.add(loadedRule);
}
return loadedRules;
}
use of org.sonar.api.batch.rule.LoadedActiveRule in project sonarqube by SonarSource.
the class ActiveRulesProviderTest method testParamsAreTransformed.
@Test
public void testParamsAreTransformed() {
LoadedActiveRule r1 = mockRule("rule1");
LoadedActiveRule r2 = mockRule("rule2");
r2.setParams(ImmutableMap.of("foo1", "bar1", "foo2", "bar2"));
List<LoadedActiveRule> qpRules = ImmutableList.of(r1, r2);
when(loader.load("qp")).thenReturn(qpRules);
QualityProfiles profiles = mockProfiles("qp");
ActiveRules activeRules = provider.provide(loader, profiles);
assertThat(activeRules.findAll()).hasSize(2);
assertThat(activeRules.findAll()).extracting("ruleKey", "params").containsOnly(Tuple.tuple(RuleKey.of("rule1", "rule1"), ImmutableMap.of()), Tuple.tuple(RuleKey.of("rule2", "rule2"), ImmutableMap.of("foo1", "bar1", "foo2", "bar2")));
verify(loader).load("qp");
verifyNoMoreInteractions(loader);
}
use of org.sonar.api.batch.rule.LoadedActiveRule in project sonarqube by SonarSource.
the class ChecksMediumTest method createActiveRuleWithParam.
private LoadedActiveRule createActiveRuleWithParam(String repositoryKey, String ruleKey, @Nullable String templateRuleKey, String name, @Nullable String severity, @Nullable String internalKey, @Nullable String languag, String paramKey, String paramValue) {
LoadedActiveRule r = new LoadedActiveRule();
r.setInternalKey(internalKey);
r.setRuleKey(RuleKey.of(repositoryKey, ruleKey));
r.setName(name);
r.setTemplateRuleKey(templateRuleKey);
r.setLanguage(languag);
r.setSeverity(severity);
r.setDeprecatedKeys(emptySet());
Map<String, String> params = new HashMap<>();
params.put(paramKey, paramValue);
r.setParams(params);
return r;
}
use of org.sonar.api.batch.rule.LoadedActiveRule in project sonarqube by SonarSource.
the class IssuesMediumTest method activateTODORule.
private void activateTODORule() {
LoadedActiveRule r = new LoadedActiveRule();
r.setRuleKey(RuleKey.of("xoo", HasTagSensor.RULE_KEY));
r.setName("TODO");
r.setLanguage("xoo");
r.setSeverity("MAJOR");
r.setDeprecatedKeys(emptySet());
r.setParams(ImmutableMap.of("tag", "TODO"));
tester.activateRule(r);
}
Aggregations