@Test public void fail_to_add_twice_the_same_param() { RulesBuilder builder = new RulesBuilder(); NewRule newRule = builder.add(RuleKey.of("squid", "S0001")); newRule.addParam("min"); newRule.addParam("max"); thrown.expect(IllegalStateException.class); thrown.expectMessage("Parameter 'min' already exists on rule 'squid:S0001'"); newRule.addParam("min"); } }
private Rules load(RuleDao ruleDao, DefaultDebtModel debtModel, Durations durations) { RulesBuilder rulesBuilder = new RulesBuilder(); List<RuleParamDto> ruleParamDtos = ruleDao.selectParameters(); ListMultimap<Integer, RuleParamDto> paramDtosByRuleId = ArrayListMultimap.create(); for (RuleParamDto dto : ruleParamDtos) { paramDtosByRuleId.put(dto.getRuleId(), dto); } for (RuleDto ruleDto : ruleDao.selectEnablesAndNonManual()) { RuleKey ruleKey = RuleKey.of(ruleDto.getRepositoryKey(), ruleDto.getRuleKey()); NewRule newRule = rulesBuilder.add(ruleKey) .setId(ruleDto.getId()) .setName(ruleDto.getName()) .setSeverity(ruleDto.getSeverityString()) .setDescription(ruleDto.getDescription()) .setStatus(ruleDto.getStatus()) .setInternalKey(ruleDto.getConfigKey()); if (hasCharacteristic(ruleDto)) { newRule.setDebtSubCharacteristic(effectiveCharacteristic(ruleDto, ruleKey, debtModel).key()); newRule.setDebtRemediationFunction(effectiveFunction(ruleDto, ruleKey, durations)); } for (RuleParamDto ruleParamDto : paramDtosByRuleId.get(ruleDto.getId())) { newRule.addParam(ruleParamDto.getName()) .setDescription(ruleParamDto.getDescription()); } } return rulesBuilder.build(); }
private static Rules createRules(StandaloneRuleDefinitionsLoader pluginRulesLoader) { RulesBuilder builder = new RulesBuilder(); for (RulesDefinition.Repository repoDef : pluginRulesLoader.getContext().repositories()) { for (RulesDefinition.Rule ruleDef : repoDef.rules()) { if (ruleDef.type() == RuleType.SECURITY_HOTSPOT) { continue; } NewRule newRule = builder.add(RuleKey.of(ruleDef.repository().key(), ruleDef.key())) .setInternalKey(ruleDef.internalKey()) .setDescription(ruleDef.htmlDescription() != null ? ruleDef.htmlDescription() : Markdown.convertToHtml(ruleDef.markdownDescription())) .setSeverity(ruleDef.severity()) .setType(ruleDef.type() != null ? ruleDef.type().toString() : null) .setName(ruleDef.name()); for (Param p : ruleDef.params()) { newRule.addParam(p.key()) .setDescription(p.description()); } } } return builder.build(); } }