o Improved handling of circular parents

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@885106 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-11-28 16:08:32 +00:00
parent f918716071
commit 411fd3c42b
2 changed files with 27 additions and 7 deletions

View File

@ -117,7 +117,7 @@ public class DefaultModelBuilder
return build( request, new LinkedHashSet<String>() );
}
private ModelBuildingResult build( ModelBuildingRequest request, Collection<String> imports )
private ModelBuildingResult build( ModelBuildingRequest request, Collection<String> importIds )
throws ModelBuildingException
{
DefaultModelBuildingResult result = new DefaultModelBuildingResult();
@ -137,6 +137,9 @@ public class DefaultModelBuilder
ModelData resultData = new ModelData( inputModel );
ModelData superData = new ModelData( getSuperModel() );
Collection<String> parentIds = new LinkedHashSet<String>();
parentIds.add( ModelProblemUtils.toId( inputModel ) );
List<ModelData> lineage = new ArrayList<ModelData>();
for ( ModelData currentData = resultData; currentData != null; )
@ -182,6 +185,18 @@ public class DefaultModelBuilder
{
currentData = superData;
}
else if ( !parentIds.add( currentData.getId() ) )
{
String message = "The parents form a cycle: ";
for ( String modelId : parentIds )
{
message += modelId + " -> ";
}
message += currentData.getId();
problems.add( ModelProblem.Severity.FATAL, message, null );
throw new ModelBuildingException( problems.getRootModelId(), problems.getProblems() );
}
}
assembleInheritance( lineage, request, problems );
@ -588,7 +603,7 @@ public class DefaultModelBuilder
}
private void importDependencyManagement( Model model, ModelBuildingRequest request,
DefaultModelProblemCollector problems, Collection<String> imports )
DefaultModelProblemCollector problems, Collection<String> importIds )
{
DependencyManagement depMngt = model.getDependencyManagement();
@ -599,7 +614,7 @@ public class DefaultModelBuilder
String importing = model.getGroupId() + ':' + model.getArtifactId() + ':' + model.getVersion();
imports.add( importing );
importIds.add( importing );
ModelResolver modelResolver = request.getModelResolver();
@ -624,10 +639,10 @@ public class DefaultModelBuilder
String imported = groupId + ':' + artifactId + ':' + version;
if ( imports.contains( imported ) )
if ( importIds.contains( imported ) )
{
String message = "The dependencies of type=pom and with scope=import form a cycle: ";
for ( String modelId : imports )
for ( String modelId : importIds )
{
message += modelId + " -> ";
}
@ -673,7 +688,7 @@ public class DefaultModelBuilder
ModelBuildingResult importResult;
try
{
importResult = build( importRequest, imports );
importResult = build( importRequest, importIds );
}
catch ( ModelBuildingException e )
{
@ -703,7 +718,7 @@ public class DefaultModelBuilder
importMngts.add( importMngt );
}
imports.remove( importing );
importIds.remove( importing );
dependencyManagementImporter.importManagement( model, importMngts, request, problems );
}

View File

@ -86,6 +86,11 @@ class DefaultModelProblemCollector
{
this.sourceModel = source;
this.source = null;
if ( rootModel == null )
{
rootModel = source;
}
}
private String getSource()