String importing = model.getGroupId() + ':' + model.getArtifactId() + ':' + model.getVersion();
importIds.add( importing );
ModelResolver modelResolver = request.getModelResolver();
ModelBuildingRequest importRequest = null;
List<DependencyManagement> importMngts = null;
for ( Iterator<Dependency> it = depMngt.getDependencies().iterator(); it.hasNext(); )
{
Dependency dependency = it.next();
if ( !"pom".equals( dependency.getType() ) || !"import".equals( dependency.getScope() ) )
{
continue;
}
it.remove();
String groupId = dependency.getGroupId();
String artifactId = dependency.getArtifactId();
String version = dependency.getVersion();
if ( groupId == null || groupId.length() <= 0 )
{
problems.add( Severity.ERROR, "'dependencyManagement.dependencies.dependency.groupId' for "
+ dependency.getManagementKey() + " is missing.", dependency.getLocation( "" ), null );
continue;
}
if ( artifactId == null || artifactId.length() <= 0 )
{
problems.add( Severity.ERROR, "'dependencyManagement.dependencies.dependency.artifactId' for "
+ dependency.getManagementKey() + " is missing.", dependency.getLocation( "" ), null );
continue;
}
if ( version == null || version.length() <= 0 )
{
problems.add( Severity.ERROR, "'dependencyManagement.dependencies.dependency.version' for "
+ dependency.getManagementKey() + " is missing.", dependency.getLocation( "" ), null );
continue;
}
String imported = groupId + ':' + artifactId + ':' + version;
if ( importIds.contains( imported ) )
{
String message = "The dependencies of type=pom and with scope=import form a cycle: ";
for ( String modelId : importIds )
{
message += modelId + " -> ";
}
message += imported;
problems.add( Severity.ERROR, message, null, null );
continue;
}
DependencyManagement importMngt =
getCache( request.getModelCache(), groupId, artifactId, version, ModelCacheTag.IMPORT );
if ( importMngt == null )
{
if ( modelResolver == null )
{
throw new IllegalArgumentException( "no model resolver provided, cannot resolve import POM "
+ ModelProblemUtils.toId( groupId, artifactId, version ) + " for POM "
+ ModelProblemUtils.toSourceHint( model ) );
}
ModelSource importSource;
try
{
importSource = modelResolver.resolveModel( groupId, artifactId, version );
}
catch ( UnresolvableModelException e )
{
StringBuilder buffer = new StringBuilder( 256 );
buffer.append( "Non-resolvable import POM" );
if ( !containsCoordinates( e.getMessage(), groupId, artifactId, version ) )
{
buffer.append( " " ).append( ModelProblemUtils.toId( groupId, artifactId, version ) );
}
buffer.append( ": " ).append( e.getMessage() );
problems.add( Severity.ERROR, buffer.toString(), dependency.getLocation( "" ), e );
continue;
}
if ( importRequest == null )
{
importRequest = new DefaultModelBuildingRequest();
importRequest.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
importRequest.setModelCache( request.getModelCache() );
importRequest.setSystemProperties( request.getSystemProperties() );
importRequest.setUserProperties( request.getUserProperties() );
importRequest.setLocationTracking( request.isLocationTracking() );
}
importRequest.setModelSource( importSource );
importRequest.setModelResolver( modelResolver.newCopy() );
ModelBuildingResult importResult;
try
{
importResult = build( importRequest, importIds );