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 java.util.List; 023 import org.apache.maven.model.InputLocation; 024 import org.apache.maven.model.Model; 025 import org.apache.maven.model.building.DefaultModelBuildingRequest; 026 import org.apache.maven.model.building.ModelBuildingRequest; 027 import org.apache.maven.model.building.ModelProblem; 028 import org.apache.maven.model.building.ModelProblemCollector; 029 import org.apache.maven.model.building.ModelProblem.Severity; 030 import org.apache.maven.model.building.ModelProblem.Version; 031 import org.apache.maven.model.building.ModelProblemCollectorRequest; 032 import org.codehaus.plexus.component.annotations.Component; 033 import org.codehaus.plexus.component.annotations.Requirement; 034 035 /** 036 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a> 037 */ 038 @Component( role = ModelValidator.class ) 039 @Deprecated 040 public class DefaultModelValidator 041 implements ModelValidator 042 { 043 044 @Requirement 045 private org.apache.maven.model.validation.ModelValidator modelValidator; 046 047 public ModelValidationResult validate( Model model ) 048 { 049 ModelValidationResult result = new ModelValidationResult(); 050 051 ModelBuildingRequest request = 052 new DefaultModelBuildingRequest().setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 ); 053 054 SimpleModelProblemCollector problems = new SimpleModelProblemCollector( result ); 055 056 modelValidator.validateEffectiveModel( model, request, problems ); 057 058 return result; 059 } 060 061 private static class SimpleModelProblemCollector 062 implements ModelProblemCollector 063 { 064 065 ModelValidationResult result; 066 067 public SimpleModelProblemCollector( ModelValidationResult result ) 068 { 069 this.result = result; 070 } 071 072 public void add( ModelProblemCollectorRequest req ) 073 { 074 if ( !ModelProblem.Severity.WARNING.equals( req.getSeverity() ) ) 075 { 076 result.addMessage( req.getMessage() ); 077 } 078 } 079 } 080 }