@Test public void test() { HtmlRulesDefinition rulesDefinition = new HtmlRulesDefinition(); RulesDefinition.Context context = new RulesDefinition.Context(); rulesDefinition.define(context); RulesDefinition.Repository repository = context.repository("Web"); assertThat(repository.name()).isEqualTo("SonarAnalyzer"); assertThat(repository.language()).isEqualTo("web"); assertThat(repository.rules()).hasSize(CheckClasses.getCheckClasses().size()); RulesDefinition.Rule alertUseRule = repository.rule("IllegalAttributeCheck"); assertThat(alertUseRule).isNotNull(); assertThat(alertUseRule.name()).isEqualTo("Track uses of disallowed attributes"); Set<String> templateRules = repository.rules().stream() .filter(RulesDefinition.Rule::template) .map(RulesDefinition.Rule::key) .collect(Collectors.toSet()); assertThat(templateRules).hasSize(6); assertThat(templateRules).containsOnly("IllegalAttributeCheck", "LibraryDependencyCheck", "ChildElementIllegalCheck", "ChildElementRequiredCheck", "ParentElementIllegalCheck", "ParentElementRequiredCheck"); for (RulesDefinition.Rule rule : repository.rules()) { for (RulesDefinition.Param param : rule.params()) { assertThat(param.description()).as("description for " + param.key()).isNotEmpty(); } } List<RulesDefinition.Rule> activated = repository.rules().stream().filter(RulesDefinition.Rule::activatedByDefault).collect(Collectors.toList()); assertThat(activated).isNotEmpty(); assertThat(activated.size()).isLessThan(CheckClasses.getCheckClasses().size()); }
@Override public void define(Context context) { NewRepository repository = context .createRepository(REPOSITORY_KEY, HtmlConstants.LANGUAGE_KEY) .setName(REPOSITORY_NAME); RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(RESOURCE_BASE_PATH, SonarWayProfile.JSON_PROFILE_PATH); ruleMetadataLoader.addRulesByAnnotatedClass(repository, CheckClasses.getCheckClasses()); for (NewRule rule : repository.rules()) { if (TEMPLATE_RULE_KEYS.contains(rule.key())) { rule.setTemplate(true); } } repository.done(); }
HtmlRulesDefinition implements RulesDefinition { @Override public void define(Context context) { NewRepository repository = context .createRepository(REPOSITORY_KEY, HtmlConstants.LANGUAGE_KEY) .setName(REPOSITORY_NAME); RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(RESOURCE_BASE_PATH, SonarWayProfile.JSON_PROFILE_PATH); ruleMetadataLoader.addRulesByAnnotatedClass(repository, CheckClasses.getCheckClasses()); for (NewRule rule : repository.rules()) { if (TEMPLATE_RULE_KEYS.contains(rule.key())) { rule.setTemplate(true); } } repository.done(); } }
HtmlRulesDefinition implements RulesDefinition { @Override public void define(Context context) { NewRepository repository = context .createRepository(REPOSITORY_KEY, HtmlConstants.LANGUAGE_KEY) .setName(REPOSITORY_NAME); RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(RESOURCE_BASE_PATH, SonarWayProfile.JSON_PROFILE_PATH); ruleMetadataLoader.addRulesByAnnotatedClass(repository, CheckClasses.getCheckClasses()); for (NewRule rule : repository.rules()) { if (TEMPLATE_RULE_KEYS.contains(rule.key())) { rule.setTemplate(true); } } repository.done(); }  }
HtmlRulesDefinition implements RulesDefinition { @Override public void define(Context context) { NewRepository repository = context .createRepository(REPOSITORY_KEY, HtmlConstants.LANGUAGE_KEY) .setName(REPOSITORY_NAME); RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(RESOURCE_BASE_PATH, SonarWayProfile.JSON_PROFILE_PATH); ruleMetadataLoader.addRulesByAnnotatedClass(repository, CheckClasses.getCheckClasses()); for (NewRule rule : repository.rules()) { if (TEMPLATE_RULE_KEYS.contains(rule.key())) { rule.setTemplate(true); } } repository.done(); }  @Override void define(Context context); }
HtmlRulesDefinition implements RulesDefinition { @Override public void define(Context context) { NewRepository repository = context .createRepository(REPOSITORY_KEY, HtmlConstants.LANGUAGE_KEY) .setName(REPOSITORY_NAME); RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(RESOURCE_BASE_PATH, SonarWayProfile.JSON_PROFILE_PATH); ruleMetadataLoader.addRulesByAnnotatedClass(repository, CheckClasses.getCheckClasses()); for (NewRule rule : repository.rules()) { if (TEMPLATE_RULE_KEYS.contains(rule.key())) { rule.setTemplate(true); } } repository.done(); }  @Override void define(Context context); static final String REPOSITORY_KEY; static final String REPOSITORY_NAME; static final String RESOURCE_BASE_PATH; }