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 @Component( role = ModelValidator.class )
36 @Deprecated
37 public class DefaultModelValidator
38 implements ModelValidator
39 {
40
41 @Requirement
42 private org.apache.maven.model.validation.ModelValidator modelValidator;
43
44 public ModelValidationResult validate( Model model )
45 {
46 ModelValidationResult result = new ModelValidationResult();
47
48 ModelBuildingRequest request =
49 new DefaultModelBuildingRequest().setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 );
50
51 SimpleModelProblemCollector problems = new SimpleModelProblemCollector( result );
52
53 modelValidator.validateEffectiveModel( model, request, problems );
54
55 return result;
56 }
57
58 private static class SimpleModelProblemCollector
59 implements ModelProblemCollector
60 {
61
62 ModelValidationResult result;
63
64 public SimpleModelProblemCollector( ModelValidationResult result )
65 {
66 this.result = result;
67 }
68
69 public void add( Severity severity, String message, InputLocation location, Exception cause )
70 {
71 if ( !ModelProblem.Severity.WARNING.equals( severity ) )
72 {
73 result.addMessage( message );
74 }
75 }
76
77 }
78
79 }