Search in sources :

Example 1 with ValidationResult

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);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ValidationResult(org.revapi.configuration.ValidationResult) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 2 with ValidationResult

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;
}
Also used : Configurable(org.revapi.configuration.Configurable) ValidationResult(org.revapi.configuration.ValidationResult)

Example 3 with 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;
}
Also used : ValidationResult(org.revapi.configuration.ValidationResult)

Example 4 with ValidationResult

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());
}
Also used : ConfigurationValidator(org.revapi.configuration.ConfigurationValidator) ValidationResult(org.revapi.configuration.ValidationResult) Test(org.junit.Test)

Example 5 with ValidationResult

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());
}
Also used : ConfigurationValidator(org.revapi.configuration.ConfigurationValidator) ValidationResult(org.revapi.configuration.ValidationResult) Test(org.junit.Test)

Aggregations

ValidationResult (org.revapi.configuration.ValidationResult)5 Test (org.junit.Test)2 ConfigurationValidator (org.revapi.configuration.ConfigurationValidator)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 Configurable (org.revapi.configuration.Configurable)1