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

@ -156,7 +156,7 @@ public class DefaultMavenProjectBuilder
private ModelInheritanceAssembler modelInheritanceAssembler; private ModelInheritanceAssembler modelInheritanceAssembler;
private ModelValidator validator; private ModelValidator validator;
// TODO: make it a component // TODO: make it a component
private MavenXpp3Reader modelReader; private MavenXpp3Reader modelReader;
@ -167,9 +167,9 @@ public class DefaultMavenProjectBuilder
private ModelInterpolator modelInterpolator; private ModelInterpolator modelInterpolator;
private ModelLineageBuilder modelLineageBuilder; private ModelLineageBuilder modelLineageBuilder;
private ProfileAdvisor profileAdvisor; private ProfileAdvisor profileAdvisor;
private BuildContextManager buildContextManager; private BuildContextManager buildContextManager;
private MavenTools mavenTools; private MavenTools mavenTools;
@ -178,7 +178,7 @@ public class DefaultMavenProjectBuilder
// I am making this available for use with a new method that takes a // I am making this available for use with a new method that takes a
// a monitor wagon monitor as a parameter so that tools can use the // a monitor wagon monitor as a parameter so that tools can use the
// methods here and receive callbacks. MNG-1015 // methods here and receive callbacks. MNG-1015
// //
// Probably no longer relevant with wagonManager/wagonManager change - joakime // Probably no longer relevant with wagonManager/wagonManager change - joakime
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -223,8 +223,8 @@ public class DefaultMavenProjectBuilder
throws ProjectBuildingException throws ProjectBuildingException
{ {
ProjectBuildCache projectBuildCache = ProjectBuildCache.read( buildContextManager ); ProjectBuildCache projectBuildCache = ProjectBuildCache.read( buildContextManager );
MavenProject project = (MavenProject) projectBuildCache.getCachedProject( artifact ); MavenProject project = projectBuildCache.getCachedProject( artifact );
if ( project != null ) if ( project != null )
{ {
@ -252,8 +252,8 @@ public class DefaultMavenProjectBuilder
ProfileManager profileManager = new DefaultProfileManager( container ); ProfileManager profileManager = new DefaultProfileManager( container );
return buildStandaloneSuperProject( localRepository, profileManager ); return buildStandaloneSuperProject( localRepository, profileManager );
} }
public MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository, ProfileManager profileManager ) public MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository, ProfileManager profileManager )
throws ProjectBuildingException throws ProjectBuildingException
{ {
Model superModel = getSuperModel(); Model superModel = getSuperModel();
@ -265,27 +265,27 @@ public class DefaultMavenProjectBuilder
superModel.setVersion( STANDALONE_SUPERPOM_VERSION ); superModel.setVersion( STANDALONE_SUPERPOM_VERSION );
MavenProject project = new MavenProject( superModel ); MavenProject project = new MavenProject( superModel );
ProjectBuildContext projectContext = ProjectBuildContext.getProjectBuildContext( buildContextManager, true ); ProjectBuildContext projectContext = ProjectBuildContext.getProjectBuildContext( buildContextManager, true );
projectContext.setCurrentProject( project ); projectContext.setCurrentProject( project );
projectContext.store( buildContextManager ); projectContext.store( buildContextManager );
String projectId = safeVersionlessKey( STANDALONE_SUPERPOM_GROUPID, STANDALONE_SUPERPOM_ARTIFACTID ); String projectId = safeVersionlessKey( STANDALONE_SUPERPOM_GROUPID, STANDALONE_SUPERPOM_ARTIFACTID );
project.setManagedVersionMap(createManagedVersionMap(projectId, superModel.getDependencyManagement(), null)); project.setManagedVersionMap(createManagedVersionMap(projectId, superModel.getDependencyManagement(), null));
List activeProfiles = profileAdvisor.applyActivatedProfiles( superModel, null, profileManager.getExplicitlyActivatedIds(), profileManager.getExplicitlyDeactivatedIds() ); List activeProfiles = profileAdvisor.applyActivatedProfiles( superModel, null, profileManager.getExplicitlyActivatedIds(), profileManager.getExplicitlyDeactivatedIds() );
List activeExternalProfiles = profileAdvisor.applyActivatedExternalProfiles( superModel, null, profileManager ); List activeExternalProfiles = profileAdvisor.applyActivatedExternalProfiles( superModel, null, profileManager );
LinkedHashSet profiles = new LinkedHashSet(); LinkedHashSet profiles = new LinkedHashSet();
if ( activeProfiles != null && !activeProfiles.isEmpty() ) if ( ( activeProfiles != null ) && !activeProfiles.isEmpty() )
{ {
profiles.addAll( activeProfiles ); profiles.addAll( activeProfiles );
} }
if ( activeExternalProfiles != null && !activeExternalProfiles.isEmpty() ) if ( ( activeExternalProfiles != null ) && !activeExternalProfiles.isEmpty() )
{ {
profiles.addAll( activeExternalProfiles ); profiles.addAll( activeExternalProfiles );
} }
@ -408,7 +408,7 @@ public class DefaultMavenProjectBuilder
{ {
Map map = null; Map map = null;
List deps; 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 ); map = new ManagedVersionMap( map );
@ -436,7 +436,7 @@ public class DefaultMavenProjectBuilder
// If the dependencyManagement section listed exclusions, // If the dependencyManagement section listed exclusions,
// add them to the managed artifacts here so that transitive // add them to the managed artifacts here so that transitive
// dependencies will be excluded if necessary. // dependencies will be excluded if necessary.
if ( null != d.getExclusions() && !d.getExclusions().isEmpty() ) if ( ( null != d.getExclusions() ) && !d.getExclusions().isEmpty() )
{ {
List exclusions = new ArrayList(); List exclusions = new ArrayList();
Iterator exclItr = d.getExclusions().iterator(); Iterator exclItr = d.getExclusions().iterator();
@ -479,7 +479,7 @@ public class DefaultMavenProjectBuilder
{ {
container.addContextValue("SystemProperties", System.getProperties()); container.addContextValue("SystemProperties", System.getProperties());
} }
Model model = readModel( "unknown", projectDescriptor, STRICT_MODEL_PARSING ); Model model = readModel( "unknown", projectDescriptor, STRICT_MODEL_PARSING );
MavenProject project = buildInternal( projectDescriptor.getAbsolutePath(), MavenProject project = buildInternal( projectDescriptor.getAbsolutePath(),
@ -492,7 +492,7 @@ public class DefaultMavenProjectBuilder
if ( checkDistributionManagementStatus ) 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() ); String projectId = safeVersionlessKey( project.getGroupId(), project.getArtifactId() );
@ -593,7 +593,7 @@ public class DefaultMavenProjectBuilder
throws ArtifactNotFoundException throws ArtifactNotFoundException
{ {
// TODO: configurable actions dependant on status // 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) // use default policy (enabled, daily update, warn on bad checksum)
ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy(); ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy();
@ -674,12 +674,12 @@ public class DefaultMavenProjectBuilder
Model superModel = getSuperModel(); Model superModel = getSuperModel();
MavenProject superProject = new MavenProject( superModel ); MavenProject superProject = new MavenProject( superModel );
String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() ); String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
List explicitlyActive; List explicitlyActive;
List explicitlyInactive; List explicitlyInactive;
if ( externalProfileManager != null ) if ( externalProfileManager != null )
{ {
// used to trigger the caching of SystemProperties in the container context... // used to trigger the caching of SystemProperties in the container context...
@ -691,7 +691,7 @@ public class DefaultMavenProjectBuilder
{ {
throw new ProjectBuildingException( projectId, "Failed to activate external profiles.", e ); throw new ProjectBuildingException( projectId, "Failed to activate external profiles.", e );
} }
explicitlyActive = externalProfileManager.getExplicitlyActivatedIds(); explicitlyActive = externalProfileManager.getExplicitlyActivatedIds();
explicitlyInactive = externalProfileManager.getExplicitlyDeactivatedIds(); explicitlyInactive = externalProfileManager.getExplicitlyDeactivatedIds();
} }
@ -700,7 +700,7 @@ public class DefaultMavenProjectBuilder
explicitlyActive = Collections.EMPTY_LIST; explicitlyActive = Collections.EMPTY_LIST;
explicitlyInactive = Collections.EMPTY_LIST; explicitlyInactive = Collections.EMPTY_LIST;
} }
superProject.setActiveProfiles( profileAdvisor.applyActivatedProfiles( superModel, null, explicitlyActive, explicitlyInactive ) ); superProject.setActiveProfiles( profileAdvisor.applyActivatedProfiles( superModel, null, explicitlyActive, explicitlyInactive ) );
//noinspection CollectionDeclaredAsConcreteClass //noinspection CollectionDeclaredAsConcreteClass
@ -710,7 +710,7 @@ public class DefaultMavenProjectBuilder
parentSearchRepositories, parentSearchRepositories,
projectDir, explicitlyActive, projectDir, explicitlyActive,
explicitlyInactive ); explicitlyInactive );
Model originalModel = ModelUtils.cloneModel( model ); Model originalModel = ModelUtils.cloneModel( model );
MavenProject project = null; MavenProject project = null;
@ -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( "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 ); modelInheritanceAssembler.assembleModelInheritance( current, previous, pathAdjustment );
getLogger().debug( "[buildInternal] Assembled model-inheritance for child=" + current.getId() );
previous = current; previous = current;
previousProject = currentProject; previousProject = currentProject;
} }
@ -810,13 +814,13 @@ public class DefaultMavenProjectBuilder
// Only track the file of a POM in the source tree // Only track the file of a POM in the source tree
project.setFile( projectDescriptor ); project.setFile( projectDescriptor );
} }
MavenProject rawParent = project.getParent(); MavenProject rawParent = project.getParent();
if ( rawParent != null ) 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... // yeah, this null check might be a bit paranoid, but better safe than sorry...
if ( processedParent != null ) if ( processedParent != null )
{ {
@ -829,10 +833,10 @@ public class DefaultMavenProjectBuilder
return project; return project;
} }
/* /*
* Order is: * Order is:
* *
* 1. model profile repositories * 1. model profile repositories
* 2. model repositories * 2. model repositories
* 3. superModel profile repositories * 3. superModel profile repositories
@ -844,16 +848,16 @@ public class DefaultMavenProjectBuilder
throws ProjectBuildingException throws ProjectBuildingException
{ {
LinkedHashSet collected = new LinkedHashSet(); LinkedHashSet collected = new LinkedHashSet();
collectInitialRepositoriesFromModel( collected, model, projectDir, explicitlyActive, explicitlyInactive ); collectInitialRepositoriesFromModel( collected, model, projectDir, explicitlyActive, explicitlyInactive );
collectInitialRepositoriesFromModel( collected, superModel, projectDir, explicitlyActive, explicitlyInactive ); collectInitialRepositoriesFromModel( collected, superModel, projectDir, explicitlyActive, explicitlyInactive );
if ( parentSearchRepositories != null && !parentSearchRepositories.isEmpty() ) if ( ( parentSearchRepositories != null ) && !parentSearchRepositories.isEmpty() )
{ {
collected.addAll( parentSearchRepositories ); collected.addAll( parentSearchRepositories );
} }
return collected; return collected;
} }
@ -865,13 +869,13 @@ public class DefaultMavenProjectBuilder
explicitlyActive, explicitlyActive,
explicitlyInactive ); explicitlyInactive );
if ( reposFromProfiles != null && !reposFromProfiles.isEmpty() ) if ( ( reposFromProfiles != null ) && !reposFromProfiles.isEmpty() )
{ {
collected.addAll( reposFromProfiles ); collected.addAll( reposFromProfiles );
} }
List modelRepos = model.getRepositories(); List modelRepos = model.getRepositories();
if ( modelRepos != null && !modelRepos.isEmpty() ) if ( ( modelRepos != null ) && !modelRepos.isEmpty() )
{ {
try try
{ {
@ -967,7 +971,7 @@ public class DefaultMavenProjectBuilder
MavenProject parentProject = project.getParent(); MavenProject parentProject = project.getParent();
Model originalModel = project.getOriginalModel(); Model originalModel = project.getOriginalModel();
Artifact parentArtifact = project.getParentArtifact(); Artifact parentArtifact = project.getParentArtifact();
// We will return a different project object using the new model (hence the need to return a project, not just modify the parameter) // We will return a different project object using the new model (hence the need to return a project, not just modify the parameter)
@ -1049,17 +1053,17 @@ public class DefaultMavenProjectBuilder
{ {
ModelLineage modelLineage = new DefaultModelLineage(); ModelLineage modelLineage = new DefaultModelLineage();
modelLineage.setOrigin( model, new File( projectDir, "pom.xml" ), new ArrayList( aggregatedRemoteWagonRepositories ) ); modelLineage.setOrigin( model, new File( projectDir, "pom.xml" ), new ArrayList( aggregatedRemoteWagonRepositories ) );
modelLineageBuilder.resumeBuildingModelLineage( modelLineage, localRepository, externalProfileManager ); modelLineageBuilder.resumeBuildingModelLineage( modelLineage, localRepository, externalProfileManager );
ProjectBuildContext projectContext = ProjectBuildContext.getProjectBuildContext( buildContextManager, true ); ProjectBuildContext projectContext = ProjectBuildContext.getProjectBuildContext( buildContextManager, true );
projectContext.setModelLineage( modelLineage ); projectContext.setModelLineage( modelLineage );
projectContext.store( buildContextManager ); projectContext.store( buildContextManager );
List explicitlyActive; List explicitlyActive;
List explicitlyInactive; List explicitlyInactive;
if ( externalProfileManager != null ) if ( externalProfileManager != null )
{ {
explicitlyActive = externalProfileManager.getExplicitlyActivatedIds(); explicitlyActive = externalProfileManager.getExplicitlyActivatedIds();
@ -1070,50 +1074,53 @@ public class DefaultMavenProjectBuilder
explicitlyActive = Collections.EMPTY_LIST; explicitlyActive = Collections.EMPTY_LIST;
explicitlyInactive = Collections.EMPTY_LIST; explicitlyInactive = Collections.EMPTY_LIST;
} }
MavenProject lastProject = null; MavenProject lastProject = null;
for ( ModelLineageIterator it = modelLineage.lineageIterator(); it.hasNext(); ) for ( ModelLineageIterator it = modelLineage.lineageIterator(); it.hasNext(); )
{ {
Model currentModel = (Model) it.next(); Model currentModel = (Model) it.next();
getLogger().debug( "[assembleLineage] Assembling MavenProject instance for: " + currentModel.getId() );
File currentPom = it.getPOMFile(); File currentPom = it.getPOMFile();
MavenProject project = new MavenProject( currentModel ); MavenProject project = new MavenProject( currentModel );
project.setFile( currentPom ); project.setFile( currentPom );
projectContext.setCurrentProject( project ); projectContext.setCurrentProject( project );
projectContext.store( buildContextManager ); projectContext.store( buildContextManager );
project.setActiveProfiles( profileAdvisor.applyActivatedProfiles( currentModel, projectDir, explicitlyActive, project.setActiveProfiles( profileAdvisor.applyActivatedProfiles( currentModel, projectDir, explicitlyActive,
explicitlyInactive ) ); explicitlyInactive ) );
if ( lastProject != null ) if ( lastProject != null )
{ {
lastProject.setParent( project ); lastProject.setParent( project );
lastProject.setParentArtifact( artifactFactory.createParentArtifact( project.getGroupId(), project lastProject.setParentArtifact( artifactFactory.createParentArtifact( project.getGroupId(), project
.getArtifactId(), project.getVersion() ) ); .getArtifactId(), project.getVersion() ) );
} }
lineage.addFirst( project ); lineage.addFirst( project );
lastProject = project; lastProject = project;
} }
MavenProject result = (MavenProject) lineage.getLast(); MavenProject result = (MavenProject) lineage.getLast();
if ( externalProfileManager != null ) if ( externalProfileManager != null )
{ {
LinkedHashSet active = new LinkedHashSet(); LinkedHashSet active = new LinkedHashSet();
List existingActiveProfiles = result.getActiveProfiles(); List existingActiveProfiles = result.getActiveProfiles();
if ( existingActiveProfiles != null && !existingActiveProfiles.isEmpty() ) if ( ( existingActiveProfiles != null ) && !existingActiveProfiles.isEmpty() )
{ {
active.addAll( existingActiveProfiles ); active.addAll( existingActiveProfiles );
} }
profileAdvisor.applyActivatedExternalProfiles( result.getModel(), projectDir, externalProfileManager ); profileAdvisor.applyActivatedExternalProfiles( result.getModel(), projectDir, externalProfileManager );
} }
return result; return result;
} }
@ -1343,6 +1350,6 @@ public class DefaultMavenProjectBuilder
public void contextualize( Context context ) public void contextualize( Context context )
throws ContextException throws ContextException
{ {
this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
} }
} }

View File

@ -67,7 +67,7 @@ public class DefaultModelLineageBuilder
private MavenTools mavenTools; private MavenTools mavenTools;
private ProfileAdvisor profileAdvisor; private ProfileAdvisor profileAdvisor;
private BuildContextManager buildContextManager; private BuildContextManager buildContextManager;
private Logger logger; private Logger logger;
@ -78,7 +78,7 @@ public class DefaultModelLineageBuilder
public DefaultModelLineageBuilder( ArtifactResolver resolver, ArtifactFactory artifactFactory, BuildContextManager buildContextManager ) public DefaultModelLineageBuilder( ArtifactResolver resolver, ArtifactFactory artifactFactory, BuildContextManager buildContextManager )
{ {
this.artifactResolver = resolver; artifactResolver = resolver;
this.artifactFactory = artifactFactory; this.artifactFactory = artifactFactory;
this.buildContextManager = buildContextManager; this.buildContextManager = buildContextManager;
} }
@ -91,30 +91,28 @@ public class DefaultModelLineageBuilder
throws ProjectBuildingException throws ProjectBuildingException
{ {
ProjectBuildCache projectBuildCache = ProjectBuildCache.read( buildContextManager ); ProjectBuildCache projectBuildCache = ProjectBuildCache.read( buildContextManager );
ModelLineage lineage = new DefaultModelLineage(); ModelLineage lineage = new DefaultModelLineage();
File pomFile = pom;
List currentRemoteRepositories = remoteRepositories == null ? new ArrayList() List currentRemoteRepositories = remoteRepositories == null ? new ArrayList()
: new ArrayList( remoteRepositories ); : new ArrayList( remoteRepositories );
while ( pomFile != null ) ModelAndFile current = new ModelAndFile( readModel( pom, projectBuildCache ), pom );
{
Model model = readModel( pomFile, projectBuildCache );
while ( current != null )
{
if ( lineage.size() == 0 ) if ( lineage.size() == 0 )
{ {
lineage.setOrigin( model, pomFile, currentRemoteRepositories ); lineage.setOrigin( current.model, current.file, currentRemoteRepositories );
} }
else 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, current = resolveParentPom( current, currentRemoteRepositories, localRepository, projectBuildCache );
projectBuildCache );
} }
return lineage; return lineage;
@ -125,8 +123,7 @@ public class DefaultModelLineageBuilder
throws ProjectBuildingException throws ProjectBuildingException
{ {
ProjectBuildCache projectBuildCache = ProjectBuildCache.read( buildContextManager ); ProjectBuildCache projectBuildCache = ProjectBuildCache.read( buildContextManager );
File pomFile = lineage.getDeepestFile();
List currentRemoteRepositories = lineage.getDeepestArtifactRepositoryList(); List currentRemoteRepositories = lineage.getDeepestArtifactRepositoryList();
if ( currentRemoteRepositories == null ) if ( currentRemoteRepositories == null )
@ -134,28 +131,25 @@ public class DefaultModelLineageBuilder
currentRemoteRepositories = new ArrayList(); 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... // 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 ) if ( lineage.size() == 0 )
{ {
lineage.setOrigin( model, pomFile, currentRemoteRepositories ); lineage.setOrigin( current.model, current.file, currentRemoteRepositories );
} }
else 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, current = resolveParentPom( current, currentRemoteRepositories, localRepository, projectBuildCache );
projectBuildCache );
} }
} }
@ -170,7 +164,7 @@ public class DefaultModelLineageBuilder
} }
/** /**
* Read the Model instance from the given POM file, and cache it in the given Map before * Read the Model instance from the given POM file, and cache it in the given Map before
* returning it. * returning it.
*/ */
private Model readModel( File pomFile, ProjectBuildCache projectBuildCache ) private Model readModel( File pomFile, ProjectBuildCache projectBuildCache )
@ -193,7 +187,7 @@ public class DefaultModelLineageBuilder
pomFile = new File( pom, "pom.xml" ); pomFile = new File( pom, "pom.xml" );
// getLogger().debug( "readModel(..): POM: " + pom + " is a directory. Trying: " + pomFile + " instead." ); // getLogger().debug( "readModel(..): POM: " + pom + " is a directory. Trying: " + pomFile + " instead." );
} }
Model model; Model model;
FileReader reader = null; FileReader reader = null;
@ -225,10 +219,10 @@ public class DefaultModelLineageBuilder
} }
/** /**
* Update the remote repository set used to resolve parent POMs, by adding those declared in * Update the remote repository set used to resolve parent POMs, by adding those declared in
* the given model to the HEAD of a new list, then appending the old remote repositories list. * the given model to the HEAD of a new list, then appending the old remote repositories list.
* The specified pomFile is used for error reporting. * The specified pomFile is used for error reporting.
* @param profileManager * @param profileManager
*/ */
private List updateRepositorySet( Model model, List oldArtifactRepositories, File pomFile, private List updateRepositorySet( Model model, List oldArtifactRepositories, File pomFile,
ProfileManager externalProfileManager ) ProfileManager externalProfileManager )
@ -236,7 +230,9 @@ public class DefaultModelLineageBuilder
{ {
List repositories = model.getRepositories(); 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; Set artifactRepositories = null;
@ -293,36 +289,57 @@ public class DefaultModelLineageBuilder
/** /**
* Pull the parent specification out of the given model, construct an Artifact instance, and * Pull the parent specification out of the given model, construct an Artifact instance, and
* resolve that artifact...then, return the resolved POM file for the parent. * resolve that artifact...then, return the resolved POM file for the parent.
* @param projectBuildCache * @param projectBuildCache
*/ */
private File resolveParentPom( Model model, List remoteRepositories, ArtifactRepository localRepository, private ModelAndFile resolveParentPom( ModelAndFile child, List remoteRepositories, ArtifactRepository localRepository,
File modelPomFile, ProjectBuildCache projectBuildCache ) ProjectBuildCache projectBuildCache )
throws ProjectBuildingException throws ProjectBuildingException
{ {
Model model = child.model;
File modelPomFile = child.file;
Parent modelParent = model.getParent(); Parent modelParent = model.getParent();
File pomFile = null; ModelAndFile result = null;
if ( modelParent != null ) if ( modelParent != null )
{ {
validateParentDeclaration( modelParent, model ); validateParentDeclaration( modelParent, model );
// getLogger().debug( "Looking for cached parent POM under: " + cacheKey ); // getLogger().debug( "Looking for cached parent POM under: " + cacheKey );
pomFile = (File) projectBuildCache.getCachedModelFile( modelParent );
if ( pomFile == null ) File parentPomFile = projectBuildCache.getCachedModelFile( modelParent );
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 );
} }
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 pomFile; return result;
} }
private void validateParentDeclaration( Parent modelParent, Model model ) private void validateParentDeclaration( Parent modelParent, Model model )
@ -404,9 +421,9 @@ public class DefaultModelLineageBuilder
{ {
Model parentModel = readModel( parentPomFile ); Model parentModel = readModel( parentPomFile );
boolean groupsMatch = parentModel.getGroupId() == null boolean groupsMatch = ( parentModel.getGroupId() == null )
|| parentModel.getGroupId().equals( modelParent.getGroupId() ); || parentModel.getGroupId().equals( modelParent.getGroupId() );
boolean versionsMatch = parentModel.getVersion() == null boolean versionsMatch = ( parentModel.getVersion() == null )
|| parentModel.getVersion().equals( modelParent.getVersion() ); || parentModel.getVersion().equals( modelParent.getVersion() );
if ( groupsMatch && versionsMatch && parentModel.getArtifactId().equals( modelParent.getArtifactId() ) ) if ( groupsMatch && versionsMatch && parentModel.getArtifactId().equals( modelParent.getArtifactId() ) )
@ -433,4 +450,16 @@ public class DefaultModelLineageBuilder
this.logger = logger; 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;
}
}
} }