List parentSearchRepositories,
Set aggregatedRemoteWagonRepositories,
boolean strict )
throws ProjectBuildingException, InvalidRepositoryException
{
Model originalModel = ModelUtils.cloneModel( model );
File projectDir = null;
if ( projectDescriptor != null )
{
projectDir = projectDescriptor.getAbsoluteFile().getParentFile();
}
ProfileManager externalProfileManager = config.getGlobalProfileManager();
ProfileManager profileManager;
if ( externalProfileManager != null )
{
profileManager = new DefaultProfileManager( container, externalProfileManager.getRequestProperties() );
}
else
{
//TODO mkleint - use the (Container, Properties constructor to make system properties embeddable
profileManager = new DefaultProfileManager( container );
}
if ( externalProfileManager != null )
{
profileManager.explicitlyActivate( externalProfileManager.getExplicitlyActivatedIds() );
profileManager.explicitlyDeactivate( externalProfileManager.getExplicitlyDeactivatedIds() );
}
List activeProfiles;
try
{
profileManager.addProfiles( model.getProfiles() );
loadProjectExternalProfiles( profileManager, projectDir );
activeProfiles = injectActiveProfiles( profileManager, model );
}
catch ( ProfileActivationException e )
{
String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
throw new ProjectBuildingException( projectId, "Failed to activate local (project-level) build profiles: " +
e.getMessage(), e );
}
if ( !model.getRepositories().isEmpty() )
{
List respositories = buildArtifactRepositories( model );
for ( Iterator it = respositories.iterator(); it.hasNext(); )
{
ArtifactRepository repository = (ArtifactRepository) it.next();
if ( !aggregatedRemoteWagonRepositories.contains( repository ) )
{
aggregatedRemoteWagonRepositories.add( repository );
}
}
}
MavenProject project = new MavenProject( model );
project.setFile( projectDescriptor );
project.setActiveProfiles( activeProfiles );
project.setOriginalModel( originalModel );
lineage.addFirst( project );
Parent parentModel = model.getParent();
String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
if ( parentModel != null )
{
if ( StringUtils.isEmpty( parentModel.getGroupId() ) )
{
throw new ProjectBuildingException( projectId, "Missing groupId element from parent element" );
}
else if ( StringUtils.isEmpty( parentModel.getArtifactId() ) )
{
throw new ProjectBuildingException( projectId, "Missing artifactId element from parent element" );
}
else if ( parentModel.getGroupId().equals( model.getGroupId() ) &&
parentModel.getArtifactId().equals( model.getArtifactId() ) )
{
throw new ProjectBuildingException( projectId,
"Parent element is a duplicate of " + "the current project " );
}
else if ( StringUtils.isEmpty( parentModel.getVersion() ) )
{
throw new ProjectBuildingException( projectId, "Missing version element from parent element" );
}
// the only way this will have a value is if we find the parent on disk...
File parentDescriptor = null;
model = null;
String parentKey =
createCacheKey( parentModel.getGroupId(), parentModel.getArtifactId(), parentModel.getVersion() );
MavenProject parentProject = (MavenProject) rawProjectCache.get( parentKey );
if ( parentProject != null )
{
model = ModelUtils.cloneModel( parentProject.getOriginalModel() );
parentDescriptor = parentProject.getFile();
}
String parentRelativePath = parentModel.getRelativePath();
// if we can't find a cached model matching the parent spec, then let's try to look on disk using
// <relativePath/>
if ( ( model == null ) && ( projectDir != null ) && StringUtils.isNotEmpty( parentRelativePath ) )
{
parentDescriptor = new File( projectDir, parentRelativePath );
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "Searching for parent-POM: " + parentModel.getId() + " of project: " +
project.getId() + " in relative path: " + parentRelativePath );
}
if ( parentDescriptor.isDirectory() )
{
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "Path specified in <relativePath/> (" + parentRelativePath +
") is a directory. Searching for 'pom.xml' within this directory." );
}
parentDescriptor = new File( parentDescriptor, "pom.xml" );
if ( !parentDescriptor.exists() )
{
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "Parent-POM: " + parentModel.getId() + " for project: " +
project.getId() + " cannot be loaded from relative path: " + parentDescriptor +
"; path does not exist." );
}
}
}
if ( parentDescriptor != null )
{
try
{
parentDescriptor = parentDescriptor.getCanonicalFile();
}
catch ( IOException e )
{
getLogger().debug( "Failed to canonicalize potential parent POM: \'" + parentDescriptor + "\'",
e );
parentDescriptor = null;
}
}
if ( ( parentDescriptor != null ) && parentDescriptor.exists() )
{
Model candidateParent = readModel( projectId, parentDescriptor, strict );
String candidateParentGroupId = candidateParent.getGroupId();
if ( ( candidateParentGroupId == null ) && ( candidateParent.getParent() != null ) )
{
candidateParentGroupId = candidateParent.getParent().getGroupId();
}
String candidateParentVersion = candidateParent.getVersion();
if ( ( candidateParentVersion == null ) && ( candidateParent.getParent() != null ) )
{
candidateParentVersion = candidateParent.getParent().getVersion();
}
if ( parentModel.getGroupId().equals( candidateParentGroupId ) &&
parentModel.getArtifactId().equals( candidateParent.getArtifactId() ) &&
parentModel.getVersion().equals( candidateParentVersion ) )
{
model = candidateParent;
getLogger().debug( "Using parent-POM from the project hierarchy at: \'" +
parentModel.getRelativePath() + "\' for project: " + project.getId() );
}
else
{
getLogger().debug( "Invalid parent-POM referenced by relative path '" +
parentModel.getRelativePath() + "' in parent specification in " + project.getId() + ":" +
"\n Specified: " + parentModel.getId() + "\n Found: " + candidateParent.getId() );
}
}
else if ( getLogger().isDebugEnabled() )
{
getLogger().debug(