001    package org.apache.maven.project.validation;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *  http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import org.apache.maven.model.InputLocation;
023    import org.apache.maven.model.Model;
024    import org.apache.maven.model.building.DefaultModelBuildingRequest;
025    import org.apache.maven.model.building.ModelBuildingRequest;
026    import org.apache.maven.model.building.ModelProblem;
027    import org.apache.maven.model.building.ModelProblemCollector;
028    import org.apache.maven.model.building.ModelProblem.Severity;
029    import org.codehaus.plexus.component.annotations.Component;
030    import org.codehaus.plexus.component.annotations.Requirement;
031    
032    /**
033     * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
034     */
035    @Component( role = ModelValidator.class )
036    @Deprecated
037    public class DefaultModelValidator
038        implements ModelValidator
039    {
040    
041        @Requirement
042        private org.apache.maven.model.validation.ModelValidator modelValidator;
043    
044        public ModelValidationResult validate( Model model )
045        {
046            ModelValidationResult result = new ModelValidationResult();
047    
048            ModelBuildingRequest request =
049                new DefaultModelBuildingRequest().setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 );
050    
051            SimpleModelProblemCollector problems = new SimpleModelProblemCollector( result );
052    
053            modelValidator.validateEffectiveModel( model, request, problems );
054    
055            return result;
056        }
057    
058        private static class SimpleModelProblemCollector
059            implements ModelProblemCollector
060        {
061    
062            ModelValidationResult result;
063    
064            public SimpleModelProblemCollector( ModelValidationResult result )
065            {
066                this.result = result;
067            }
068    
069            public void add( Severity severity, String message, InputLocation location, Exception cause )
070            {
071                if ( !ModelProblem.Severity.WARNING.equals( severity ) )
072                {
073                    result.addMessage( message );
074                }
075            }
076    
077        }
078    
079    }