Search in sources :

Example 1 with RuleSet

use of net.sourceforge.pmd.RuleSet in project eclipse-pmd by acanda.

the class AddRuleSetConfigurationModel method validateLocation.

/**
 * Validates the location of the rule set configuration and sets or resets the property {@link #rules} depending on
 * whether {@link #location} contains a valid rule set configuration location or not.
 */
@SuppressWarnings("PMD.AvoidCatchingGenericException")
private void validateLocation(final String propertyName, final ValidationResult result) {
    final Builder<Rule> rules = ImmutableList.builder();
    String ruleSetName = null;
    if (!errorIfBlank(LOCATION, location, "Please enter the location of the rule set configuration", result)) {
        RuleSet ruleSet = null;
        try {
            final String referenceId;
            if (isRemoteTypeSelected) {
                referenceId = validateRemoteLocation(result);
            } else {
                referenceId = validateLocalLocation(result);
            }
            if (referenceId != null) {
                ruleSet = new RuleSetFactory().createRuleSet(referenceId);
                ruleSetName = ruleSet.getName();
                rules.addAll(ruleSet.getRules());
            }
        } catch (final RuleSetNotFoundException | RuntimeException e) {
        // the rule set location is invalid - the validation problem will be added below
        }
        if (ruleSet == null || ruleSet.getRules().isEmpty()) {
            result.add(new ValidationProblem(LOCATION, Severity.ERROR, "The rule set configuration at the given location is invalid"));
        }
    }
    if (LOCATION.equals(propertyName)) {
        setRules(rules.build());
        setName(ruleSetName == null ? "" : ruleSetName);
    }
}
Also used : RuleSetFactory(net.sourceforge.pmd.RuleSetFactory) RuleSet(net.sourceforge.pmd.RuleSet) RuleSetNotFoundException(net.sourceforge.pmd.RuleSetNotFoundException) ValidationProblem(ch.acanda.eclipse.pmd.ui.model.ValidationProblem) Rule(net.sourceforge.pmd.Rule)

Aggregations

ValidationProblem (ch.acanda.eclipse.pmd.ui.model.ValidationProblem)1 Rule (net.sourceforge.pmd.Rule)1 RuleSet (net.sourceforge.pmd.RuleSet)1 RuleSetFactory (net.sourceforge.pmd.RuleSetFactory)1 RuleSetNotFoundException (net.sourceforge.pmd.RuleSetNotFoundException)1