use of org.revapi.configuration.ValidationResult in project revapi by revapi.
the class ValidateConfigurationMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
Analyzer analyzer = prepareAnalyzer(project, SimpleReporter.class, Collections.emptyMap());
try {
if (analyzer != null) {
ValidationResult res = analyzer.validateConfiguration();
if (!res.isSuccessful()) {
String errors = res.getErrors() == null ? "" : Stream.of(res.getErrors()).map(e -> e.message + " @ " + e.dataPath).collect(Collectors.joining(", ", "Errors: ", ""));
String missingSchemas = res.getMissingSchemas() == null ? "" : Stream.of(res.getMissingSchemas()).collect(Collectors.joining(", ", "Missing schemas: ", ""));
throw new MojoExecutionException("Failed to validate configuration. " + errors + " " + missingSchemas);
}
}
} catch (MojoExecutionException e) {
throw e;
} catch (Exception e) {
throw new MojoExecutionException("Failed to validate configuration.", e);
}
}
use of org.revapi.configuration.ValidationResult in project revapi by revapi.
the class Revapi method validate.
private ValidationResult validate(@Nonnull AnalysisContext analysisContext, ValidationResult validationResult, Iterator<? extends Configurable> configurables) {
while (configurables.hasNext()) {
Configurable c = configurables.next();
ValidationResult partial = configurationValidator.validate(analysisContext.getConfiguration(), c);
validationResult = validationResult.merge(partial);
}
return validationResult;
}
use of org.revapi.configuration.ValidationResult in project revapi by revapi.
the class Revapi method validateConfiguration.
/**
* Validates the configuration of the analysis context.
*
* @param analysisContext the analysis context
* @return the validation result
*/
public ValidationResult validateConfiguration(@Nonnull AnalysisContext analysisContext) {
ValidationResult validation = ValidationResult.success();
Iterator<? extends Configurable> it = concat(availableApiAnalyzers.stream(), availableFilters.stream(), availableReporters.stream(), availableTransforms.stream()).map(this::instantiate).iterator();
validation = validate(analysisContext, validation, it);
return validation;
}
use of org.revapi.configuration.ValidationResult in project revapi by revapi.
the class ConfigurableElementFilterTest method testInvalidConfig_noFilters.
@Test
public void testInvalidConfig_noFilters() throws Exception {
ConfigurationValidator validator = new ConfigurationValidator();
String json = "[{\"extension\": \"revapi.filter\", \"configuration\" : { }}]";
ValidationResult result = validator.validate(ModelNode.fromJSONString(json), new ConfigurableElementFilter());
Assert.assertFalse(result.isSuccessful());
}
use of org.revapi.configuration.ValidationResult in project revapi by revapi.
the class ConfigurableElementFilterTest method testInvalidConfig_noDefsForFilter.
@Test
public void testInvalidConfig_noDefsForFilter() throws Exception {
ConfigurationValidator validator = new ConfigurationValidator();
String json = "[{\"extension\": \"revapi.filter\", \"configuration\" : { \"elements\" : { \"include\" : [] }}}]";
ValidationResult result = validator.validate(ModelNode.fromJSONString(json), new ConfigurableElementFilter());
Assert.assertFalse(result.isSuccessful());
json = "[{\"extension\": \"revapi.filter\", \"configuration\": { \"elements\" : { \"exclude\" : [] }}}]";
result = validator.validate(ModelNode.fromJSONString(json), new ConfigurableElementFilter());
Assert.assertFalse(result.isSuccessful());
json = "[{\"extension\": \"revapi.filter\", \"configuration\": { \"archives\" : { \"exclude\" : {} }}}]";
result = validator.validate(ModelNode.fromJSONString(json), new ConfigurableElementFilter());
Assert.assertFalse(result.isSuccessful());
}
Aggregations