View Javadoc

1   package org.apache.maven.project.validation;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.List;
23  import org.apache.maven.model.InputLocation;
24  import org.apache.maven.model.Model;
25  import org.apache.maven.model.building.DefaultModelBuildingRequest;
26  import org.apache.maven.model.building.ModelBuildingRequest;
27  import org.apache.maven.model.building.ModelProblem;
28  import org.apache.maven.model.building.ModelProblemCollector;
29  import org.apache.maven.model.building.ModelProblem.Severity;
30  import org.apache.maven.model.building.ModelProblem.Version;
31  import org.apache.maven.model.building.ModelProblemCollectorRequest;
32  import org.codehaus.plexus.component.annotations.Component;
33  import org.codehaus.plexus.component.annotations.Requirement;
34  
35  /**
36   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
37   */
38  @Component( role = ModelValidator.class )
39  @Deprecated
40  public class DefaultModelValidator
41      implements ModelValidator
42  {
43  
44      @Requirement
45      private org.apache.maven.model.validation.ModelValidator modelValidator;
46  
47      public ModelValidationResult validate( Model model )
48      {
49          ModelValidationResult result = new ModelValidationResult();
50  
51          ModelBuildingRequest request =
52              new DefaultModelBuildingRequest().setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 );
53  
54          SimpleModelProblemCollector problems = new SimpleModelProblemCollector( result );
55  
56          modelValidator.validateEffectiveModel( model, request, problems );
57  
58          return result;
59      }
60  
61      private static class SimpleModelProblemCollector
62          implements ModelProblemCollector
63      {
64  
65          ModelValidationResult result;
66  
67          public SimpleModelProblemCollector( ModelValidationResult result )
68          {
69              this.result = result;
70          }
71  
72          public void add( ModelProblemCollectorRequest req )
73          {
74              if ( !ModelProblem.Severity.WARNING.equals( req.getSeverity() ) )
75              {
76                  result.addMessage( req.getMessage() );
77              }
78          }
79      }
80  }