aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-checkstyle-plugin/src
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-10-08 15:48:07 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-10-08 15:48:07 +0000
commitfc24fe199eb5968ab7adb26fd23f650e4a8f8a9e (patch)
tree59332c8e45a7b6184cc602756c6c193898e62d94 /plugins/sonar-checkstyle-plugin/src
parent7ca495d67492c6b3dbb653102e345f8fc43f09ae (diff)
downloadsonarqube-fc24fe199eb5968ab7adb26fd23f650e4a8f8a9e.tar.gz
sonarqube-fc24fe199eb5968ab7adb26fd23f650e4a8f8a9e.zip
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.
Diffstat (limited to 'plugins/sonar-checkstyle-plugin/src')
-rw-r--r--plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleRuleRepository.java8
-rw-r--r--plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleRuleRepositoryTest.java3
2 files changed, 7 insertions, 4 deletions
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<Rule> createRules() {
List<Rule> rules = new ArrayList<Rule>();
- 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<Rule> rules = repository.createRules();
assertThat(rules.size(), greaterThan(100));
}