mirror of https://github.com/apache/maven.git
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:
parent
3870ab0e60
commit
0299085031
|
@ -22,8 +22,10 @@ package org.apache.maven.model.building;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -108,6 +110,12 @@ public class DefaultModelBuilder
|
|||
|
||||
public ModelBuildingResult build( ModelBuildingRequest request )
|
||||
throws ModelBuildingException
|
||||
{
|
||||
return build( request, new LinkedHashSet<String>() );
|
||||
}
|
||||
|
||||
private ModelBuildingResult build( ModelBuildingRequest request, Collection<String> imports )
|
||||
throws ModelBuildingException
|
||||
{
|
||||
DefaultModelBuildingResult result = new DefaultModelBuildingResult();
|
||||
|
||||
|
@ -212,6 +220,13 @@ public class DefaultModelBuilder
|
|||
|
||||
public ModelBuildingResult build( ModelBuildingRequest request, ModelBuildingResult result )
|
||||
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();
|
||||
|
||||
|
@ -230,7 +245,7 @@ public class DefaultModelBuilder
|
|||
lifecycleBindingsInjector.injectLifecycleBindings( resultModel, request, problems );
|
||||
}
|
||||
|
||||
importDependencyManagement( resultModel, request, problems );
|
||||
importDependencyManagement( resultModel, request, problems, imports );
|
||||
|
||||
dependencyManagementInjector.injectManagement( resultModel, request, problems );
|
||||
|
||||
|
@ -544,7 +559,7 @@ public class DefaultModelBuilder
|
|||
}
|
||||
|
||||
private void importDependencyManagement( Model model, ModelBuildingRequest request,
|
||||
DefaultModelProblemCollector problems )
|
||||
DefaultModelProblemCollector problems, Collection<String> imports )
|
||||
{
|
||||
DependencyManagement depMngt = model.getDependencyManagement();
|
||||
|
||||
|
@ -553,6 +568,10 @@ public class DefaultModelBuilder
|
|||
return;
|
||||
}
|
||||
|
||||
String importing = model.getGroupId() + ':' + model.getArtifactId() + ':' + model.getVersion();
|
||||
|
||||
imports.add( importing );
|
||||
|
||||
ModelResolver modelResolver = request.getModelResolver();
|
||||
|
||||
ModelBuildingRequest importRequest = null;
|
||||
|
@ -574,6 +593,20 @@ public class DefaultModelBuilder
|
|||
String artifactId = dependency.getArtifactId();
|
||||
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 =
|
||||
getCache( request.getModelCache(), groupId, artifactId, version, ModelCacheTag.IMPORT );
|
||||
|
||||
|
@ -610,7 +643,7 @@ public class DefaultModelBuilder
|
|||
ModelBuildingResult importResult;
|
||||
try
|
||||
{
|
||||
importResult = build( importRequest );
|
||||
importResult = build( importRequest, imports );
|
||||
}
|
||||
catch ( ModelBuildingException e )
|
||||
{
|
||||
|
@ -640,6 +673,8 @@ public class DefaultModelBuilder
|
|||
importMngts.add( importMngt );
|
||||
}
|
||||
|
||||
imports.remove( importing );
|
||||
|
||||
dependencyManagementImporter.importManagement( model, importMngts, request, problems );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue