@Test void should_deal_with_unsupported_property() { Reader reader = read("/org/sonar/plugins/pmd/simple.xml"); RulesProfile profile = importer.importProfile(reader, messages); ActiveRule check = profile.getActiveRuleByConfigKey("pmd", "rulesets/java/coupling.xml/CouplingBetweenObjects"); assertThat(check.getParameter("threshold")).isNull(); assertThat(messages.getWarnings()).hasSize(2); }
@Override public RulesProfile importProfile(Reader pmdConfigurationFile, ValidationMessages messages) { PmdRuleSet pmdRuleset = PmdRuleSets.from(pmdConfigurationFile, messages); RulesProfile profile = RulesProfile.create(); for (PmdRule pmdRule : pmdRuleset.getPmdRules()) { String ruleClassName = pmdRule.getClazz(); if (PmdConstants.XPATH_CLASS.equals(ruleClassName)) { messages.addWarningText("PMD XPath rule '" + pmdRule.getName() + "' can't be imported automatically. The rule must be created manually through the SonarQube web interface."); } else { String ruleRef = pmdRule.getRef(); if (ruleRef == null) { messages.addWarningText("A PMD rule without 'ref' attribute can't be imported. see '" + ruleClassName + "'"); } else { Rule rule = ruleFinder.find(RuleQuery.create().withRepositoryKey(PmdConstants.REPOSITORY_KEY).withConfigKey(ruleRef)); if (rule != null) { ActiveRule activeRule = profile.activateRule(rule, PmdLevelUtils.fromLevel(pmdRule.getPriority())); setParameters(activeRule, pmdRule, rule, messages); } else { messages.addWarningText("Unable to import unknown PMD rule '" + ruleRef + "'"); } } } } return profile; }
PmdProfileImporter extends ProfileImporter { @Override public RulesProfile importProfile(Reader pmdConfigurationFile, ValidationMessages messages) { PmdRuleSet pmdRuleset = PmdRuleSets.from(pmdConfigurationFile, messages); RulesProfile profile = RulesProfile.create(); for (PmdRule pmdRule : pmdRuleset.getPmdRules()) { String ruleClassName = pmdRule.getClazz(); if (PmdConstants.XPATH_CLASS.equals(ruleClassName)) { messages.addWarningText("PMD XPath rule '" + pmdRule.getName() + "' can't be imported automatically. The rule must be created manually through the SonarQube web interface."); } else { String ruleRef = pmdRule.getRef(); if (ruleRef == null) { messages.addWarningText("A PMD rule without 'ref' attribute can't be imported. see '" + ruleClassName + "'"); } else { Rule rule = ruleFinder.find(RuleQuery.create().withRepositoryKey(PmdConstants.REPOSITORY_KEY).withConfigKey(ruleRef)); if (rule != null) { ActiveRule activeRule = profile.activateRule(rule, PmdLevelUtils.fromLevel(pmdRule.getPriority())); setParameters(activeRule, pmdRule, rule, messages); } else { messages.addWarningText("Unable to import unknown PMD rule '" + ruleRef + "'"); } } } } return profile; } }
PmdProfileImporter extends ProfileImporter { @Override public RulesProfile importProfile(Reader pmdConfigurationFile, ValidationMessages messages) { PmdRuleSet pmdRuleset = PmdRuleSets.from(pmdConfigurationFile, messages); RulesProfile profile = RulesProfile.create(); for (PmdRule pmdRule : pmdRuleset.getPmdRules()) { String ruleClassName = pmdRule.getClazz(); if (PmdConstants.XPATH_CLASS.equals(ruleClassName)) { messages.addWarningText("PMD XPath rule '" + pmdRule.getName() + "' can't be imported automatically. The rule must be created manually through the SonarQube web interface."); } else { String ruleRef = pmdRule.getRef(); if (ruleRef == null) { messages.addWarningText("A PMD rule without 'ref' attribute can't be imported. see '" + ruleClassName + "'"); } else { Rule rule = ruleFinder.find(RuleQuery.create().withRepositoryKey(PmdConstants.REPOSITORY_KEY).withConfigKey(ruleRef)); if (rule != null) { ActiveRule activeRule = profile.activateRule(rule, PmdLevelUtils.fromLevel(pmdRule.getPriority())); setParameters(activeRule, pmdRule, rule, messages); } else { messages.addWarningText("Unable to import unknown PMD rule '" + ruleRef + "'"); } } } } return profile; } PmdProfileImporter(RuleFinder ruleFinder); }
PmdProfileImporter extends ProfileImporter { @Override public RulesProfile importProfile(Reader pmdConfigurationFile, ValidationMessages messages) { PmdRuleSet pmdRuleset = PmdRuleSets.from(pmdConfigurationFile, messages); RulesProfile profile = RulesProfile.create(); for (PmdRule pmdRule : pmdRuleset.getPmdRules()) { String ruleClassName = pmdRule.getClazz(); if (PmdConstants.XPATH_CLASS.equals(ruleClassName)) { messages.addWarningText("PMD XPath rule '" + pmdRule.getName() + "' can't be imported automatically. The rule must be created manually through the SonarQube web interface."); } else { String ruleRef = pmdRule.getRef(); if (ruleRef == null) { messages.addWarningText("A PMD rule without 'ref' attribute can't be imported. see '" + ruleClassName + "'"); } else { Rule rule = ruleFinder.find(RuleQuery.create().withRepositoryKey(PmdConstants.REPOSITORY_KEY).withConfigKey(ruleRef)); if (rule != null) { ActiveRule activeRule = profile.activateRule(rule, PmdLevelUtils.fromLevel(pmdRule.getPriority())); setParameters(activeRule, pmdRule, rule, messages); } else { messages.addWarningText("Unable to import unknown PMD rule '" + ruleRef + "'"); } } } } return profile; } PmdProfileImporter(RuleFinder ruleFinder); @Override RulesProfile importProfile(Reader pmdConfigurationFile, ValidationMessages messages); }
PmdProfileImporter extends ProfileImporter { @Override public RulesProfile importProfile(Reader pmdConfigurationFile, ValidationMessages messages) { PmdRuleSet pmdRuleset = PmdRuleSets.from(pmdConfigurationFile, messages); RulesProfile profile = RulesProfile.create(); for (PmdRule pmdRule : pmdRuleset.getPmdRules()) { String ruleClassName = pmdRule.getClazz(); if (PmdConstants.XPATH_CLASS.equals(ruleClassName)) { messages.addWarningText("PMD XPath rule '" + pmdRule.getName() + "' can't be imported automatically. The rule must be created manually through the SonarQube web interface."); } else { String ruleRef = pmdRule.getRef(); if (ruleRef == null) { messages.addWarningText("A PMD rule without 'ref' attribute can't be imported. see '" + ruleClassName + "'"); } else { Rule rule = ruleFinder.find(RuleQuery.create().withRepositoryKey(PmdConstants.REPOSITORY_KEY).withConfigKey(ruleRef)); if (rule != null) { ActiveRule activeRule = profile.activateRule(rule, PmdLevelUtils.fromLevel(pmdRule.getPriority())); setParameters(activeRule, pmdRule, rule, messages); } else { messages.addWarningText("Unable to import unknown PMD rule '" + ruleRef + "'"); } } } } return profile; } PmdProfileImporter(RuleFinder ruleFinder); @Override RulesProfile importProfile(Reader pmdConfigurationFile, ValidationMessages messages);  }