aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorfmallet <freddy.mallet@gmail.com>2010-09-15 22:01:00 +0000
committerfmallet <freddy.mallet@gmail.com>2010-09-15 22:01:00 +0000
commitf27104c1d98ac616ba1c91c3cfe96e0e495b725a (patch)
tree371c7f3c40eb1629956a91fdfa1002133ba60969 /plugins
parent513e60ec6d331bd8554326425fb3f401eeb6b2a9 (diff)
downloadsonarqube-f27104c1d98ac616ba1c91c3cfe96e0e495b725a.tar.gz
sonarqube-f27104c1d98ac616ba1c91c3cfe96e0e495b725a.zip
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.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-pmd-plugin/pmd-result.xml2
-rw-r--r--plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdProfileImporter.java13
-rw-r--r--plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileImporterTest.java9
3 files changed, 23 insertions, 1 deletions
diff --git a/plugins/sonar-pmd-plugin/pmd-result.xml b/plugins/sonar-pmd-plugin/pmd-result.xml
index f5ba165ad06..b95ea127b30 100644
--- a/plugins/sonar-pmd-plugin/pmd-result.xml
+++ b/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> \ No newline at end of file
diff --git a/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdProfileImporter.java b/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdProfileImporter.java
index 21f3968d9ea..85ad6321f71 100644
--- a/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdProfileImporter.java
+++ b/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);
diff --git a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileImporterTest.java b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileImporterTest.java
index dd2ca319122..fd386c398ab 100644
--- a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileImporterTest.java
+++ b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileImporterTest.java
@@ -75,6 +75,15 @@ public class PmdProfileImporterTest {
}
@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"));
RulesProfile profile = importer.importProfile(reader, messages);