o Properly reported cycles in the imported models

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@810004 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-09-01 12:36:12 +00:00
parent 3870ab0e60
commit 0299085031
1 changed files with 38 additions and 3 deletions

View File

@ -22,8 +22,10 @@ package org.apache.maven.model.building;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -108,6 +110,12 @@ public class DefaultModelBuilder
public ModelBuildingResult build( ModelBuildingRequest request ) public ModelBuildingResult build( ModelBuildingRequest request )
throws ModelBuildingException throws ModelBuildingException
{
return build( request, new LinkedHashSet<String>() );
}
private ModelBuildingResult build( ModelBuildingRequest request, Collection<String> imports )
throws ModelBuildingException
{ {
DefaultModelBuildingResult result = new DefaultModelBuildingResult(); DefaultModelBuildingResult result = new DefaultModelBuildingResult();
@ -212,6 +220,13 @@ public class DefaultModelBuilder
public ModelBuildingResult build( ModelBuildingRequest request, ModelBuildingResult result ) public ModelBuildingResult build( ModelBuildingRequest request, ModelBuildingResult result )
throws ModelBuildingException throws ModelBuildingException
{
return build( request, result, new LinkedHashSet<String>() );
}
private ModelBuildingResult build( ModelBuildingRequest request, ModelBuildingResult result,
Collection<String> imports )
throws ModelBuildingException
{ {
Model resultModel = result.getEffectiveModel(); Model resultModel = result.getEffectiveModel();
@ -230,7 +245,7 @@ public class DefaultModelBuilder
lifecycleBindingsInjector.injectLifecycleBindings( resultModel, request, problems ); lifecycleBindingsInjector.injectLifecycleBindings( resultModel, request, problems );
} }
importDependencyManagement( resultModel, request, problems ); importDependencyManagement( resultModel, request, problems, imports );
dependencyManagementInjector.injectManagement( resultModel, request, problems ); dependencyManagementInjector.injectManagement( resultModel, request, problems );
@ -544,7 +559,7 @@ public class DefaultModelBuilder
} }
private void importDependencyManagement( Model model, ModelBuildingRequest request, private void importDependencyManagement( Model model, ModelBuildingRequest request,
DefaultModelProblemCollector problems ) DefaultModelProblemCollector problems, Collection<String> imports )
{ {
DependencyManagement depMngt = model.getDependencyManagement(); DependencyManagement depMngt = model.getDependencyManagement();
@ -553,6 +568,10 @@ public class DefaultModelBuilder
return; return;
} }
String importing = model.getGroupId() + ':' + model.getArtifactId() + ':' + model.getVersion();
imports.add( importing );
ModelResolver modelResolver = request.getModelResolver(); ModelResolver modelResolver = request.getModelResolver();
ModelBuildingRequest importRequest = null; ModelBuildingRequest importRequest = null;
@ -574,6 +593,20 @@ public class DefaultModelBuilder
String artifactId = dependency.getArtifactId(); String artifactId = dependency.getArtifactId();
String version = dependency.getVersion(); String version = dependency.getVersion();
String imported = groupId + ':' + artifactId + ':' + version;
if ( imports.contains( imported ) )
{
String message = "The dependencies of type=pom and with scope=import from a cycle: ";
for ( String modelId : imports )
{
message += modelId + " -> ";
}
message += imported;
problems.addError( message );
continue;
}
DependencyManagement importMngt = DependencyManagement importMngt =
getCache( request.getModelCache(), groupId, artifactId, version, ModelCacheTag.IMPORT ); getCache( request.getModelCache(), groupId, artifactId, version, ModelCacheTag.IMPORT );
@ -610,7 +643,7 @@ public class DefaultModelBuilder
ModelBuildingResult importResult; ModelBuildingResult importResult;
try try
{ {
importResult = build( importRequest ); importResult = build( importRequest, imports );
} }
catch ( ModelBuildingException e ) catch ( ModelBuildingException e )
{ {
@ -640,6 +673,8 @@ public class DefaultModelBuilder
importMngts.add( importMngt ); importMngts.add( importMngt );
} }
imports.remove( importing );
dependencyManagementImporter.importManagement( model, importMngts, request, problems ); dependencyManagementImporter.importManagement( model, importMngts, request, problems );
} }