mirror of https://github.com/apache/maven.git
o Moved model validator into o.a.m.model and moved old impl into compat module
o Added method to validate raw POM git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@779289 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
90db120ca1
commit
41e54938d5
|
@ -0,0 +1,51 @@
|
|||
package org.apache.maven.project.validation;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.model.Model;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.component.annotations.Requirement;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
@Component(role = ModelValidator.class )
|
||||
@Deprecated
|
||||
public class DefaultModelValidator
|
||||
implements ModelValidator
|
||||
{
|
||||
|
||||
@Requirement
|
||||
private org.apache.maven.model.validation.ModelValidator modelValidator;
|
||||
|
||||
public ModelValidationResult validate( Model model )
|
||||
{
|
||||
ModelValidationResult result = new ModelValidationResult();
|
||||
|
||||
for ( String message : modelValidator.validateEffectiveModel( model, false ).getMessages() )
|
||||
{
|
||||
result.addMessage( message );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package org.apache.maven.project.validation;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class ModelValidationResult
|
||||
extends org.apache.maven.model.validation.ModelValidationResult
|
||||
{
|
||||
|
||||
}
|
|
@ -27,6 +27,7 @@ import org.apache.maven.model.Model;
|
|||
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
@Deprecated
|
||||
public interface ModelValidator
|
||||
{
|
||||
|
||||
|
@ -34,15 +35,4 @@ public interface ModelValidator
|
|||
|
||||
ModelValidationResult validate( Model model );
|
||||
|
||||
/**
|
||||
* Checks the specified model for missing or invalid values.
|
||||
*
|
||||
* @param model The model to validate, must not be {@code null}.
|
||||
* @param lenient A flag whether validation should be lenient instead of strict. For building of projects, strict
|
||||
* validation should be used to ensure proper building. For the mere retrievel of dependencies during
|
||||
* artifact resolution, lenient validation should be used to account for models of poor quality.
|
||||
* @return The result of the validation, never {@code null}.
|
||||
*/
|
||||
ModelValidationResult validate( Model model, boolean lenient );
|
||||
|
||||
}
|
|
@ -50,10 +50,10 @@ import org.apache.maven.model.plugin.PluginConfigurationExpander;
|
|||
import org.apache.maven.model.profile.ProfileActivationException;
|
||||
import org.apache.maven.model.profile.ProfileInjector;
|
||||
import org.apache.maven.model.profile.ProfileSelector;
|
||||
import org.apache.maven.model.validation.ModelValidationResult;
|
||||
import org.apache.maven.model.validation.ModelValidator;
|
||||
import org.apache.maven.profiles.ProfileManager;
|
||||
import org.apache.maven.project.artifact.ProjectArtifact;
|
||||
import org.apache.maven.project.validation.ModelValidationResult;
|
||||
import org.apache.maven.project.validation.ModelValidator;
|
||||
import org.apache.maven.repository.RepositorySystem;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.component.annotations.Requirement;
|
||||
|
@ -509,7 +509,7 @@ public class DefaultMavenProjectBuilder
|
|||
throws InvalidProjectModelException
|
||||
{
|
||||
// Must validate before artifact construction to make sure dependencies are good
|
||||
ModelValidationResult validationResult = validator.validate( model, lenient );
|
||||
ModelValidationResult validationResult = validator.validateEffectiveModel( model, lenient );
|
||||
|
||||
String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
|
||||
|
||||
|
@ -574,8 +574,6 @@ public class DefaultMavenProjectBuilder
|
|||
{
|
||||
return models;
|
||||
}
|
||||
|
||||
// FIXME: Validate the parent coordinate and throw proper exceptions
|
||||
|
||||
Artifact artifactParent =
|
||||
repositorySystem.createProjectArtifact( parent.getGroupId(), parent.getArtifactId(), parent.getVersion() );
|
||||
|
@ -727,17 +725,23 @@ public class DefaultMavenProjectBuilder
|
|||
private Model readModel( String projectId, File pomFile, boolean strict )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
Model model;
|
||||
|
||||
Map<String, Object> options =
|
||||
Collections.<String, Object> singletonMap( ModelReader.IS_STRICT, Boolean.valueOf( strict ) );
|
||||
try
|
||||
{
|
||||
return modelReader.read( pomFile, options );
|
||||
model = modelReader.read( pomFile, options );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new ProjectBuildingException( projectId, "Failed to read POM for " + projectId + " from " + pomFile
|
||||
+ ": " + e.getMessage(), pomFile, e );
|
||||
}
|
||||
|
||||
validator.validateRawModel( model, !strict );
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
// Super Model Handling
|
||||
|
|
|
@ -22,7 +22,7 @@ package org.apache.maven.project;
|
|||
import java.io.File;
|
||||
|
||||
import org.apache.maven.artifact.InvalidRepositoryException;
|
||||
import org.apache.maven.project.validation.ModelValidationResult;
|
||||
import org.apache.maven.model.validation.ModelValidationResult;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
public class InvalidProjectModelException
|
||||
|
|
|
@ -25,7 +25,7 @@ import java.util.Arrays;
|
|||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
|
||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
||||
import org.apache.maven.project.validation.ModelValidationResult;
|
||||
import org.apache.maven.model.validation.ModelValidationResult;
|
||||
import org.codehaus.plexus.PlexusTestCase;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.validation;
|
||||
package org.apache.maven.model.validation;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
|
@ -22,7 +22,6 @@ package org.apache.maven.project.validation;
|
|||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.DependencyManagement;
|
||||
|
@ -46,12 +45,30 @@ public class DefaultModelValidator
|
|||
{
|
||||
private static final String ID_REGEX = "[A-Za-z0-9_\\-.]+";
|
||||
|
||||
public ModelValidationResult validate( Model model )
|
||||
public ModelValidationResult validateRawModel( Model model, boolean lenient )
|
||||
{
|
||||
return validate( model, false );
|
||||
ModelValidationResult result = new ModelValidationResult();
|
||||
|
||||
Parent parent = model.getParent();
|
||||
if ( parent != null )
|
||||
{
|
||||
validateStringNotEmpty( "parent.groupId", result, parent.getGroupId() );
|
||||
|
||||
validateStringNotEmpty( "parent.artifactId", result, parent.getArtifactId() );
|
||||
|
||||
validateStringNotEmpty( "parent.version", result, parent.getVersion() );
|
||||
|
||||
if ( parent.getGroupId().equals( model.getGroupId() )
|
||||
&& parent.getArtifactId().equals( model.getArtifactId() ) )
|
||||
{
|
||||
result.addMessage( "The parent element cannot have the same ID as the project." );
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public ModelValidationResult validate( Model model, boolean lenient )
|
||||
public ModelValidationResult validateEffectiveModel( Model model, boolean lenient )
|
||||
{
|
||||
ModelValidationResult result = new ModelValidationResult();
|
||||
|
||||
|
@ -92,7 +109,7 @@ public class DefaultModelValidator
|
|||
validateStringNotEmpty( "dependencies.dependency.version", result, d.getVersion(),
|
||||
d.getManagementKey() );
|
||||
|
||||
if ( Artifact.SCOPE_SYSTEM.equals( d.getScope() ) )
|
||||
if ( "system".equals( d.getScope() ) )
|
||||
{
|
||||
String systemPath = d.getSystemPath();
|
||||
|
||||
|
@ -127,7 +144,7 @@ public class DefaultModelValidator
|
|||
validateSubElementStringNotEmpty( d, "dependencyManagement.dependencies.dependency.groupId", result,
|
||||
d.getGroupId() );
|
||||
|
||||
if ( Artifact.SCOPE_SYSTEM.equals( d.getScope() ) )
|
||||
if ( "system".equals( d.getScope() ) )
|
||||
{
|
||||
String systemPath = d.getSystemPath();
|
||||
|
||||
|
@ -367,4 +384,5 @@ public class DefaultModelValidator
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.validation;
|
||||
package org.apache.maven.model.validation;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
|
@ -47,7 +47,7 @@ public class ModelValidationResult
|
|||
|
||||
public String getMessage( int i )
|
||||
{
|
||||
return messages.get( i ).toString();
|
||||
return messages.get( i );
|
||||
}
|
||||
|
||||
public List<String> getMessages()
|
|
@ -0,0 +1,57 @@
|
|||
package org.apache.maven.model.validation;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.model.Model;
|
||||
|
||||
/**
|
||||
* Checks the model for missing or invalid values.
|
||||
*
|
||||
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface ModelValidator
|
||||
{
|
||||
|
||||
/**
|
||||
* Checks the specified (raw) model for missing or invalid values. The raw model is directly created from the POM
|
||||
* file and has not been subjected to inheritance, interpolation or profile/default injection.
|
||||
*
|
||||
* @param model The model to validate, must not be {@code null}.
|
||||
* @param lenient A flag whether validation should be lenient instead of strict. For building of projects, strict
|
||||
* validation should be used to ensure proper building. For the mere retrievel of dependencies during
|
||||
* artifact resolution, lenient validation should be used to account for models of poor quality.
|
||||
* @return The result of the validation, never {@code null}.
|
||||
*/
|
||||
ModelValidationResult validateRawModel( Model model, boolean lenient );
|
||||
|
||||
/**
|
||||
* Checks the specified (effective) model for missing or invalid values. The effective model is fully assembled and
|
||||
* has undergone inheritance, interpolation and other model operations.
|
||||
*
|
||||
* @param model The model to validate, must not be {@code null}.
|
||||
* @param lenient A flag whether validation should be lenient instead of strict. For building of projects, strict
|
||||
* validation should be used to ensure proper building. For the mere retrievel of dependencies during
|
||||
* artifact resolution, lenient validation should be used to account for models of poor quality.
|
||||
* @return The result of the validation, never {@code null}.
|
||||
*/
|
||||
ModelValidationResult validateEffectiveModel( Model model, boolean lenient );
|
||||
|
||||
}
|
Loading…
Reference in New Issue