Переглянути джерело

fix SONAR-1766 - A warning is generated when the user tries to import a PMD configuration file with contains XPath rules. Those rules must be defined through the user web interface.

tags/2.6
fmallet 13 роки тому
джерело
коміт
f27104c1d9

+ 1
- 1
plugins/sonar-pmd-plugin/pmd-result.xml Переглянути файл

@@ -1,3 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<pmd version="4.2.5" timestamp="2010-09-15T23:40:19.345">
<pmd version="4.2.5" timestamp="2010-09-15T23:57:48.955">
</pmd>

+ 13
- 0
plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdProfileImporter.java Переглянути файл

@@ -58,6 +58,16 @@ public class PmdProfileImporter extends ProfileImporter {
protected RulesProfile createRuleProfile(PmdRuleset pmdRuleset, ValidationMessages messages) {
RulesProfile profile = RulesProfile.create();
for (PmdRule pmdRule : pmdRuleset.getPmdRules()) {
if (PmdConstants.XPATH_CLASS.equals(pmdRule.getClazz())) {
messages.addWarningText("PMD XPath rule '" + pmdRule.getName()
+ "' can't be imported automatically. The rule must be created manually through the Sonar web interface.");
continue;
}
if (pmdRule.getRef() == null) {
messages.addWarningText("A PMD rule without 'ref' attribute can't be imported. see '" + pmdRule.getClazz()
+ "'");
continue;
}
Rule rule = ruleFinder.find(RuleQuery.create().withRepositoryKey(PmdConstants.REPOSITORY_KEY).withConfigKey(pmdRule.getRef()));
if (rule != null) {
ActiveRule activeRule = profile.activateRule(rule, PmdLevelUtils.fromLevel(pmdRule.getPriority()));
@@ -86,6 +96,9 @@ public class PmdProfileImporter extends ProfileImporter {
PmdRuleset pmdResultset = new PmdRuleset();
for (Element eltRule : getChildren(eltResultset, "rule", namespace)) {
PmdRule pmdRule = new PmdRule(eltRule.getAttributeValue("ref"));
pmdRule.setClazz(eltRule.getAttributeValue("class"));
pmdRule.setName(eltRule.getAttributeValue("name"));
pmdRule.setMessage(eltRule.getAttributeValue("message"));
parsePmdPriority(eltRule, pmdRule, namespace);
parsePmdProperties(eltRule, pmdRule, namespace);
pmdResultset.addRule(pmdRule);

+ 9
- 0
plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileImporterTest.java Переглянути файл

@@ -74,6 +74,15 @@ public class PmdProfileImporterTest {
assertThat(messages.hasErrors(), is(false));
}

@Test
public void testImportingProfileWithXPathRule() {
Reader reader = new StringReader(TestUtils.getResourceContent("/org/sonar/plugins/pmd/export_xpath_rules.xml"));
RulesProfile profile = importer.importProfile(reader, messages);

assertThat(profile.getActiveRules().size(), is(0));
assertThat(messages.hasWarnings(), is(true));
}

@Test
public void testImportingParameters() {
Reader reader = new StringReader(TestUtils.getResourceContent("/org/sonar/plugins/pmd/simple.xml"));

Завантаження…
Відмінити
Зберегти