use of org.sonarqube.ws.Rules.ActiveList 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;
}
use of org.sonarqube.ws.Rules.ActiveList in project sonarqube by SonarSource.
the class DefaultActiveRulesLoaderTest method responseOfSize.
/**
* Generates an imaginary protobuf result.
*
* @param numberOfRules the number of rules, that the response should contain
* @param total the number of results on all pages
* @return the binary stream
*/
private InputStream responseOfSize(int numberOfRules, int total) {
Builder rules = SearchResponse.newBuilder();
Actives.Builder actives = Actives.newBuilder();
IntStream.rangeClosed(1, numberOfRules).mapToObj(i -> RuleKey.of("squid", "S" + i)).forEach(key -> {
Rule.Builder ruleBuilder = Rule.newBuilder();
ruleBuilder.setKey(key.toString());
rules.addRules(ruleBuilder);
Active.Builder activeBuilder = Active.newBuilder();
activeBuilder.setCreatedAt("2014-05-27T15:50:45+0100");
if (EXAMPLE_KEY.equals(key)) {
activeBuilder.addParams(Rules.Active.Param.newBuilder().setKey(FORMAT_KEY).setValue(FORMAT_VALUE));
activeBuilder.setSeverity(SEVERITY_VALUE);
}
ActiveList activeList = Rules.ActiveList.newBuilder().addActiveList(activeBuilder).build();
actives.putAllActives(ImmutableSortedMap.of(key.toString(), activeList));
});
rules.setActives(actives);
rules.setPs(numberOfRules);
rules.setTotal(total);
return new ByteArrayInputStream(rules.build().toByteArray());
}
Aggregations