diff options
Diffstat (limited to 'plugins/sonar-pmd-plugin')
3 files changed, 11 insertions, 11 deletions
diff --git a/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdRuleRepository.java b/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdRuleRepository.java index 19214409b08..04fe1fdfe76 100644 --- a/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdRuleRepository.java +++ b/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdRuleRepository.java @@ -19,6 +19,7 @@ */ package org.sonar.plugins.pmd; +import com.google.common.collect.Lists; import org.sonar.api.platform.ServerFileSystem; import org.sonar.api.resources.Java; import org.sonar.api.rules.Rule; @@ -26,26 +27,27 @@ import org.sonar.api.rules.RuleRepository; import org.sonar.api.rules.XMLRuleParser; import java.io.File; -import java.util.ArrayList; import java.util.List; public final class PmdRuleRepository extends RuleRepository { // for user extensions private ServerFileSystem fileSystem; + private XMLRuleParser xmlRuleParser; - public PmdRuleRepository(ServerFileSystem fileSystem) { + public PmdRuleRepository(ServerFileSystem fileSystem, XMLRuleParser xmlRuleParser) { super(PmdConstants.REPOSITORY_KEY, Java.KEY); setName(PmdConstants.REPOSITORY_NAME); this.fileSystem = fileSystem; + this.xmlRuleParser = xmlRuleParser; } @Override public List<Rule> createRules() { - List<Rule> rules = new ArrayList<Rule>(); - rules.addAll(XMLRuleParser.parseXML(getClass().getResourceAsStream("/org/sonar/plugins/pmd/rules.xml"))); + List<Rule> rules = Lists.newArrayList(); + rules.addAll(xmlRuleParser.parse(getClass().getResourceAsStream("/org/sonar/plugins/pmd/rules.xml"))); for (File userExtensionXml : fileSystem.getExtensions(PmdConstants.REPOSITORY_KEY, "xml")) { - rules.addAll(XMLRuleParser.parseXML(userExtensionXml)); + rules.addAll(xmlRuleParser.parse(userExtensionXml)); } return rules; } diff --git a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileExporterTest.java b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileExporterTest.java index d6189e13196..438bb9d3c4d 100644 --- a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileExporterTest.java +++ b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileExporterTest.java @@ -17,10 +17,7 @@ import org.apache.commons.lang.StringUtils; import org.junit.Test; import org.sonar.api.platform.ServerFileSystem; import org.sonar.api.profiles.RulesProfile; -import org.sonar.api.rules.ActiveRule; -import org.sonar.api.rules.Rule; -import org.sonar.api.rules.RuleFinder; -import org.sonar.api.rules.RuleQuery; +import org.sonar.api.rules.*; import org.sonar.api.utils.ValidationMessages; import org.sonar.plugins.pmd.xml.PmdProperty; import org.sonar.plugins.pmd.xml.PmdRule; @@ -34,7 +31,7 @@ public class PmdProfileExporterTest { @Test public void testExportProfile() throws IOException, SAXException { ServerFileSystem fileSystem = mock(ServerFileSystem.class); - PmdRuleRepository repository = new PmdRuleRepository(fileSystem); + PmdRuleRepository repository = new PmdRuleRepository(fileSystem, new XMLRuleParser()); List<Rule> rules = repository.createRules(); RuleFinder ruleFinder = new PmdRuleFinder(rules); diff --git a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdRuleRepositoryTest.java b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdRuleRepositoryTest.java index ac55ffc35f9..d726c28564e 100644 --- a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdRuleRepositoryTest.java +++ b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdRuleRepositoryTest.java @@ -28,13 +28,14 @@ import java.util.List; import org.junit.Test; import org.sonar.api.platform.ServerFileSystem; import org.sonar.api.rules.Rule; +import org.sonar.api.rules.XMLRuleParser; public class PmdRuleRepositoryTest { @Test public void testLoadRepositoryFromXml() { ServerFileSystem fileSystem = mock(ServerFileSystem.class); - PmdRuleRepository repository = new PmdRuleRepository(fileSystem); + PmdRuleRepository repository = new PmdRuleRepository(fileSystem, new XMLRuleParser()); List<Rule> rules = repository.createRules(); assertThat(rules.size(), greaterThan(100)); } |