1 package com.mycompany.sonar.checkstyle;
3 import org.apache.commons.io.IOUtils;
4 import org.sonar.api.resources.Java;
5 import org.sonar.api.rules.Rule;
6 import org.sonar.api.rules.RuleRepository;
7 import org.sonar.api.rules.XMLRuleParser;
9 import java.io.InputStream;
10 import java.util.List;
12 public class CheckstyleExtensionRepository extends RuleRepository {
14 // Must be the same than the Checkstyle plugin
15 private static final String REPOSITORY_KEY = "checkstyle";
16 private XMLRuleParser ruleParser;
18 public CheckstyleExtensionRepository(XMLRuleParser ruleParser) {
19 super(REPOSITORY_KEY, Java.KEY);
20 this.ruleParser = ruleParser;
24 public List<Rule> createRules() {
25 // In this example, new rules are declared in a XML file
26 InputStream input = getClass().getResourceAsStream("/com/mycompany/sonar/checkstyle/extensions.xml");
28 return ruleParser.parse(input);
31 IOUtils.closeQuietly(input);