/** * @return the config key the active rule belongs to */ public String getConfigKey() { return rule.getConfigKey(); }
private void verifyRule(Rule rule, RuleDefinitionDto ruleDefinition, RuleParamDto ruleParam) { assertThat(rule).isNotNull(); assertThat(rule.getName()).isEqualTo(ruleDefinition.getName()); assertThat(rule.getLanguage()).isEqualTo(ruleDefinition.getLanguage()); assertThat(rule.getKey()).isEqualTo(ruleDefinition.getRuleKey()); assertThat(rule.getConfigKey()).isEqualTo(ruleDefinition.getConfigKey()); assertThat(rule.isTemplate()).isEqualTo(ruleDefinition.isTemplate()); assertThat(rule.getCreatedAt().getTime()).isEqualTo(ruleDefinition.getCreatedAt()); assertThat(rule.getUpdatedAt().getTime()).isEqualTo(ruleDefinition.getUpdatedAt()); assertThat(rule.getRepositoryKey()).isEqualTo(ruleDefinition.getRepositoryKey()); assertThat(rule.getSeverity().name()).isEqualTo(ruleDefinition.getSeverityString()); assertThat(rule.getSystemTags()).isEqualTo(ruleDefinition.getSystemTags().stream().toArray(String[]::new)); assertThat(rule.getTags()).isEmpty(); assertThat(rule.getId()).isEqualTo(ruleDefinition.getId()); assertThat(rule.getDescription()).isEqualTo(ruleDefinition.getDescription()); assertThat(rule.getParams()).hasSize(1); org.sonar.api.rules.RuleParam param = rule.getParams().iterator().next(); assertThat(param.getRule()).isSameAs(rule); assertThat(param.getKey()).isEqualTo(ruleParam.getName()); assertThat(param.getDescription()).isEqualTo(ruleParam.getDescription()); assertThat(param.getType()).isEqualTo(ruleParam.getType()); assertThat(param.getDefaultValue()).isEqualTo(ruleParam.getDefaultValue()); } }
@Test public void should_success_finder_wrap() { // has Id assertThat(underTest.findById(rule1.getId()).getId()).isEqualTo(rule1.getId()); // should_find_by_id assertThat(underTest.findById(rule3.getId()).getConfigKey()).isEqualTo("Checker/Treewalker/AnnotationUseStyleCheck"); // should_not_find_disabled_rule_by_id assertThat(underTest.findById(rule2.getId())).isNull(); // should_find_by_key Rule rule = underTest.findByKey("checkstyle", "com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck"); assertThat(rule).isNotNull(); assertThat(rule.getKey()).isEqualTo(("com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck")); assertThat(rule.isEnabled()).isTrue(); // find_should_return_null_if_no_results assertThat(underTest.findByKey("checkstyle", "unknown")).isNull(); assertThat(underTest.find(RuleQuery.create().withRepositoryKey("checkstyle").withConfigKey("unknown"))).isNull(); // find_repository_rules assertThat(underTest.findAll(RuleQuery.create().withRepositoryKey("checkstyle"))).hasSize(2); // find_all_enabled assertThat(underTest.findAll(RuleQuery.create())).extracting("id").containsOnly(rule1.getId(), rule3.getId(), rule4.getId()); assertThat(underTest.findAll(RuleQuery.create())).hasSize(3); // do_not_find_disabled_rules assertThat(underTest.findByKey("checkstyle", "DisabledCheck")).isNull(); // do_not_find_unknown_rules assertThat(underTest.findAll(RuleQuery.create().withRepositoryKey("unknown_repository"))).isEmpty(); }
newRule.setName(ruleName(repository.getKey(), rule)); newRule.setHtmlDescription(ruleDescription(repository.getKey(), rule)); newRule.setInternalKey(rule.getConfigKey()); newRule.setTemplate(rule.isTemplate()); newRule.setSeverity(rule.getSeverity().toString());
/** * @return the config key the active rule belongs to */ public String getConfigKey() { return rule.getConfigKey(); }
/** * @return the config key the active rule belongs to */ public String getConfigKey() { return rule.getConfigKey(); }
public final String getRuleKey() { return rule.getConfigKey(); }
private List<FxCopRule> transformIntoFxCopRules(List<ActiveRule> activeRulesByPlugin) { List<FxCopRule> result = new ArrayList<FxCopRule>(); for (ActiveRule activeRule : activeRulesByPlugin) { // Extracts the rule's information Rule rule = activeRule.getRule(); String configKey = rule.getConfigKey(); String fileName = StringUtils.substringAfter(configKey, "@"); String name = StringUtils.substringBefore(configKey, "@"); // Creates the FxCop rule FxCopRule fxCopRule = new FxCopRule(); fxCopRule.setEnabled(true); fxCopRule.setFileName(fileName); fxCopRule.setName(name); RulePriority priority = activeRule.getSeverity(); if (priority != null) { fxCopRule.setPriority(priority.name().toLowerCase()); } result.add(fxCopRule); } return result; }
private PmdRuleset createPmdRuleset(String repositoryKey, List<ActiveRule> activeRules, String profileName) { PmdRuleset ruleset = new PmdRuleset(profileName); for (ActiveRule activeRule : activeRules) { if (activeRule.getRule().getRepositoryKey().equals(repositoryKey)) { String configKey = activeRule.getRule().getConfigKey(); PmdRule rule = new PmdRule(configKey, PmdLevelUtils.toLevel(activeRule.getSeverity())); if ((activeRule.getActiveRuleParams() != null) && !activeRule.getActiveRuleParams().isEmpty()) { List<PmdProperty> properties = new ArrayList<PmdProperty>(); for (ActiveRuleParam activeRuleParam : activeRule.getActiveRuleParams()) { properties.add(new PmdProperty(activeRuleParam.getRuleParam().getKey(), activeRuleParam.getValue())); } rule.setProperties(properties); } ruleset.addRule(rule); processXPathRule(activeRule.getRuleKey(), rule); } } return ruleset; }
private PmdRuleSet createPmdRuleset(String repositoryKey, List<ActiveRule> activeRules) { PmdRuleSet ruleset = new PmdRuleSet(); ruleset.setName(repositoryKey); ruleset.setDescription(String.format("Sonar Profile: %s", repositoryKey)); for (ActiveRule activeRule : activeRules) { if (activeRule.getRule().getRepositoryKey().equals(repositoryKey)) { String configKey = activeRule.getRule().getConfigKey(); PmdRule rule = new PmdRule(configKey, PmdLevelUtils.toLevel(activeRule.getSeverity())); addRuleProperties(activeRule, rule); ruleset.addRule(rule); processXPathRule(activeRule.getRuleKey(), rule); } } return ruleset; } }
private PmdRuleset createPmdRuleset(String repositoryKey, List<ActiveRule> activeRules, String profileName) { PmdRuleset ruleset = new PmdRuleset(profileName); for (ActiveRule activeRule : activeRules) { if (activeRule.getRule().getRepositoryKey().equals(repositoryKey)) { String configKey = activeRule.getRule().getConfigKey(); PmdRule rule = new PmdRule(configKey, PmdLevelUtils.toLevel(activeRule.getSeverity())); if ((activeRule.getActiveRuleParams() != null) && !activeRule.getActiveRuleParams().isEmpty()) { List<PmdProperty> properties = new ArrayList<>(); for (ActiveRuleParam activeRuleParam : activeRule.getActiveRuleParams()) { properties.add(new PmdProperty(activeRuleParam.getRuleParam().getKey(), activeRuleParam.getValue())); } rule.setProperties(properties); } ruleset.addRule(rule); processXPathRule(activeRule.getRuleKey(), rule); } } return ruleset; }
/** * Materialize the current active rule set for the profile * * @param activeRules * @param profileName * @return */ protected PmdRuleset createPmdRuleset(List<ActiveRule> activeRules, String profileName) { PmdRuleset ruleset = new PmdRuleset(profileName); for (ActiveRule activeRule : activeRules) { if (activeRule.getRule().getPluginName().equals(PhpmdRuleRepository.PHPMD_REPOSITORY_KEY)) { String configKey = activeRule.getRule().getConfigKey(); PmdRule rule = new PmdRule(configKey, mapper.to(activeRule.getPriority())); List<ActiveRuleParam> activeRuleParams = activeRule.getActiveRuleParams(); if (activeRuleParams != null && !activeRuleParams.isEmpty()) { List<PmdProperty> properties = new ArrayList<PmdProperty>(); for (ActiveRuleParam activeRuleParam : activeRuleParams) { properties.add(new PmdProperty(activeRuleParam.getRuleParam().getKey(), activeRuleParam.getValue())); } rule.setProperties(properties); } ruleset.addRule(rule); processXPathRule(activeRule.getRuleKey(), rule); } } return ruleset; }
@Override public void define(Context context) { NewRepository repository = context .createRepository(DelphiPmdConstants.REPOSITORY_KEY, DelphiLanguage.KEY) .setName(DelphiPmdConstants.REPOSITORY_NAME); List<org.sonar.api.rules.Rule> rules = DelphiRulesUtils.getInitialReferential(); // TODO Review // https://github.com/SonarCommunity/sonar-pmd/blob/master/src/main/java/org/sonar/plugins/pmd/PmdRulesDefinition.java for (org.sonar.api.rules.Rule rule : rules) { NewRule newRule = repository.createRule(rule.getKey()) .setName(rule.getName()) .setHtmlDescription(rule.getDescription()) .setInternalKey(rule.getConfigKey()) .setSeverity(rule.getSeverity().name()); for (RuleParam param : rule.getParams()) { newRule.createParam(param.getKey()) .setDefaultValue(param.getDefaultValue()) .setType(RuleParamType.parse(param.getType())) .setDescription(param.getDescription()); } } SqaleXmlLoader.load(repository, "/org/sonar/plugins/delphi/sqale/delphi-model.xml"); repository.done(); }
newRule.setName(ruleName(repository.getKey(), rule)); newRule.setHtmlDescription(ruleDescription(repository.getKey(), rule)); newRule.setInternalKey(rule.getConfigKey()); newRule.setTemplate(rule.isTemplate()); newRule.setSeverity(rule.getSeverity().toString());