mirror of https://github.com/apache/maven.git
o Improved model validation to ignore super POM for plugin version check
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@930720 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a123fce495
commit
5aa2078ab1
|
@ -30,10 +30,13 @@ import java.util.Map;
|
|||
import java.util.HashMap;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.DependencyManagement;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Parent;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.PluginManagement;
|
||||
import org.apache.maven.model.Profile;
|
||||
import org.apache.maven.model.Repository;
|
||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||
|
@ -219,6 +222,9 @@ public class DefaultModelBuilder
|
|||
}
|
||||
}
|
||||
|
||||
problems.setSource( inputModel );
|
||||
checkPluginVersions( lineage, request, problems );
|
||||
|
||||
assembleInheritance( lineage, request, problems );
|
||||
|
||||
Model resultModel = resultData.getModel();
|
||||
|
@ -444,6 +450,55 @@ public class DefaultModelBuilder
|
|||
}
|
||||
}
|
||||
|
||||
private void checkPluginVersions( List<ModelData> lineage, ModelBuildingRequest request,
|
||||
ModelProblemCollector problems )
|
||||
{
|
||||
if ( request.getValidationLevel() < ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, String> versions = new HashMap<String, String>();
|
||||
Map<String, String> managedVersions = new HashMap<String, String>();
|
||||
|
||||
for ( int i = 0, n = lineage.size() - 1; i < n; i++ )
|
||||
{
|
||||
Model model = lineage.get( i ).getModel();
|
||||
Build build = model.getBuild();
|
||||
if ( build != null )
|
||||
{
|
||||
for ( Plugin plugin : build.getPlugins() )
|
||||
{
|
||||
String key = plugin.getKey();
|
||||
if ( versions.get( key ) == null )
|
||||
{
|
||||
versions.put( key, plugin.getVersion() );
|
||||
}
|
||||
}
|
||||
PluginManagement mngt = build.getPluginManagement();
|
||||
if ( mngt != null )
|
||||
{
|
||||
for ( Plugin plugin : mngt.getPlugins() )
|
||||
{
|
||||
String key = plugin.getKey();
|
||||
if ( managedVersions.get( key ) == null )
|
||||
{
|
||||
managedVersions.put( key, plugin.getVersion() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ( String key : versions.keySet() )
|
||||
{
|
||||
if ( versions.get( key ) == null && managedVersions.get( key ) == null )
|
||||
{
|
||||
problems.add( Severity.WARNING, "'build.plugins.plugin.version' for " + key + " is missing.", null );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void assembleInheritance( List<ModelData> lineage, ModelBuildingRequest request,
|
||||
ModelProblemCollector problems )
|
||||
{
|
||||
|
|
|
@ -671,11 +671,11 @@ public class DefaultModelValidator
|
|||
String sourceHint, ModelBuildingRequest request )
|
||||
{
|
||||
Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
|
||||
Severity errOn31 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 );
|
||||
|
||||
if ( !validateNotNull( fieldName, problems, errOn31, string, sourceHint ) )
|
||||
if ( string == null )
|
||||
{
|
||||
return false;
|
||||
// NOTE: The check for missing plugin versions is handled directly by the model builder
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( string.length() > 0 && !hasExpression( string ) && !"RELEASE".equals( string )
|
||||
|
|
|
@ -273,22 +273,6 @@ public class DefaultModelValidatorTest
|
|||
assertEquals( "'build.plugins.plugin.artifactId' is missing.", result.getErrors().get( 0 ) );
|
||||
}
|
||||
|
||||
public void testMissingPluginVersion()
|
||||
throws Exception
|
||||
{
|
||||
SimpleProblemCollector result =
|
||||
validateEffective( "missing-plugin-version-pom.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 );
|
||||
|
||||
assertViolations( result, 0, 1, 0 );
|
||||
|
||||
assertEquals( "'build.plugins.plugin.version' for org.apache.maven.plugins:maven-it-plugin is missing.",
|
||||
result.getErrors().get( 0 ) );
|
||||
|
||||
result = validateEffective( "missing-plugin-version-pom.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
|
||||
|
||||
assertViolations( result, 0, 0, 1 );
|
||||
}
|
||||
|
||||
public void testEmptyPluginVersion()
|
||||
throws Exception
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue