mirror of https://github.com/apache/maven.git
[MNG-4488] [regression] Parent POMs resolved from repository are validated in strict mode
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@888390 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8433f039d0
commit
ed4f6d1094
|
@ -589,7 +589,20 @@ public class DefaultModelBuilder
|
|||
throw new ModelBuildingException( problems.getRootModelId(), problems.getProblems() );
|
||||
}
|
||||
|
||||
Model parentModel = readModel( modelSource, null, request, problems );
|
||||
ModelBuildingRequest lenientRequest = request;
|
||||
if ( request.getValidationLevel() > ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 )
|
||||
{
|
||||
lenientRequest = new FilterModelBuildingRequest( request )
|
||||
{
|
||||
@Override
|
||||
public int getValidationLevel()
|
||||
{
|
||||
return ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Model parentModel = readModel( modelSource, null, lenientRequest, problems );
|
||||
|
||||
ModelData parentData =
|
||||
new ModelData( parentModel, parent.getGroupId(), parent.getArtifactId(), parent.getVersion() );
|
||||
|
|
|
@ -0,0 +1,215 @@
|
|||
package org.apache.maven.model.building;
|
||||
|
||||
/*
|
||||
* 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 java.io.File;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.maven.model.Profile;
|
||||
import org.apache.maven.model.resolution.ModelResolver;
|
||||
|
||||
/**
|
||||
* A model building request that delegates all methods invocations to another request, meant for easy transformations by
|
||||
* subclassing.
|
||||
*
|
||||
* @author Benjamin Bentmann
|
||||
*/
|
||||
class FilterModelBuildingRequest
|
||||
implements ModelBuildingRequest
|
||||
{
|
||||
|
||||
protected ModelBuildingRequest request;
|
||||
|
||||
public FilterModelBuildingRequest( ModelBuildingRequest request )
|
||||
{
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
public File getPomFile()
|
||||
{
|
||||
return request.getPomFile();
|
||||
}
|
||||
|
||||
public FilterModelBuildingRequest setPomFile( File pomFile )
|
||||
{
|
||||
request.setPomFile( pomFile );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModelSource getModelSource()
|
||||
{
|
||||
return request.getModelSource();
|
||||
}
|
||||
|
||||
public FilterModelBuildingRequest setModelSource( ModelSource modelSource )
|
||||
{
|
||||
request.setModelSource( modelSource );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getValidationLevel()
|
||||
{
|
||||
return request.getValidationLevel();
|
||||
}
|
||||
|
||||
public FilterModelBuildingRequest setValidationLevel( int validationLevel )
|
||||
{
|
||||
request.setValidationLevel( validationLevel );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isProcessPlugins()
|
||||
{
|
||||
return request.isProcessPlugins();
|
||||
}
|
||||
|
||||
public FilterModelBuildingRequest setProcessPlugins( boolean processPlugins )
|
||||
{
|
||||
request.setProcessPlugins( processPlugins );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isTwoPhaseBuilding()
|
||||
{
|
||||
return request.isTwoPhaseBuilding();
|
||||
}
|
||||
|
||||
public FilterModelBuildingRequest setTwoPhaseBuilding( boolean twoPhaseBuilding )
|
||||
{
|
||||
request.setTwoPhaseBuilding( twoPhaseBuilding );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<Profile> getProfiles()
|
||||
{
|
||||
return request.getProfiles();
|
||||
}
|
||||
|
||||
public FilterModelBuildingRequest setProfiles( List<Profile> profiles )
|
||||
{
|
||||
request.setProfiles( profiles );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<String> getActiveProfileIds()
|
||||
{
|
||||
return request.getActiveProfileIds();
|
||||
}
|
||||
|
||||
public FilterModelBuildingRequest setActiveProfileIds( List<String> activeProfileIds )
|
||||
{
|
||||
request.setActiveProfileIds( activeProfileIds );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<String> getInactiveProfileIds()
|
||||
{
|
||||
return request.getInactiveProfileIds();
|
||||
}
|
||||
|
||||
public FilterModelBuildingRequest setInactiveProfileIds( List<String> inactiveProfileIds )
|
||||
{
|
||||
request.setInactiveProfileIds( inactiveProfileIds );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Properties getSystemProperties()
|
||||
{
|
||||
return request.getSystemProperties();
|
||||
}
|
||||
|
||||
public FilterModelBuildingRequest setSystemProperties( Properties systemProperties )
|
||||
{
|
||||
request.setSystemProperties( systemProperties );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Properties getUserProperties()
|
||||
{
|
||||
return request.getUserProperties();
|
||||
}
|
||||
|
||||
public FilterModelBuildingRequest setUserProperties( Properties userProperties )
|
||||
{
|
||||
request.setUserProperties( userProperties );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Date getBuildStartTime()
|
||||
{
|
||||
return request.getBuildStartTime();
|
||||
}
|
||||
|
||||
public ModelBuildingRequest setBuildStartTime( Date buildStartTime )
|
||||
{
|
||||
request.setBuildStartTime( buildStartTime );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModelResolver getModelResolver()
|
||||
{
|
||||
return request.getModelResolver();
|
||||
}
|
||||
|
||||
public FilterModelBuildingRequest setModelResolver( ModelResolver modelResolver )
|
||||
{
|
||||
request.setModelResolver( modelResolver );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModelBuildingListener getModelBuildingListener()
|
||||
{
|
||||
return request.getModelBuildingListener();
|
||||
}
|
||||
|
||||
public ModelBuildingRequest setModelBuildingListener( ModelBuildingListener modelBuildingListener )
|
||||
{
|
||||
request.setModelBuildingListener( modelBuildingListener );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModelCache getModelCache()
|
||||
{
|
||||
return request.getModelCache();
|
||||
}
|
||||
|
||||
public FilterModelBuildingRequest setModelCache( ModelCache modelCache )
|
||||
{
|
||||
request.setModelCache( modelCache );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
|
@ -76,6 +76,8 @@ public class DefaultModelValidator
|
|||
|
||||
if ( request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 )
|
||||
{
|
||||
Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
|
||||
|
||||
validateEnum( "modelVersion", problems, Severity.ERROR, model.getModelVersion(), null, "4.0.0" );
|
||||
validateStringNoExpression( "groupId", problems, Severity.WARNING, model.getGroupId() );
|
||||
validateStringNoExpression( "artifactId", problems, Severity.WARNING, model.getArtifactId() );
|
||||
|
@ -99,7 +101,7 @@ public class DefaultModelValidator
|
|||
{
|
||||
if ( !profileIds.add( profile.getId() ) )
|
||||
{
|
||||
addViolation( problems, Severity.ERROR, "profiles.profile.id must be unique"
|
||||
addViolation( problems, errOn30, "profiles.profile.id must be unique"
|
||||
+ " but found duplicate profile with id " + profile.getId() );
|
||||
}
|
||||
|
||||
|
@ -354,6 +356,8 @@ public class DefaultModelValidator
|
|||
private void validateDependencies( ModelProblemCollector problems, List<Dependency> dependencies, String prefix,
|
||||
ModelBuildingRequest request )
|
||||
{
|
||||
Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
|
||||
|
||||
Map<String, Dependency> index = new HashMap<String, Dependency>();
|
||||
|
||||
for ( Dependency dependency : dependencies )
|
||||
|
@ -363,7 +367,7 @@ public class DefaultModelValidator
|
|||
if ( "pom".equals( dependency.getType() ) && "import".equals( dependency.getScope() )
|
||||
&& StringUtils.isNotEmpty( dependency.getClassifier() ) )
|
||||
{
|
||||
addViolation( problems, Severity.ERROR, "'" + prefix + ".classifier' must be empty for imported POM: " + key );
|
||||
addViolation( problems, errOn30, "'" + prefix + ".classifier' must be empty for imported POM: " + key );
|
||||
}
|
||||
else if ( "system".equals( dependency.getScope() ) )
|
||||
{
|
||||
|
@ -379,8 +383,6 @@ public class DefaultModelValidator
|
|||
|
||||
if ( existing != null )
|
||||
{
|
||||
Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
|
||||
|
||||
String msg;
|
||||
if ( equals( existing.getVersion(), dependency.getVersion() ) )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue