1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package io.wcm.devops.conga.tooling.maven.plugin.validation;
21
22 import org.apache.maven.plugin.MojoFailureException;
23
24 import io.wcm.devops.conga.model.reader.ModelReader;
25 import io.wcm.devops.conga.resource.Resource;
26
27
28
29
30
31 public final class ModelValidator<T> implements DefinitionValidator<T> {
32
33 private final String modelName;
34 private final ModelReader<T> modelReader;
35
36
37
38
39
40 public ModelValidator(String modelName, ModelReader<T> modelReader) {
41 this.modelName = modelName;
42 this.modelReader = modelReader;
43 }
44
45 @Override
46 @SuppressWarnings("PMD.PreserveStackTrace")
47 public T validate(Resource resource, String pathForLog) throws MojoFailureException {
48 try {
49 return modelReader.read(resource);
50 }
51 catch (Exception ex) {
52 throw new MojoFailureException(modelName + " definition " + pathForLog + " is invalid:\n" + ex.getMessage());
53 }
54 }
55
56 }