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);
}
}
Aggregations