@Test public void use_template_rule_key() { RuleKey ruleKey = RuleKey.of("squid", "S0001_123"); NewActiveRule rule = new NewActiveRule.Builder() .setRuleKey(ruleKey) .setTemplateRuleKey("S0001") .build(); builder.addRule(rule); CheckFactory checkFactory = new CheckFactory(builder.build()); Checks checks = checkFactory.create("squid").addAnnotatedChecks(CheckWithKey.class); Object check = checks.of(ruleKey); assertThat(check).isInstanceOf(CheckWithKey.class); assertThat(checks.of(ruleKey)).isSameAs(check); assertThat(checks.ruleKey(check)).isEqualTo(ruleKey); assertThat(checks.all()).containsOnly(check); }
private static NewActiveRule transform(LoadedActiveRule activeRule, String qProfileKey) { NewActiveRule.Builder builder = new NewActiveRule.Builder(); builder .setRuleKey(activeRule.getRuleKey()) .setName(activeRule.getName()) .setSeverity(activeRule.getSeverity()) .setCreatedAt(activeRule.getCreatedAt()) .setUpdatedAt(activeRule.getUpdatedAt()) .setLanguage(activeRule.getLanguage()) .setInternalKey(activeRule.getInternalKey()) .setTemplateRuleKey(activeRule.getTemplateRuleKey()) .setQProfileKey(qProfileKey); // load parameters if (activeRule.getParams() != null) { for (Map.Entry<String, String> params : activeRule.getParams().entrySet()) { builder.setParam(params.getKey(), params.getValue()); } } return builder.build(); }
private static void createNewActiveRule(ActiveRulesBuilder builder, ActiveRule activeRule, Sonarlint.Rules storageRules, String language, Rules rules) { RuleKey ruleKey = RuleKey.of(activeRule.getRepo(), activeRule.getKey()); Rule rule = rules.find(ruleKey); Sonarlint.Rules.Rule storageRule; try { storageRule = storageRules.getRulesByKeyOrThrow(ruleKey.toString()); } catch (IllegalArgumentException e) { throw new MessageException("Unknown active rule in the quality profile of the project. Please update the SonarQube server binding."); } Builder newActiveRule = new NewActiveRule.Builder() .setRuleKey(ruleKey) .setLanguage(language) .setName(rule.name()) .setInternalKey(rule.internalKey()) .setSeverity(activeRule.getSeverity()); if (!StringUtils.isEmpty(storageRule.getTemplateKey())) { RuleKey templateRuleKey = RuleKey.parse(storageRule.getTemplateKey()); newActiveRule.setTemplateRuleKey(templateRuleKey.rule()); } for (Map.Entry<String, String> param : activeRule.getParamsMap().entrySet()) { newActiveRule.setParam(param.getKey(), param.getValue()); } builder.addRule(newActiveRule.build()); }
private static NewActiveRule transform(LoadedActiveRule activeRule, String qProfileKey) { NewActiveRule.Builder builder = new NewActiveRule.Builder(); builder .setRuleKey(activeRule.getRuleKey()) .setName(activeRule.getName()) .setSeverity(activeRule.getSeverity()) .setCreatedAt(activeRule.getCreatedAt()) .setUpdatedAt(activeRule.getUpdatedAt()) .setLanguage(activeRule.getLanguage()) .setInternalKey(activeRule.getInternalKey()) .setTemplateRuleKey(activeRule.getTemplateRuleKey()) .setQProfileKey(qProfileKey); // load parameters if (activeRule.getParams() != null) { for (Map.Entry<String, String> params : activeRule.getParams().entrySet()) { builder.setParam(params.getKey(), params.getValue()); } } return builder.build(); }