Fixing a problem where parent POMs that are not found during model-lineage discovery were not previously stubbed out, and caused the build to fail where it didn't in 2.0.7

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@564299 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2007-08-09 17:45:37 +00:00
parent 711eb8c416
commit db3f9be45e
2 changed files with 135 additions and 99 deletions

View File

@ -224,7 +224,7 @@ public class DefaultMavenProjectBuilder
{
ProjectBuildCache projectBuildCache = ProjectBuildCache.read( buildContextManager );
MavenProject project = (MavenProject) projectBuildCache.getCachedProject( artifact );
MavenProject project = projectBuildCache.getCachedProject( artifact );
if ( project != null )
{
@ -280,12 +280,12 @@ public class DefaultMavenProjectBuilder
LinkedHashSet profiles = new LinkedHashSet();
if ( activeProfiles != null && !activeProfiles.isEmpty() )
if ( ( activeProfiles != null ) && !activeProfiles.isEmpty() )
{
profiles.addAll( activeProfiles );
}
if ( activeExternalProfiles != null && !activeExternalProfiles.isEmpty() )
if ( ( activeExternalProfiles != null ) && !activeExternalProfiles.isEmpty() )
{
profiles.addAll( activeExternalProfiles );
}
@ -408,7 +408,7 @@ public class DefaultMavenProjectBuilder
{
Map map = null;
List deps;
if ( dependencyManagement != null && (deps = dependencyManagement.getDependencies()) != null && deps.size() > 0)
if ( ( dependencyManagement != null ) && ( (deps = dependencyManagement.getDependencies()) != null ) && ( deps.size() > 0 ))
{
map = new ManagedVersionMap( map );
@ -436,7 +436,7 @@ public class DefaultMavenProjectBuilder
// If the dependencyManagement section listed exclusions,
// add them to the managed artifacts here so that transitive
// dependencies will be excluded if necessary.
if ( null != d.getExclusions() && !d.getExclusions().isEmpty() )
if ( ( null != d.getExclusions() ) && !d.getExclusions().isEmpty() )
{
List exclusions = new ArrayList();
Iterator exclItr = d.getExclusions().iterator();
@ -492,7 +492,7 @@ public class DefaultMavenProjectBuilder
if ( checkDistributionManagementStatus )
{
if ( project.getDistributionManagement() != null && project.getDistributionManagement().getStatus() != null )
if ( ( project.getDistributionManagement() != null ) && ( project.getDistributionManagement().getStatus() != null ) )
{
String projectId = safeVersionlessKey( project.getGroupId(), project.getArtifactId() );
@ -593,7 +593,7 @@ public class DefaultMavenProjectBuilder
throws ArtifactNotFoundException
{
// TODO: configurable actions dependant on status
if ( !projectArtifact.isSnapshot() && status.compareTo( ArtifactStatus.DEPLOYED ) < 0 )
if ( !projectArtifact.isSnapshot() && ( status.compareTo( ArtifactStatus.DEPLOYED ) < 0 ) )
{
// use default policy (enabled, daily update, warn on bad checksum)
ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy();
@ -754,8 +754,12 @@ public class DefaultMavenProjectBuilder
getLogger().debug( "Cannot determine whether " + currentProject.getId() + " is a module of " + previousProject.getId() + ". Reason: " + e.getMessage(), e );
}
getLogger().debug( "[buildInternal] Assembling model-inheritance: child=" + current.getId() + ", parent=" + previous.getId() );
modelInheritanceAssembler.assembleModelInheritance( current, previous, pathAdjustment );
getLogger().debug( "[buildInternal] Assembled model-inheritance for child=" + current.getId() );
previous = current;
previousProject = currentProject;
}
@ -815,7 +819,7 @@ public class DefaultMavenProjectBuilder
if ( rawParent != null )
{
MavenProject processedParent = (MavenProject) projectBuildCache.getCachedProject( rawParent );
MavenProject processedParent = projectBuildCache.getCachedProject( rawParent );
// yeah, this null check might be a bit paranoid, but better safe than sorry...
if ( processedParent != null )
@ -849,7 +853,7 @@ public class DefaultMavenProjectBuilder
collectInitialRepositoriesFromModel( collected, superModel, projectDir, explicitlyActive, explicitlyInactive );
if ( parentSearchRepositories != null && !parentSearchRepositories.isEmpty() )
if ( ( parentSearchRepositories != null ) && !parentSearchRepositories.isEmpty() )
{
collected.addAll( parentSearchRepositories );
}
@ -865,13 +869,13 @@ public class DefaultMavenProjectBuilder
explicitlyActive,
explicitlyInactive );
if ( reposFromProfiles != null && !reposFromProfiles.isEmpty() )
if ( ( reposFromProfiles != null ) && !reposFromProfiles.isEmpty() )
{
collected.addAll( reposFromProfiles );
}
List modelRepos = model.getRepositories();
if ( modelRepos != null && !modelRepos.isEmpty() )
if ( ( modelRepos != null ) && !modelRepos.isEmpty() )
{
try
{
@ -1075,6 +1079,9 @@ public class DefaultMavenProjectBuilder
for ( ModelLineageIterator it = modelLineage.lineageIterator(); it.hasNext(); )
{
Model currentModel = (Model) it.next();
getLogger().debug( "[assembleLineage] Assembling MavenProject instance for: " + currentModel.getId() );
File currentPom = it.getPOMFile();
MavenProject project = new MavenProject( currentModel );
@ -1106,7 +1113,7 @@ public class DefaultMavenProjectBuilder
LinkedHashSet active = new LinkedHashSet();
List existingActiveProfiles = result.getActiveProfiles();
if ( existingActiveProfiles != null && !existingActiveProfiles.isEmpty() )
if ( ( existingActiveProfiles != null ) && !existingActiveProfiles.isEmpty() )
{
active.addAll( existingActiveProfiles );
}
@ -1343,6 +1350,6 @@ public class DefaultMavenProjectBuilder
public void contextualize( Context context )
throws ContextException
{
this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
}

View File

@ -78,7 +78,7 @@ public class DefaultModelLineageBuilder
public DefaultModelLineageBuilder( ArtifactResolver resolver, ArtifactFactory artifactFactory, BuildContextManager buildContextManager )
{
this.artifactResolver = resolver;
artifactResolver = resolver;
this.artifactFactory = artifactFactory;
this.buildContextManager = buildContextManager;
}
@ -94,27 +94,25 @@ public class DefaultModelLineageBuilder
ModelLineage lineage = new DefaultModelLineage();
File pomFile = pom;
List currentRemoteRepositories = remoteRepositories == null ? new ArrayList()
: new ArrayList( remoteRepositories );
while ( pomFile != null )
{
Model model = readModel( pomFile, projectBuildCache );
ModelAndFile current = new ModelAndFile( readModel( pom, projectBuildCache ), pom );
while ( current != null )
{
if ( lineage.size() == 0 )
{
lineage.setOrigin( model, pomFile, currentRemoteRepositories );
lineage.setOrigin( current.model, current.file, currentRemoteRepositories );
}
else
{
lineage.addParent( model, pomFile, currentRemoteRepositories );
lineage.addParent( current.model, current.file, currentRemoteRepositories );
}
currentRemoteRepositories = updateRepositorySet( model, currentRemoteRepositories, pomFile, profileManager );
currentRemoteRepositories = updateRepositorySet( current.model, currentRemoteRepositories, current.file, profileManager );
pomFile = resolveParentPom( model, currentRemoteRepositories, localRepository, pomFile,
projectBuildCache );
current = resolveParentPom( current, currentRemoteRepositories, localRepository, projectBuildCache );
}
return lineage;
@ -126,7 +124,6 @@ public class DefaultModelLineageBuilder
{
ProjectBuildCache projectBuildCache = ProjectBuildCache.read( buildContextManager );
File pomFile = lineage.getDeepestFile();
List currentRemoteRepositories = lineage.getDeepestArtifactRepositoryList();
if ( currentRemoteRepositories == null )
@ -134,28 +131,25 @@ public class DefaultModelLineageBuilder
currentRemoteRepositories = new ArrayList();
}
Model model = lineage.getDeepestModel();
ModelAndFile current = new ModelAndFile( lineage.getDeepestModel(), lineage.getDeepestFile() );
// use the above information to re-bootstrap the resolution chain...
pomFile = resolveParentPom( model, currentRemoteRepositories, localRepository, pomFile, projectBuildCache );
current = resolveParentPom( current, currentRemoteRepositories, localRepository, projectBuildCache );
while ( pomFile != null )
while ( current != null )
{
model = readModel( pomFile, projectBuildCache );
if ( lineage.size() == 0 )
{
lineage.setOrigin( model, pomFile, currentRemoteRepositories );
lineage.setOrigin( current.model, current.file, currentRemoteRepositories );
}
else
{
lineage.addParent( model, pomFile, currentRemoteRepositories );
lineage.addParent( current.model, current.file, currentRemoteRepositories );
}
currentRemoteRepositories = updateRepositorySet( model, currentRemoteRepositories, pomFile, profileManager );
currentRemoteRepositories = updateRepositorySet( current.model, currentRemoteRepositories, current.file, profileManager );
pomFile = resolveParentPom( model, currentRemoteRepositories, localRepository, pomFile,
projectBuildCache );
current = resolveParentPom( current, currentRemoteRepositories, localRepository, projectBuildCache );
}
}
@ -236,7 +230,9 @@ public class DefaultModelLineageBuilder
{
List repositories = model.getRepositories();
loadActiveProfileRepositories( repositories, model, externalProfileManager, pomFile.getParentFile() );
File projectDir = pomFile == null ? null : pomFile.getParentFile();
loadActiveProfileRepositories( repositories, model, externalProfileManager, projectDir );
Set artifactRepositories = null;
@ -295,13 +291,16 @@ public class DefaultModelLineageBuilder
* resolve that artifact...then, return the resolved POM file for the parent.
* @param projectBuildCache
*/
private File resolveParentPom( Model model, List remoteRepositories, ArtifactRepository localRepository,
File modelPomFile, ProjectBuildCache projectBuildCache )
private ModelAndFile resolveParentPom( ModelAndFile child, List remoteRepositories, ArtifactRepository localRepository,
ProjectBuildCache projectBuildCache )
throws ProjectBuildingException
{
Model model = child.model;
File modelPomFile = child.file;
Parent modelParent = model.getParent();
File pomFile = null;
ModelAndFile result = null;
if ( modelParent != null )
{
@ -309,20 +308,38 @@ public class DefaultModelLineageBuilder
// getLogger().debug( "Looking for cached parent POM under: " + cacheKey );
pomFile = (File) projectBuildCache.getCachedModelFile( modelParent );
File parentPomFile = projectBuildCache.getCachedModelFile( modelParent );
if ( pomFile == null )
if ( parentPomFile == null )
{
pomFile = resolveParentWithRelativePath( modelParent, modelPomFile );
parentPomFile = resolveParentWithRelativePath( modelParent, modelPomFile );
}
if ( pomFile == null )
if ( parentPomFile == null )
{
pomFile = resolveParentFromRepositories( modelParent, localRepository, remoteRepositories, modelPomFile );
}
parentPomFile = resolveParentFromRepositories( modelParent, localRepository, remoteRepositories, modelPomFile );
}
return pomFile;
Model parent;
if ( parentPomFile == null )
{
getLogger().warn( "Cannot find parent POM: " + modelParent.getId() + " for child: " + model.getId() + ". Using stub model instead." );
parent = new Model();
parent.setGroupId( modelParent.getGroupId() );
parent.setArtifactId( modelParent.getArtifactId() );
parent.setVersion( modelParent.getVersion() );
}
else
{
parent = readModel( parentPomFile );
}
result = new ModelAndFile( parent, parentPomFile );
}
return result;
}
private void validateParentDeclaration( Parent modelParent, Model model )
@ -404,9 +421,9 @@ public class DefaultModelLineageBuilder
{
Model parentModel = readModel( parentPomFile );
boolean groupsMatch = parentModel.getGroupId() == null
boolean groupsMatch = ( parentModel.getGroupId() == null )
|| parentModel.getGroupId().equals( modelParent.getGroupId() );
boolean versionsMatch = parentModel.getVersion() == null
boolean versionsMatch = ( parentModel.getVersion() == null )
|| parentModel.getVersion().equals( modelParent.getVersion() );
if ( groupsMatch && versionsMatch && parentModel.getArtifactId().equals( modelParent.getArtifactId() ) )
@ -433,4 +450,16 @@ public class DefaultModelLineageBuilder
this.logger = logger;
}
private static final class ModelAndFile
{
private final Model model;
private final File file;
ModelAndFile( Model model, File file )
{
this.model = model;
this.file = file;
}
}
}