1 package org.apache.maven.project.validation;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.model.InputLocation;
23 import org.apache.maven.model.Model;
24 import org.apache.maven.model.building.DefaultModelBuildingRequest;
25 import org.apache.maven.model.building.ModelBuildingRequest;
26 import org.apache.maven.model.building.ModelProblem;
27 import org.apache.maven.model.building.ModelProblemCollector;
28 import org.apache.maven.model.building.ModelProblem.Severity;
29 import org.codehaus.plexus.component.annotations.Component;
30 import org.codehaus.plexus.component.annotations.Requirement;
31
32
33
34
35
36 @Component( role = ModelValidator.class )
37 @Deprecated
38 public class DefaultModelValidator
39 implements ModelValidator
40 {
41
42 @Requirement
43 private org.apache.maven.model.validation.ModelValidator modelValidator;
44
45 public ModelValidationResult validate( Model model )
46 {
47 ModelValidationResult result = new ModelValidationResult();
48
49 ModelBuildingRequest request =
50 new DefaultModelBuildingRequest().setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 );
51
52 SimpleModelProblemCollector problems = new SimpleModelProblemCollector( result );
53
54 modelValidator.validateEffectiveModel( model, request, problems );
55
56 return result;
57 }
58
59 private static class SimpleModelProblemCollector
60 implements ModelProblemCollector
61 {
62
63 ModelValidationResult result;
64
65 public SimpleModelProblemCollector( ModelValidationResult result )
66 {
67 this.result = result;
68 }
69
70 public void add( Severity severity, String message, InputLocation location, Exception cause )
71 {
72 if ( !ModelProblem.Severity.WARNING.equals( severity ) )
73 {
74 result.addMessage( message );
75 }
76 }
77
78 }
79
80 }