Java Code Examples for org.sonar.api.server.rule.RulesDefinition#NewExtendedRepository

The following examples show how to use org.sonar.api.server.rule.RulesDefinition#NewExtendedRepository . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RulesLoader.java    From AEM-Rules-for-SonarQube with Apache License 2.0 6 votes vote down vote up
private RulesDefinition.NewRule createRule(RulesDefinition.NewExtendedRepository repo, Class clazz, Rule ruleAnnotation) {
    String ruleKey = StringUtils.defaultIfEmpty(ruleAnnotation.key(), clazz.getCanonicalName());
    String ruleName = StringUtils.defaultIfEmpty(ruleAnnotation.name(), null);
    String description = StringUtils.defaultIfEmpty(loadDescription(ruleKey), "No description yet.");

    RulesDefinition.NewRule rule = repo.createRule(ruleKey);
    rule.setName(ruleName).setMarkdownDescription(description);
    rule.setSeverity(ruleAnnotation.priority().name());
    rule.setStatus(RuleStatus.valueOf(ruleAnnotation.status()));
    rule.setTags(ruleAnnotation.tags());

    setMetadata(rule, clazz);

    List<Field> fields = FieldUtils2.getFields(clazz, true);
    for (Field field : fields) {
        loadParameters(rule, field);
    }

    return rule;
}
 
Example 2
Source File: RulesLoader.java    From AEM-Rules-for-SonarQube with Apache License 2.0 4 votes vote down vote up
public <T> void load(RulesDefinition.NewExtendedRepository repo, List<Class<? extends T>> annotatedClasses) {
    for (Class annotatedClass : annotatedClasses) {
        loadRule(repo, annotatedClass);
    }
}
 
Example 3
Source File: RulesLoader.java    From AEM-Rules-for-SonarQube with Apache License 2.0 4 votes vote down vote up
@CheckForNull
private RulesDefinition.NewRule loadRule(RulesDefinition.NewExtendedRepository repo, Class clazz) {
    return Optional.ofNullable(AnnotationUtils.getAnnotation(clazz, Rule.class))
        .map(annotationRule -> createRule(repo, clazz, annotationRule))
        .orElse(null);
}