From fc24fe199eb5968ab7adb26fd23f650e4a8f8a9e Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Fri, 8 Oct 2010 15:48:07 +0000 Subject: API: apply the same pattern between rules and profiles API. The extension point to define rules is org.sonar.api.rules.RuleRepository. The classes AnnotationRuleParser and XMLRuleParser are components that can be used but not extended. --- .../org/sonar/plugins/checkstyle/CheckstyleRuleRepository.java | 8 +++++--- .../sonar/plugins/checkstyle/CheckstyleRuleRepositoryTest.java | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'plugins/sonar-checkstyle-plugin/src') diff --git a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleRuleRepository.java b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleRuleRepository.java index ee533a1cffa..02dd0ad885c 100644 --- a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleRuleRepository.java +++ b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleRuleRepository.java @@ -33,19 +33,21 @@ public final class CheckstyleRuleRepository extends RuleRepository { // for user extensions private ServerFileSystem fileSystem; + private XMLRuleParser xmlRuleParser; - public CheckstyleRuleRepository(ServerFileSystem fileSystem) { + public CheckstyleRuleRepository(ServerFileSystem fileSystem, XMLRuleParser xmlRuleParser) { super(CheckstyleConstants.REPOSITORY_KEY, Java.KEY); setName(CheckstyleConstants.REPOSITORY_NAME); this.fileSystem = fileSystem; + this.xmlRuleParser = xmlRuleParser; } @Override public List createRules() { List rules = new ArrayList(); - rules.addAll(XMLRuleParser.parseXML(getClass().getResourceAsStream("/org/sonar/plugins/checkstyle/rules.xml"))); + rules.addAll(xmlRuleParser.parse(getClass().getResourceAsStream("/org/sonar/plugins/checkstyle/rules.xml"))); for (File userExtensionXml : fileSystem.getExtensions(CheckstyleConstants.REPOSITORY_KEY, "xml")) { - rules.addAll(XMLRuleParser.parseXML(userExtensionXml)); + rules.addAll(xmlRuleParser.parse(userExtensionXml)); } return rules; } diff --git a/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleRuleRepositoryTest.java b/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleRuleRepositoryTest.java index 71d29f5c572..a501feb7308 100644 --- a/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleRuleRepositoryTest.java +++ b/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleRuleRepositoryTest.java @@ -22,6 +22,7 @@ package org.sonar.plugins.checkstyle; import org.junit.Test; import org.sonar.api.platform.ServerFileSystem; import org.sonar.api.rules.Rule; +import org.sonar.api.rules.XMLRuleParser; import java.util.List; @@ -34,7 +35,7 @@ public class CheckstyleRuleRepositoryTest { @Test public void loadRepositoryFromXml() { ServerFileSystem fileSystem = mock(ServerFileSystem.class); - CheckstyleRuleRepository repository = new CheckstyleRuleRepository(fileSystem); + CheckstyleRuleRepository repository = new CheckstyleRuleRepository(fileSystem, new XMLRuleParser()); List rules = repository.createRules(); assertThat(rules.size(), greaterThan(100)); } -- cgit v1.2.3