@Test public void test() { SonarRuntime sonarRuntime = SonarRuntimeImpl.forSonarQube(Version.create(7, 3), SonarQubeSide.SERVER); XmlRulesDefinition rulesDefinition = new XmlRulesDefinition(sonarRuntime); RulesDefinition.Context context = new RulesDefinition.Context(); rulesDefinition.define(context); RulesDefinition.Repository repository = context.repository("xml"); assertThat(repository.name()).isEqualTo("SonarAnalyzer"); assertThat(repository.language()).isEqualTo("xml"); assertThat(repository.rules()).hasSize(CheckList.getCheckClasses().size()); RulesDefinition.Rule alertUseRule = repository.rule("IndentCheck"); assertThat(alertUseRule).isNotNull(); assertThat(alertUseRule.name()).isEqualTo("Source code should be indented consistently"); assertThat(repository.rules().stream().filter(Rule::template).map(Rule::key)) .isNotEmpty() .containsOnly("XPathCheck"); for (Rule rule : repository.rules()) { for (RulesDefinition.Param param : rule.params()) { assertThat(param.description()).as("description for " + param.key()).isNotEmpty(); } } }
@Override public void define(Context context) { NewRepository repository = context.createRepository(Xml.REPOSITORY_KEY, Xml.KEY).setName(Xml.REPOSITORY_NAME); RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(Xml.XML_RESOURCE_PATH, Xml.SONAR_WAY_PATH, sonarRuntime); ruleMetadataLoader.addRulesByAnnotatedClass(repository, CheckList.getCheckClasses()); repository.rule("XPathCheck").setTemplate(true); repository.done(); }
XmlRulesDefinition implements RulesDefinition { @Override public void define(Context context) { NewRepository repository = context.createRepository(Xml.REPOSITORY_KEY, Xml.KEY).setName(Xml.REPOSITORY_NAME); RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(Xml.XML_RESOURCE_PATH, Xml.SONAR_WAY_PATH, sonarRuntime); ruleMetadataLoader.addRulesByAnnotatedClass(repository, CheckList.getCheckClasses()); repository.rule("XPathCheck").setTemplate(true); repository.done(); } }
XmlRulesDefinition implements RulesDefinition { @Override public void define(Context context) { NewRepository repository = context.createRepository(Xml.REPOSITORY_KEY, Xml.KEY).setName(Xml.REPOSITORY_NAME); RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(Xml.XML_RESOURCE_PATH, Xml.SONAR_WAY_PATH, sonarRuntime); ruleMetadataLoader.addRulesByAnnotatedClass(repository, CheckList.getCheckClasses()); repository.rule("XPathCheck").setTemplate(true); repository.done(); } XmlRulesDefinition(SonarRuntime sonarRuntime); }
XmlRulesDefinition implements RulesDefinition { @Override public void define(Context context) { NewRepository repository = context.createRepository(Xml.REPOSITORY_KEY, Xml.KEY).setName(Xml.REPOSITORY_NAME); RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(Xml.XML_RESOURCE_PATH, Xml.SONAR_WAY_PATH, sonarRuntime); ruleMetadataLoader.addRulesByAnnotatedClass(repository, CheckList.getCheckClasses()); repository.rule("XPathCheck").setTemplate(true); repository.done(); } XmlRulesDefinition(SonarRuntime sonarRuntime); @Override void define(Context context); }
XmlRulesDefinition implements RulesDefinition { @Override public void define(Context context) { NewRepository repository = context.createRepository(Xml.REPOSITORY_KEY, Xml.KEY).setName(Xml.REPOSITORY_NAME); RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(Xml.XML_RESOURCE_PATH, Xml.SONAR_WAY_PATH, sonarRuntime); ruleMetadataLoader.addRulesByAnnotatedClass(repository, CheckList.getCheckClasses()); repository.rule("XPathCheck").setTemplate(true); repository.done(); } XmlRulesDefinition(SonarRuntime sonarRuntime); @Override void define(Context context);  }