@Test public void test() { PmdRulesDefinition definition = new PmdRulesDefinition(); RulesDefinition.Context context = new RulesDefinition.Context(); definition.define(context); RulesDefinition.Repository repository = context.repository(PmdConstants.REPOSITORY_KEY); assertThat(repository.name()).isEqualTo(PmdConstants.REPOSITORY_NAME); assertThat(repository.language()).isEqualTo(Java.KEY); List<Rule> rules = repository.rules(); for (Rule rule : rules) { assertThat(rule.key()).isNotNull(); assertThat(rule.internalKey()).isNotNull(); assertThat(rule.name()).isNotNull(); assertThat(rule.htmlDescription()).isNotNull(); assertThat(rule.severity()).isNotNull(); for (Param param : rule.params()) { assertThat(param.name()).isNotNull(); assertThat(param.description()) .overridingErrorMessage("Description is not set for parameter '" + param.name() + "' of rule '" + rule.key()) .isNotNull(); } if (!"XPathRule".equals(rule.key())) { assertThat(rule.debtRemediationFunction()) .overridingErrorMessage("Sqale remediation function is not set for rule '" + rule.key()) .isNotNull(); assertThat(rule.debtSubCharacteristic()) .overridingErrorMessage("Sqale characteristic is not set for rule '" + rule.key()) .isNotNull(); } } }
@Override public void define(Context context) { NewRepository repository = context .createRepository(PmdConstants.REPOSITORY_KEY, Java.KEY) .setName(PmdConstants.REPOSITORY_NAME); extractRulesData(repository, "/org/sonar/plugins/pmd/rules.xml", "/org/sonar/l10n/pmd/rules/pmd"); extractRulesData(repository, "/org/sonar/plugins/pmd/rules-p3c.xml", "/org/sonar/l10n/pmd/rules/pmd-p3c"); repository.done(); NewRepository xmlRepository = context .createRepository(PmdConstants.XML_REPOSITORY_KEY, Xml.KEY) .setName(PmdConstants.XML_REPOSITORY_NAME); extractRulesData(xmlRepository, "/org/sonar/plugins/pmd/rules-xml.xml", "/org/sonar/l10n/pmd/rules/pmd-xml"); xmlRepository.done(); }
PmdRulesDefinition implements RulesDefinition { @Override public void define(Context context) { NewRepository repository = context .createRepository(PmdConstants.REPOSITORY_KEY, Java.KEY) .setName(PmdConstants.REPOSITORY_NAME); extractRulesData(repository, "/org/sonar/plugins/pmd/rules.xml", "/org/sonar/l10n/pmd/rules/pmd"); extractRulesData(repository, "/org/sonar/plugins/pmd/rules-p3c.xml", "/org/sonar/l10n/pmd/rules/pmd-p3c"); repository.done(); NewRepository xmlRepository = context .createRepository(PmdConstants.XML_REPOSITORY_KEY, Xml.KEY) .setName(PmdConstants.XML_REPOSITORY_NAME); extractRulesData(xmlRepository, "/org/sonar/plugins/pmd/rules-xml.xml", "/org/sonar/l10n/pmd/rules/pmd-xml"); xmlRepository.done(); } }
PmdRulesDefinition implements RulesDefinition { @Override public void define(Context context) { NewRepository repository = context .createRepository(PmdConstants.REPOSITORY_KEY, Java.KEY) .setName(PmdConstants.REPOSITORY_NAME); extractRulesData(repository, "/org/sonar/plugins/pmd/rules.xml", "/org/sonar/l10n/pmd/rules/pmd"); extractRulesData(repository, "/org/sonar/plugins/pmd/rules-p3c.xml", "/org/sonar/l10n/pmd/rules/pmd-p3c"); repository.done(); NewRepository xmlRepository = context .createRepository(PmdConstants.XML_REPOSITORY_KEY, Xml.KEY) .setName(PmdConstants.XML_REPOSITORY_NAME); extractRulesData(xmlRepository, "/org/sonar/plugins/pmd/rules-xml.xml", "/org/sonar/l10n/pmd/rules/pmd-xml"); xmlRepository.done(); } PmdRulesDefinition(); }
PmdRulesDefinition implements RulesDefinition { @Override public void define(Context context) { NewRepository repository = context .createRepository(PmdConstants.REPOSITORY_KEY, Java.KEY) .setName(PmdConstants.REPOSITORY_NAME); extractRulesData(repository, "/org/sonar/plugins/pmd/rules.xml", "/org/sonar/l10n/pmd/rules/pmd"); extractRulesData(repository, "/org/sonar/plugins/pmd/rules-p3c.xml", "/org/sonar/l10n/pmd/rules/pmd-p3c"); repository.done(); NewRepository xmlRepository = context .createRepository(PmdConstants.XML_REPOSITORY_KEY, Xml.KEY) .setName(PmdConstants.XML_REPOSITORY_NAME); extractRulesData(xmlRepository, "/org/sonar/plugins/pmd/rules-xml.xml", "/org/sonar/l10n/pmd/rules/pmd-xml"); xmlRepository.done(); } PmdRulesDefinition(); @Override void define(Context context); }
PmdRulesDefinition implements RulesDefinition { @Override public void define(Context context) { NewRepository repository = context .createRepository(PmdConstants.REPOSITORY_KEY, Java.KEY) .setName(PmdConstants.REPOSITORY_NAME); extractRulesData(repository, "/org/sonar/plugins/pmd/rules.xml", "/org/sonar/l10n/pmd/rules/pmd"); extractRulesData(repository, "/org/sonar/plugins/pmd/rules-p3c.xml", "/org/sonar/l10n/pmd/rules/pmd-p3c"); repository.done(); NewRepository xmlRepository = context .createRepository(PmdConstants.XML_REPOSITORY_KEY, Xml.KEY) .setName(PmdConstants.XML_REPOSITORY_NAME); extractRulesData(xmlRepository, "/org/sonar/plugins/pmd/rules-xml.xml", "/org/sonar/l10n/pmd/rules/pmd-xml"); xmlRepository.done(); } PmdRulesDefinition(); @Override void define(Context context);  }