public static void loadHtmlDescriptions(NewRepository repository, String languageKey) { ExternalDescriptionLoader loader = new ExternalDescriptionLoader(repository, languageKey); for (NewRule newRule : repository.rules()) { loader.addHtmlDescription(newRule); } }
@VisibleForTesting static void extractRulesData(NewRepository repository, String xmlRulesFilePath, String htmlDescriptionFolder) throws IOException { final RulesDefinitionXmlLoader ruleLoader = new RulesDefinitionXmlLoader(); try (InputStream resource = CheckstyleRulesDefinition.class .getResourceAsStream(xmlRulesFilePath)) { ruleLoader.load(repository, resource, "UTF-8"); } ExternalDescriptionLoader.loadHtmlDescriptions(repository, htmlDescriptionFolder); try (InputStream resource = CheckstyleRulesDefinition.class .getResourceAsStream("/org/sonar/l10n/checkstyle.properties")) { loadNames(repository, resource); } SqaleXmlLoader.load(repository, "/com/sonar/sqale/checkstyle-model.xml"); }
public void addHtmlDescription(NewRule rule) { URL resource = ExternalDescriptionLoader.class.getResource(resourceBasePath + "/" + rule.key() + ".html"); if (resource != null) { addHtmlDescription(rule, resource); } }
public AnnotationBasedRulesDefinition(NewRepository repository, String languageKey) { this.repository = repository; this.languageKey = languageKey; String externalDescriptionBasePath = String.format("/org/sonar/l10n/%s/rules/%s", languageKey, repository.key()); this.externalDescriptionLoader = new ExternalDescriptionLoader(repository, externalDescriptionBasePath); }
static void extractRulesData(NewRepository repository, String xmlRulesFilePath, String htmlDescriptionFolder) { RulesDefinitionXmlLoader ruleLoader = new RulesDefinitionXmlLoader(); ruleLoader.load(repository, PmdRulesDefinition.class.getResourceAsStream(xmlRulesFilePath), "UTF-8"); ExternalDescriptionLoader.loadHtmlDescriptions(repository, htmlDescriptionFolder); PropertyFileLoader.loadNames(repository, PmdRulesDefinition.class.getResourceAsStream("/org/sonar/l10n/pmd.properties")); SqaleXmlLoader.load(repository, "/com/sonar/sqale/pmd-model.xml"); } }
public void addRuleClasses(boolean failIfSqaleNotFound, boolean failIfNoExplicitKey, Iterable<Class> ruleClasses) { new RulesDefinitionAnnotationLoader().load(repository, Iterables.toArray(ruleClasses, Class.class)); List<NewRule> newRules = Lists.newArrayList(); for (Class<?> ruleClass : ruleClasses) { NewRule rule = newRule(ruleClass, failIfNoExplicitKey); externalDescriptionLoader.addHtmlDescription(rule); rule.setTemplate(AnnotationUtils.getAnnotation(ruleClass, RuleTemplate.class) != null); if (!isSqaleAnnotated(ruleClass) && failIfSqaleNotFound) { throw new IllegalArgumentException("No SqaleSubCharacteristic annotation was found on " + ruleClass); } try { setupSqaleModel(rule, ruleClass); } catch (RuntimeException e) { throw new IllegalArgumentException("Could not setup SQALE model on " + ruleClass, e); } newRules.add(rule); } setupExternalNames(newRules); }