Fixing a few problems with the model-lineage builder, where it was stubbing models inappropriately and other minor logical problems.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@564761 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2007-08-10 20:49:14 +00:00
parent 1d58a421ce
commit c5a74a8242
8 changed files with 329 additions and 193 deletions

View File

@ -330,7 +330,7 @@ public class DefaultBuildExtensionScanner
getLogger().debug( "Building model-lineage for: " + pom + " to pre-scan for extensions." ); getLogger().debug( "Building model-lineage for: " + pom + " to pre-scan for extensions." );
lineage = modelLineageBuilder.buildModelLineage( pom, localRepository, originalRemoteRepositories, lineage = modelLineageBuilder.buildModelLineage( pom, localRepository, originalRemoteRepositories,
globalProfileManager ); globalProfileManager, false );
} }
catch ( ProjectBuildingException e ) catch ( ProjectBuildingException e )
{ {

View File

@ -754,11 +754,11 @@ 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() ); getLogger().debug( "[buildInternal] Assembling model-inheritance: child=" + current.getId() + " has distributionManagement? " + ( current.getDistributionManagement() != null ) + ", parent=" + previous.getId() + " has distributionManagement? " + ( previous.getDistributionManagement() != null ) );
modelInheritanceAssembler.assembleModelInheritance( current, previous, pathAdjustment ); modelInheritanceAssembler.assembleModelInheritance( current, previous, pathAdjustment );
getLogger().debug( "[buildInternal] Assembled model-inheritance for child=" + current.getId() ); getLogger().debug( "[buildInternal] Assembled model-inheritance for child=" + current.getId() + " (has distributionManagement? " + ( current.getDistributionManagement() != null ) + ")" );
previous = current; previous = current;
previousProject = currentProject; previousProject = currentProject;
@ -1054,7 +1054,8 @@ 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 ); // strict means "no stubs", so we invert it here for the allowStubs parameter.
modelLineageBuilder.resumeBuildingModelLineage( modelLineage, localRepository, externalProfileManager, !strict );
ProjectBuildContext projectContext = ProjectBuildContext.getProjectBuildContext( buildContextManager, true ); ProjectBuildContext projectContext = ProjectBuildContext.getProjectBuildContext( buildContextManager, true );
@ -1080,8 +1081,6 @@ public class DefaultMavenProjectBuilder
{ {
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 );

View File

@ -45,7 +45,7 @@ public class DefaultModelLineage
{ {
throw new IllegalStateException( "You must call setOrigin(..) before adding a parent to the lineage." ); throw new IllegalStateException( "You must call setOrigin(..) before adding a parent to the lineage." );
} }
tuples.add( new ModelLineageTuple( model, pomFile, artifactRepositories ) ); tuples.add( new ModelLineageTuple( model, pomFile, artifactRepositories ) );
} }
@ -123,18 +123,18 @@ public class DefaultModelLineage
{ {
return Collections.EMPTY_LIST; return Collections.EMPTY_LIST;
} }
List tuplesInReverse = new ArrayList( tuples ); List tuplesInReverse = new ArrayList( tuples );
Collections.reverse( tuplesInReverse ); Collections.reverse( tuplesInReverse );
List results = new ArrayList( tuplesInReverse.size() ); List results = new ArrayList( tuplesInReverse.size() );
for ( Iterator it = tuplesInReverse.iterator(); it.hasNext(); ) for ( Iterator it = tuplesInReverse.iterator(); it.hasNext(); )
{ {
ModelLineageTuple tuple = (ModelLineageTuple) it.next(); ModelLineageTuple tuple = (ModelLineageTuple) it.next();
results.add( tuple.remoteRepositories ); results.add( tuple.remoteRepositories );
} }
return results; return results;
} }
@ -156,18 +156,18 @@ public class DefaultModelLineage
{ {
return Collections.EMPTY_LIST; return Collections.EMPTY_LIST;
} }
List tuplesInReverse = new ArrayList( tuples ); List tuplesInReverse = new ArrayList( tuples );
Collections.reverse( tuplesInReverse ); Collections.reverse( tuplesInReverse );
List results = new ArrayList( tuplesInReverse.size() ); List results = new ArrayList( tuplesInReverse.size() );
for ( Iterator it = tuplesInReverse.iterator(); it.hasNext(); ) for ( Iterator it = tuplesInReverse.iterator(); it.hasNext(); )
{ {
ModelLineageTuple tuple = (ModelLineageTuple) it.next(); ModelLineageTuple tuple = (ModelLineageTuple) it.next();
results.add( tuple.file ); results.add( tuple.file );
} }
return results; return results;
} }
@ -177,18 +177,18 @@ public class DefaultModelLineage
{ {
return Collections.EMPTY_LIST; return Collections.EMPTY_LIST;
} }
List tuplesInReverse = new ArrayList( tuples ); List tuplesInReverse = new ArrayList( tuples );
Collections.reverse( tuplesInReverse ); Collections.reverse( tuplesInReverse );
List results = new ArrayList( tuplesInReverse.size() ); List results = new ArrayList( tuplesInReverse.size() );
for ( Iterator it = tuplesInReverse.iterator(); it.hasNext(); ) for ( Iterator it = tuplesInReverse.iterator(); it.hasNext(); )
{ {
ModelLineageTuple tuple = (ModelLineageTuple) it.next(); ModelLineageTuple tuple = (ModelLineageTuple) it.next();
results.add( tuple.model ); results.add( tuple.model );
} }
return results; return results;
} }
@ -198,9 +198,9 @@ public class DefaultModelLineage
{ {
return null; return null;
} }
ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( 0 ); ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( 0 );
return tuple.remoteRepositories; return tuple.remoteRepositories;
} }
@ -210,9 +210,9 @@ public class DefaultModelLineage
{ {
return null; return null;
} }
ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( 0 ); ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( 0 );
return tuple.model; return tuple.model;
} }
@ -222,45 +222,45 @@ public class DefaultModelLineage
{ {
return null; return null;
} }
ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( 0 ); ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( 0 );
return tuple.file; return tuple.file;
} }
public List getDeepestArtifactRepositoryList() public List getDeepestAncestorArtifactRepositoryList()
{ {
if ( tuples.isEmpty() ) if ( tuples.isEmpty() )
{ {
return null; return null;
} }
ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( tuples.size() - 1 ); ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( tuples.size() - 1 );
return tuple.remoteRepositories; return tuple.remoteRepositories;
} }
public File getDeepestFile() public File getDeepestAncestorFile()
{ {
if ( tuples.isEmpty() ) if ( tuples.isEmpty() )
{ {
return null; return null;
} }
ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( tuples.size() - 1 ); ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( tuples.size() - 1 );
return tuple.file; return tuple.file;
} }
public Model getDeepestModel() public Model getDeepestAncestorModel()
{ {
if ( tuples.isEmpty() ) if ( tuples.isEmpty() )
{ {
return null; return null;
} }
ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( tuples.size() - 1 ); ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( tuples.size() - 1 );
return tuple.model; return tuple.model;
} }
@ -298,7 +298,7 @@ public class DefaultModelLineage
{ {
throw new IllegalStateException( "Origin already set; you must use addParent(..) for successive additions to the lineage." ); throw new IllegalStateException( "Origin already set; you must use addParent(..) for successive additions to the lineage." );
} }
tuples.add( new ModelLineageTuple( model, pomFile, artifactRepositories ) ); tuples.add( new ModelLineageTuple( model, pomFile, artifactRepositories ) );
} }
@ -309,7 +309,7 @@ public class DefaultModelLineage
{ {
return tuples.size(); return tuples.size();
} }
private static final class ModelLineageTuple private static final class ModelLineageTuple
{ {
private Model model; private Model model;

View File

@ -87,7 +87,7 @@ public class DefaultModelLineageBuilder
* @see org.apache.maven.project.build.model.ModelLineageBuilder#buildModelLineage(java.io.File, org.apache.maven.artifact.repository.ArtifactRepository, java.util.List) * @see org.apache.maven.project.build.model.ModelLineageBuilder#buildModelLineage(java.io.File, org.apache.maven.artifact.repository.ArtifactRepository, java.util.List)
*/ */
public ModelLineage buildModelLineage( File pom, ArtifactRepository localRepository, List remoteRepositories, public ModelLineage buildModelLineage( File pom, ArtifactRepository localRepository, List remoteRepositories,
ProfileManager profileManager ) ProfileManager profileManager, boolean allowStubs )
throws ProjectBuildingException throws ProjectBuildingException
{ {
ProjectBuildCache projectBuildCache = ProjectBuildCache.read( buildContextManager ); ProjectBuildCache projectBuildCache = ProjectBuildCache.read( buildContextManager );
@ -99,7 +99,7 @@ public class DefaultModelLineageBuilder
ModelAndFile current = new ModelAndFile( readModel( pom, projectBuildCache ), pom ); ModelAndFile current = new ModelAndFile( readModel( pom, projectBuildCache ), pom );
while ( current != null ) do
{ {
if ( lineage.size() == 0 ) if ( lineage.size() == 0 )
{ {
@ -112,44 +112,43 @@ public class DefaultModelLineageBuilder
currentRemoteRepositories = updateRepositorySet( current.model, currentRemoteRepositories, current.file, profileManager ); currentRemoteRepositories = updateRepositorySet( current.model, currentRemoteRepositories, current.file, profileManager );
current = resolveParentPom( current, currentRemoteRepositories, localRepository, projectBuildCache ); current = resolveParentPom( current, currentRemoteRepositories, localRepository, projectBuildCache, allowStubs );
} }
while ( current != null );
return lineage; return lineage;
} }
public void resumeBuildingModelLineage( ModelLineage lineage, ArtifactRepository localRepository, public void resumeBuildingModelLineage( ModelLineage lineage, ArtifactRepository localRepository,
ProfileManager profileManager ) ProfileManager profileManager, boolean allowStubs )
throws ProjectBuildingException throws ProjectBuildingException
{ {
if ( lineage.size() == 0 )
{
throw new ProjectBuildingException( "unknown", "Cannot resume a ModelLineage that doesn't contain at least one Model instance." );
}
ProjectBuildCache projectBuildCache = ProjectBuildCache.read( buildContextManager ); ProjectBuildCache projectBuildCache = ProjectBuildCache.read( buildContextManager );
List currentRemoteRepositories = lineage.getDeepestArtifactRepositoryList(); List currentRemoteRepositories = lineage.getDeepestAncestorArtifactRepositoryList();
if ( currentRemoteRepositories == null ) if ( currentRemoteRepositories == null )
{ {
currentRemoteRepositories = new ArrayList(); currentRemoteRepositories = new ArrayList();
} }
ModelAndFile current = new ModelAndFile( lineage.getDeepestModel(), lineage.getDeepestFile() ); ModelAndFile current = new ModelAndFile( lineage.getDeepestAncestorModel(), lineage.getDeepestAncestorFile() );
// use the above information to re-bootstrap the resolution chain... // use the above information to re-bootstrap the resolution chain...
current = resolveParentPom( current, currentRemoteRepositories, localRepository, projectBuildCache ); current = resolveParentPom( current, currentRemoteRepositories, localRepository, projectBuildCache, allowStubs );
while ( current != null ) while ( current != null )
{ {
if ( lineage.size() == 0 ) lineage.addParent( current.model, current.file, currentRemoteRepositories );
{
lineage.setOrigin( current.model, current.file, currentRemoteRepositories );
}
else
{
lineage.addParent( current.model, current.file, currentRemoteRepositories );
}
currentRemoteRepositories = updateRepositorySet( current.model, currentRemoteRepositories, current.file, profileManager ); currentRemoteRepositories = updateRepositorySet( current.model, currentRemoteRepositories, current.file, profileManager );
current = resolveParentPom( current, currentRemoteRepositories, localRepository, projectBuildCache ); current = resolveParentPom( current, currentRemoteRepositories, localRepository, projectBuildCache, allowStubs );
} }
} }
@ -290,9 +289,10 @@ 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
* @param allowStubs
*/ */
private ModelAndFile resolveParentPom( ModelAndFile child, List remoteRepositories, ArtifactRepository localRepository, private ModelAndFile resolveParentPom( ModelAndFile child, List remoteRepositories, ArtifactRepository localRepository,
ProjectBuildCache projectBuildCache ) ProjectBuildCache projectBuildCache, boolean allowStubs )
throws ProjectBuildingException throws ProjectBuildingException
{ {
Model model = child.model; Model model = child.model;
@ -304,9 +304,7 @@ public class DefaultModelLineageBuilder
if ( modelParent != null ) if ( modelParent != null )
{ {
validateParentDeclaration( modelParent, model ); validateParentDeclaration( modelParent, model );
// getLogger().debug( "Looking for cached parent POM under: " + cacheKey );
File parentPomFile = projectBuildCache.getCachedModelFile( modelParent ); File parentPomFile = projectBuildCache.getCachedModelFile( modelParent );
@ -317,26 +315,48 @@ public class DefaultModelLineageBuilder
if ( parentPomFile == null ) if ( parentPomFile == null )
{ {
parentPomFile = resolveParentFromRepositories( modelParent, localRepository, remoteRepositories, modelPomFile ); try
{
parentPomFile = resolveParentFromRepositories( modelParent, localRepository, remoteRepositories, modelPomFile );
}
catch( ProjectBuildingException e )
{
if ( allowStubs )
{
getLogger().debug( "DISREGARDING the error encountered while resolving artifact for: " + modelParent.getId() + ", building a stub model in its place.", e );
parentPomFile = null;
}
else
{
throw e;
}
}
} }
Model parent;
if ( parentPomFile == null ) if ( parentPomFile == null )
{ {
getLogger().warn( "Cannot find parent POM: " + modelParent.getId() + " for child: " + model.getId() + ". Using stub model instead." ); if ( allowStubs )
{
getLogger().warn( "Cannot find parent POM: " + modelParent.getId() + " for child: " + model.getId() + ". Using stub model instead." );
parent = new Model(); Model parent = new Model();
parent.setGroupId( modelParent.getGroupId() ); parent.setGroupId( modelParent.getGroupId() );
parent.setArtifactId( modelParent.getArtifactId() ); parent.setArtifactId( modelParent.getArtifactId() );
parent.setVersion( modelParent.getVersion() ); parent.setVersion( modelParent.getVersion() );
result = new ModelAndFile( parent, parentPomFile );
}
else
{
getLogger().error( "Cannot find parent POM: " + modelParent.getId() );
}
} }
else else
{ {
parent = readModel( parentPomFile ); Model parent = readModel( parentPomFile );
result = new ModelAndFile( parent, parentPomFile );
} }
result = new ModelAndFile( parent, parentPomFile );
} }
return result; return result;

View File

@ -28,56 +28,56 @@ import java.util.List;
/** /**
* Tracks information from a current POM and its ancestors, including Model instances, associated * Tracks information from a current POM and its ancestors, including Model instances, associated
* POM files, and repository lists used to resolve each model. * POM files, and repository lists used to resolve each model.
* *
* @author jdcasey * @author jdcasey
* *
*/ */
public interface ModelLineage public interface ModelLineage
{ {
/** /**
* Retrieve the Model instance for the deepest ancestor which has been resolved so far in this * Retrieve the Model instance for the deepest ancestor which has been resolved so far in this
* lineage. * lineage.
*/ */
Model getDeepestModel(); Model getDeepestAncestorModel();
/** /**
* Retrieve the POM file for the deepest ancestor which has been resolved so far in this * Retrieve the POM file for the deepest ancestor which has been resolved so far in this
* lineage. * lineage.
*/ */
File getDeepestFile(); File getDeepestAncestorFile();
/** /**
* Retrieve the remote-repository list for the deepest ancestor which has been resolved so far * Retrieve the remote-repository list for the deepest ancestor which has been resolved so far
* in this lineage. * in this lineage.
*/ */
List getDeepestArtifactRepositoryList(); List getDeepestAncestorArtifactRepositoryList();
/** /**
* Retrieve the Model instance for the POM from which this lineage was constructed. This is the * Retrieve the Model instance for the POM from which this lineage was constructed. This is the
* "leaf" of the inheritance hierarchy, or the current POM, or the child (all means the same * "leaf" of the inheritance hierarchy, or the current POM, or the child (all means the same
* thing). * thing).
*/ */
Model getOriginatingModel(); Model getOriginatingModel();
/** /**
* Retrieve the File for the POM from which this lineage was constructed. This is the * Retrieve the File for the POM from which this lineage was constructed. This is the
* "leaf" of the inheritance hierarchy, or the current POM, or the child (all means the same * "leaf" of the inheritance hierarchy, or the current POM, or the child (all means the same
* thing). * thing).
*/ */
File getOriginatingPOMFile(); File getOriginatingPOMFile();
/** /**
* Retrieve the List of ArtifactRepository instances used to resolve the first parent POM of the * Retrieve the List of ArtifactRepository instances used to resolve the first parent POM of the
* POM from which this lineage was constructed. This is the "leaf" of the inheritance hierarchy, * POM from which this lineage was constructed. This is the "leaf" of the inheritance hierarchy,
* or the current POM, or the child (all means the same thing). * or the current POM, or the child (all means the same thing).
*/ */
List getOriginatingArtifactRepositoryList(); List getOriginatingArtifactRepositoryList();
/** /**
* Setup the originating POM information from which this lineage is constructed. This is the * Setup the originating POM information from which this lineage is constructed. This is the
* "child" POM that is the starting point of the build. * "child" POM that is the starting point of the build.
* *
* @throws IllegalStateException When the originating POM information has already been set. * @throws IllegalStateException When the originating POM information has already been set.
*/ */
void setOrigin( Model model, File pomFile, List artifactRepositories ); void setOrigin( Model model, File pomFile, List artifactRepositories );
@ -85,59 +85,59 @@ public interface ModelLineage
/** /**
* Add a parent model, along with its file and the repositories used to resolve it. * Add a parent model, along with its file and the repositories used to resolve it.
* NOTE: If setOrigin(..) hasn't been called, this method will result in an IllegalStateException. * NOTE: If setOrigin(..) hasn't been called, this method will result in an IllegalStateException.
* *
* @throws IllegalStateException When the originating POM information has not yet been set. * @throws IllegalStateException When the originating POM information has not yet been set.
*/ */
void addParent( Model model, File pomFile, List artifactRepositories ); void addParent( Model model, File pomFile, List artifactRepositories );
/** /**
* Retrieve the models in this lineage, with the deepest parent at the zero index, and the current * Retrieve the models in this lineage, with the deepest parent at the zero index, and the current
* POM at the last index. * POM at the last index.
*/ */
List getModelsInDescendingOrder(); List getModelsInDescendingOrder();
/** /**
* Retrieve the files used to construct this lineage, with that of the deepest parent at the * Retrieve the files used to construct this lineage, with that of the deepest parent at the
* zero index, and that of the current POM at the last index. * zero index, and that of the current POM at the last index.
*/ */
List getFilesInDescendingOrder(); List getFilesInDescendingOrder();
/** /**
* Retrieve the remote-artifact repository lists used to construct this lineage, with * Retrieve the remote-artifact repository lists used to construct this lineage, with
* that of the deepest parent at the zero index, and that of the current POM at the last index. * that of the deepest parent at the zero index, and that of the current POM at the last index.
*/ */
List getArtifactRepositoryListsInDescendingOrder(); List getArtifactRepositoryListsInDescendingOrder();
/** /**
* Retrieve an Iterator derivative that functions in the simplest sense just like the return * Retrieve an Iterator derivative that functions in the simplest sense just like the return
* value of the modelIterator() method. However, the ModelLineageIterator also gives access to * value of the modelIterator() method. However, the ModelLineageIterator also gives access to
* the current POM file and current remote ArtifactRepository instances used to resolve the * the current POM file and current remote ArtifactRepository instances used to resolve the
* current Model...along with a method to give explicit access to the current Model instance. * current Model...along with a method to give explicit access to the current Model instance.
*/ */
ModelLineageIterator lineageIterator(); ModelLineageIterator lineageIterator();
/** /**
* Retrieve an Iterator derivative that functions in the simplest sense just like the return * Retrieve an Iterator derivative that functions in the simplest sense just like the return
* value of the modelIterator() method. However, the ModelLineageIterator also gives access to * value of the modelIterator() method. However, the ModelLineageIterator also gives access to
* the current POM file and current remote ArtifactRepository instances used to resolve the * the current POM file and current remote ArtifactRepository instances used to resolve the
* current Model...along with a method to give explicit access to the current Model instance. * current Model...along with a method to give explicit access to the current Model instance.
*/ */
ModelLineageIterator reversedLineageIterator(); ModelLineageIterator reversedLineageIterator();
/** /**
* Iterate over the lineage of Model instances, starting with the child (current) Model, * Iterate over the lineage of Model instances, starting with the child (current) Model,
* and ending with the deepest ancestor. * and ending with the deepest ancestor.
*/ */
Iterator modelIterator(); Iterator modelIterator();
/** /**
* Iterate over the lineage of POM Files, starting with the child (current) POM and ending with * Iterate over the lineage of POM Files, starting with the child (current) POM and ending with
* the deepest ancestor. * the deepest ancestor.
*/ */
Iterator fileIterator(); Iterator fileIterator();
/** /**
* Iterate over the remote-repository Lists used to resolve the lineage, starting with the * Iterate over the remote-repository Lists used to resolve the lineage, starting with the
* child (current) remote-repository List and ending with the deepest ancestor. * child (current) remote-repository List and ending with the deepest ancestor.
*/ */
Iterator artifactRepositoryListIterator(); Iterator artifactRepositoryListIterator();
@ -149,7 +149,7 @@ public interface ModelLineage
File getFile( Model model ); File getFile( Model model );
/** /**
* Retrieve the List of remote repositories from which the given Model instance was resolved. * Retrieve the List of remote repositories from which the given Model instance was resolved.
* If the model itself doesn't belong to this lineage, match it in the lineage by Model.getId(). * If the model itself doesn't belong to this lineage, match it in the lineage by Model.getId().
*/ */
List getArtifactRepositories( Model model ); List getArtifactRepositories( Model model );

View File

@ -29,7 +29,7 @@ import java.util.List;
/** /**
* Builds the lineage of Model instances, starting from a given POM file, and stretching back through * Builds the lineage of Model instances, starting from a given POM file, and stretching back through
* all of the parent POMs that are defined in the respective <parent/> sections. * all of the parent POMs that are defined in the respective <parent/> sections.
* *
* NOTE: In all of the build/resume methods below, each Model MUST have its active profiles searched * NOTE: In all of the build/resume methods below, each Model MUST have its active profiles searched
* for new repositories from which to discover parent POMs. * for new repositories from which to discover parent POMs.
*/ */
@ -39,33 +39,37 @@ public interface ModelLineageBuilder
String ROLE = ModelLineageBuilder.class.getName(); String ROLE = ModelLineageBuilder.class.getName();
/** /**
* Construct a lineage of the current POM plus all of its ancestors. * Construct a lineage of the current POM plus all of its ancestors.
* *
* COMING: Also, set ProjectBuildContext.currentModelLineage build-context to the result of this * COMING: Also, set ProjectBuildContext.currentModelLineage build-context to the result of this
* method before returning. * method before returning.
* *
* @param pom The current POM, whose Model will terminate the constructed lineage * @param pom The current POM, whose Model will terminate the constructed lineage
* @param localRepository The local repository against which parent POMs should be resolved * @param localRepository The local repository against which parent POMs should be resolved
* @param remoteRepositories List of ArtifactRepository instances against which parent POMs * @param remoteRepositories List of ArtifactRepository instances against which parent POMs
* should be resolved * should be resolved
* @param profileManager The profile manager containing information about global profiles to be * @param profileManager The profile manager containing information about global profiles to be
* applied (from settings.xml, for instance) * applied (from settings.xml, for instance)
* @param allowStubs Whether stubbed-out Model instances should be constructed in the event that
* a parent-POM cannot be resolved.
*/ */
ModelLineage buildModelLineage( File pom, ArtifactRepository localRepository, List remoteRepositories, ModelLineage buildModelLineage( File pom, ArtifactRepository localRepository, List remoteRepositories,
ProfileManager profileManager ) ProfileManager profileManager, boolean allowStubs )
throws ProjectBuildingException; throws ProjectBuildingException;
/** /**
* Resume the process of constructing a lineage of inherited models, picking up using the deepest * Resume the process of constructing a lineage of inherited models, picking up using the deepest
* parent already in the lineage. * parent already in the lineage.
* *
* @param lineage The ModelLineage instance in progress, which should be completed. * @param lineage The ModelLineage instance in progress, which should be completed.
* @param localRepository The local repository against which parent POMs should be resolved * @param localRepository The local repository against which parent POMs should be resolved
* @param profileManager The profile manager containing information about global profiles to be * @param profileManager The profile manager containing information about global profiles to be
* applied (from settings.xml, for instance) * applied (from settings.xml, for instance)
* @param allowStubs Whether stubbed-out Model instances should be constructed in the event that
* a parent-POM cannot be resolved.
*/ */
void resumeBuildingModelLineage( ModelLineage lineage, ArtifactRepository localRepository, void resumeBuildingModelLineage( ModelLineage lineage, ArtifactRepository localRepository,
ProfileManager profileManager ) ProfileManager profileManager, boolean allowStubs )
throws ProjectBuildingException; throws ProjectBuildingException;
} }

View File

@ -58,13 +58,13 @@ public class DefaultModelLineageBuilderTest
defaultLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); defaultLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
} }
public void tearDown() public void tearDown()
throws Exception throws Exception
{ {
BuildContextManager ctxMgr = (BuildContextManager) lookup( BuildContextManager.ROLE ); BuildContextManager ctxMgr = (BuildContextManager) lookup( BuildContextManager.ROLE );
ctxMgr.clearBuildContext(); ctxMgr.clearBuildContext();
super.tearDown(); super.tearDown();
} }
@ -96,7 +96,7 @@ public class DefaultModelLineageBuilderTest
IOUtil.close( writer ); IOUtil.close( writer );
} }
ModelLineage lineage = modelLineageBuilder.buildModelLineage( pomFile, null, null, null ); ModelLineage lineage = modelLineageBuilder.buildModelLineage( pomFile, null, null, null, false );
assertEquals( 1, lineage.size() ); assertEquals( 1, lineage.size() );
@ -150,11 +150,13 @@ public class DefaultModelLineageBuilderTest
writeModel( current, currentPOM ); writeModel( current, currentPOM );
// 7. build the lineage. // 7. build the lineage.
ArtifactRepository localRepository = new DefaultArtifactRepository( "local", localRepoDirectory.toURL() ArtifactRepository localRepository = new DefaultArtifactRepository(
.toExternalForm(), defaultLayout ); "local",
localRepoDirectory.toURL().toExternalForm(),
defaultLayout );
ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM, localRepository, ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM, localRepository,
Collections.EMPTY_LIST, null ); Collections.EMPTY_LIST, null, false );
assertEquals( 3, lineage.size() ); assertEquals( 3, lineage.size() );
@ -165,6 +167,54 @@ public class DefaultModelLineageBuilderTest
assertEquals( ancestor.getId(), ( (Model) modelIterator.next() ).getId() ); assertEquals( ancestor.getId(), ( (Model) modelIterator.next() ).getId() );
} }
public void testReadPOMWithMissingParentAndAllowStubsSetToTrue()
throws IOException, ProjectBuildingException
{
// 1. create local repository directory
File localRepoDirectory = File.createTempFile( "DefaultModelLineageBuilder.localRepository.", "" );
localRepoDirectory.delete();
localRepoDirectory.mkdirs();
deleteDirOnExit( localRepoDirectory );
// 5. create the current pom with a parent-ref on the parent model
Model current = createModel( "group", "current", "1" );
Parent currentParent = new Parent();
currentParent.setGroupId( "group" );
currentParent.setArtifactId( "parent" );
currentParent.setVersion( "1" );
current.setParent( currentParent );
// 6. write the current pom somewhere
File currentPOM = File.createTempFile( "DefaultModelLineageBuilder.test.", ".pom" );
currentPOM.deleteOnExit();
writeModel( current, currentPOM );
// 7. build the lineage.
ArtifactRepository localRepository = new DefaultArtifactRepository(
"local",
localRepoDirectory.toURL().toExternalForm(),
defaultLayout );
ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM, localRepository,
Collections.EMPTY_LIST, null, true );
assertEquals( 2, lineage.size() );
Iterator modelIterator = lineage.modelIterator();
assertEquals( current.getId(), ( (Model) modelIterator.next() ).getId() );
Model parent = (Model) modelIterator.next();
assertEquals( currentParent.getGroupId(), parent.getGroupId() );
assertEquals( currentParent.getArtifactId(), parent.getArtifactId() );
assertEquals( currentParent.getVersion(), parent.getVersion() );
}
public void testReadPOMWithParentInLocalRepositoryAndAncestorInRemoteRepository() public void testReadPOMWithParentInLocalRepositoryAndAncestorInRemoteRepository()
throws IOException, ProjectBuildingException throws IOException, ProjectBuildingException
{ {
@ -219,14 +269,19 @@ public class DefaultModelLineageBuilderTest
writeModel( current, currentPOM ); writeModel( current, currentPOM );
// 7. build the lineage. // 7. build the lineage.
ArtifactRepository localRepository = new DefaultArtifactRepository( "local", localRepoDirectory.toURL() ArtifactRepository localRepository = new DefaultArtifactRepository(
.toExternalForm(), defaultLayout ); "local",
localRepoDirectory.toURL().toExternalForm(),
defaultLayout );
ArtifactRepository remoteRepository = new DefaultArtifactRepository( "test", remoteRepoDirectory.toURL() ArtifactRepository remoteRepository = new DefaultArtifactRepository( "test",
.toExternalForm(), defaultLayout ); remoteRepoDirectory.toURL()
.toExternalForm(),
defaultLayout );
ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM, localRepository, Collections ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM, localRepository,
.singletonList( remoteRepository ), null ); Collections.singletonList( remoteRepository ),
null, false );
assertEquals( 3, lineage.size() ); assertEquals( 3, lineage.size() );
@ -277,11 +332,13 @@ public class DefaultModelLineageBuilderTest
writeModel( current, currentPOM ); writeModel( current, currentPOM );
// 7. build the lineage. // 7. build the lineage.
ArtifactRepository localRepository = new DefaultArtifactRepository( "local", projectRootDirectory.toURL() ArtifactRepository localRepository = new DefaultArtifactRepository( "local",
.toExternalForm(), defaultLayout ); projectRootDirectory.toURL()
.toExternalForm(),
defaultLayout );
ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM, localRepository, ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM, localRepository,
Collections.EMPTY_LIST, null ); Collections.EMPTY_LIST, null, false );
assertEquals( 2, lineage.size() ); assertEquals( 2, lineage.size() );
@ -341,9 +398,9 @@ public class DefaultModelLineageBuilderTest
// 4. write the parent model to the local repo directory // 4. write the parent model to the local repo directory
writeModel( parent, parentPOM ); writeModel( parent, parentPOM );
BuildContextManager buildContextManager = (BuildContextManager) lookup( BuildContextManager.ROLE, "default" ); BuildContextManager buildContextManager = (BuildContextManager) lookup( BuildContextManager.ROLE, "default" );
ProjectBuildCache cache = ProjectBuildCache.read( buildContextManager ); ProjectBuildCache cache = ProjectBuildCache.read( buildContextManager );
cache.cacheModelFileForModel( parentPOM, parent ); cache.cacheModelFileForModel( parentPOM, parent );
cache.store( buildContextManager ); cache.store( buildContextManager );
@ -366,8 +423,8 @@ public class DefaultModelLineageBuilderTest
writeModel( current, currentPOM ); writeModel( current, currentPOM );
// 7. build the lineage. // 7. build the lineage.
ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM, null, Collections ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM, null, Collections.EMPTY_LIST, null,
.EMPTY_LIST, null ); false );
assertEquals( 2, lineage.size() ); assertEquals( 2, lineage.size() );

View File

@ -52,129 +52,129 @@ public class DefaultModelInheritanceAssemblerTest
extends TestCase extends TestCase
{ {
private ModelInheritanceAssembler assembler = new DefaultModelInheritanceAssembler(); private ModelInheritanceAssembler assembler = new DefaultModelInheritanceAssembler();
public void testShouldAdjustChildUrlBasedOnParentAndModulePathInSiblingDir() public void testShouldAdjustChildUrlBasedOnParentAndModulePathInSiblingDir()
{ {
Model parent = makeBaseModel( "parent" ); Model parent = makeBaseModel( "parent" );
parent.setUrl( "http://www.google.com/parent" ); parent.setUrl( "http://www.google.com/parent" );
Model child = makeBaseModel( "child" ); Model child = makeBaseModel( "child" );
// TODO: this is probably what we should be appending... // TODO: this is probably what we should be appending...
// child.setUrl( "/child.dir" ); // child.setUrl( "/child.dir" );
parent.addModule( "../child" ); parent.addModule( "../child" );
assembler.assembleModelInheritance( child, parent, ".." ); assembler.assembleModelInheritance( child, parent, ".." );
String resultingUrl = child.getUrl(); String resultingUrl = child.getUrl();
System.out.println( resultingUrl ); System.out.println( resultingUrl );
assertEquals( "http://www.google.com/child", resultingUrl ); assertEquals( "http://www.google.com/child", resultingUrl );
} }
public void testShouldAdjustPathsThreeLevelsDeepAncestryInRepoAndNonStandardModulePaths() public void testShouldAdjustPathsThreeLevelsDeepAncestryInRepoAndNonStandardModulePaths()
{ {
Model top = makeBaseModel( "top" ); Model top = makeBaseModel( "top" );
top.setUrl( "http://www.google.com/top" ); top.setUrl( "http://www.google.com/top" );
Model middle = makeBaseModel( "middle" ); Model middle = makeBaseModel( "middle" );
top.addModule( "../middle" ); top.addModule( "../middle" );
Model bottom = makeBaseModel( "bottom" ); Model bottom = makeBaseModel( "bottom" );
middle.addModule( "../bottom" ); middle.addModule( "../bottom" );
assembler.assembleModelInheritance( middle, top, ".." ); assembler.assembleModelInheritance( middle, top, ".." );
assembler.assembleModelInheritance( bottom, middle, ".." ); assembler.assembleModelInheritance( bottom, middle, ".." );
String resultingUrl = bottom.getUrl(); String resultingUrl = bottom.getUrl();
System.out.println( resultingUrl ); System.out.println( resultingUrl );
assertEquals( "http://www.google.com/bottom", resultingUrl ); assertEquals( "http://www.google.com/bottom", resultingUrl );
} }
public void testShouldMergeSuccessiveDependencyManagementSectionsOverThreeLevels() public void testShouldMergeSuccessiveDependencyManagementSectionsOverThreeLevels()
{ {
Model top = makeBaseModel( "top" ); Model top = makeBaseModel( "top" );
DependencyManagement topMgmt = new DependencyManagement(); DependencyManagement topMgmt = new DependencyManagement();
topMgmt.addDependency( makeDep( "top-dep" ) ); topMgmt.addDependency( makeDep( "top-dep" ) );
top.setDependencyManagement( topMgmt ); top.setDependencyManagement( topMgmt );
Model mid = makeBaseModel( "mid" ); Model mid = makeBaseModel( "mid" );
DependencyManagement midMgmt = new DependencyManagement(); DependencyManagement midMgmt = new DependencyManagement();
midMgmt.addDependency( makeDep( "mid-dep" ) ); midMgmt.addDependency( makeDep( "mid-dep" ) );
mid.setDependencyManagement( midMgmt ); mid.setDependencyManagement( midMgmt );
Model bottom = makeBaseModel( "bottom" ); Model bottom = makeBaseModel( "bottom" );
DependencyManagement bottomMgmt = new DependencyManagement(); DependencyManagement bottomMgmt = new DependencyManagement();
bottomMgmt.addDependency( makeDep( "bottom-dep" ) ); bottomMgmt.addDependency( makeDep( "bottom-dep" ) );
bottom.setDependencyManagement( bottomMgmt ); bottom.setDependencyManagement( bottomMgmt );
assembler.assembleModelInheritance( mid, top ); assembler.assembleModelInheritance( mid, top );
assembler.assembleModelInheritance( bottom, mid ); assembler.assembleModelInheritance( bottom, mid );
DependencyManagement result = bottom.getDependencyManagement(); DependencyManagement result = bottom.getDependencyManagement();
List resultDeps = result.getDependencies(); List resultDeps = result.getDependencies();
assertEquals( 3, resultDeps.size() ); assertEquals( 3, resultDeps.size() );
} }
public void testShouldMergeDependencyManagementSectionsFromTopTwoLevelsToBottomLevel() public void testShouldMergeDependencyManagementSectionsFromTopTwoLevelsToBottomLevel()
{ {
Model top = makeBaseModel( "top" ); Model top = makeBaseModel( "top" );
DependencyManagement topMgmt = new DependencyManagement(); DependencyManagement topMgmt = new DependencyManagement();
topMgmt.addDependency( makeDep( "top-dep" ) ); topMgmt.addDependency( makeDep( "top-dep" ) );
top.setDependencyManagement( topMgmt ); top.setDependencyManagement( topMgmt );
Model mid = makeBaseModel( "mid" ); Model mid = makeBaseModel( "mid" );
DependencyManagement midMgmt = new DependencyManagement(); DependencyManagement midMgmt = new DependencyManagement();
midMgmt.addDependency( makeDep( "mid-dep" ) ); midMgmt.addDependency( makeDep( "mid-dep" ) );
mid.setDependencyManagement( midMgmt ); mid.setDependencyManagement( midMgmt );
Model bottom = makeBaseModel( "bottom" ); Model bottom = makeBaseModel( "bottom" );
assembler.assembleModelInheritance( mid, top ); assembler.assembleModelInheritance( mid, top );
assembler.assembleModelInheritance( bottom, mid ); assembler.assembleModelInheritance( bottom, mid );
DependencyManagement result = bottom.getDependencyManagement(); DependencyManagement result = bottom.getDependencyManagement();
List resultDeps = result.getDependencies(); List resultDeps = result.getDependencies();
assertEquals( 2, resultDeps.size() ); assertEquals( 2, resultDeps.size() );
} }
private Dependency makeDep( String artifactId ) private Dependency makeDep( String artifactId )
{ {
Dependency dep = new Dependency(); Dependency dep = new Dependency();
dep.setGroupId( "maven" ); dep.setGroupId( "maven" );
dep.setArtifactId( artifactId ); dep.setArtifactId( artifactId );
dep.setVersion( "1.0" ); dep.setVersion( "1.0" );
return dep; return dep;
} }
@ -274,6 +274,62 @@ public class DefaultModelInheritanceAssemblerTest
childDistMgmt.getSnapshotRepository().isUniqueVersion() ); childDistMgmt.getSnapshotRepository().isUniqueVersion() );
} }
public void testThreeLevelDistributionManagementInheritance()
{
Model gpar = makeBaseModel( "gpar" );
Model parent = makeBaseModel( "parent" );
Model child = makeBaseModel( "child" );
DistributionManagement distributionManagement = new DistributionManagement();
distributionManagement.setDownloadUrl( "downloadUrl" );
distributionManagement.setRelocation( new Relocation() );
distributionManagement.setStatus( "deployed" );
DeploymentRepository repository = new DeploymentRepository();
repository.setId( "apache.releases" );
repository.setUrl( "scp://minotaur.apache.org/www/www.apache.org/dist/java-repository" );
repository.setName( "name" );
repository.setLayout( "legacy" );
distributionManagement.setRepository( repository );
DeploymentRepository snapshotRepository = new DeploymentRepository();
snapshotRepository.setId( "apache.snapshots" );
snapshotRepository.setUrl( "scp://minotaur.apache.org/www/cvs.apache.org/repository" );
snapshotRepository.setName( "name" );
snapshotRepository.setLayout( "legacy" );
snapshotRepository.setUniqueVersion( false );
distributionManagement.setSnapshotRepository( snapshotRepository );
Site site = new Site();
site.setId( "apache.website" );
site.setUrl( "scp://minotaur.apache.org/www/maven.apache.org/" );
site.setName( "name3" );
distributionManagement.setSite( site );
gpar.setDistributionManagement( distributionManagement );
assembler.assembleModelInheritance( parent, gpar );
assembler.assembleModelInheritance( child, parent );
DistributionManagement childDistMgmt = child.getDistributionManagement();
assertNotNull( "Check distMgmt inherited", childDistMgmt );
assertNull( "Check status NOT inherited", childDistMgmt.getStatus() );
assertNull( "Check relocation NOT inherited", childDistMgmt.getRelocation() );
assertEquals( "Check downloadUrl inherited", distributionManagement.getDownloadUrl(),
childDistMgmt.getDownloadUrl() );
Site childSite = childDistMgmt.getSite();
assertNotNull( "Check site inherited", childSite );
assertEquals( "Check id matches", site.getId(), childSite.getId() );
assertEquals( "Check name matches", site.getName(), childSite.getName() );
assertEquals( "Check url matches with appended path", site.getUrl() + "parent/child", childSite.getUrl() );
assertRepositoryBase( childDistMgmt.getRepository(), repository );
assertRepositoryBase( childDistMgmt.getSnapshotRepository(), snapshotRepository );
assertEquals( "Check uniqueVersion is inherited", snapshotRepository.isUniqueVersion(),
childDistMgmt.getSnapshotRepository().isUniqueVersion() );
}
private static void assertRepositoryBase( RepositoryBase childRepository, RepositoryBase repository ) private static void assertRepositoryBase( RepositoryBase childRepository, RepositoryBase repository )
{ {
assertNotNull( "Check repository inherited", childRepository ); assertNotNull( "Check repository inherited", childRepository );
@ -590,7 +646,7 @@ public class DefaultModelInheritanceAssemblerTest
{ {
Build childBuild = child.getBuild(); Build childBuild = child.getBuild();
if ( expectedPlugins != null && !expectedPlugins.isEmpty() ) if ( ( expectedPlugins != null ) && !expectedPlugins.isEmpty() )
{ {
assertNotNull( childBuild ); assertNotNull( childBuild );
@ -616,7 +672,7 @@ public class DefaultModelInheritanceAssemblerTest
} }
else else
{ {
assertTrue( childBuild == null || childBuild.getPlugins() == null || childBuild.getPlugins().isEmpty() ); assertTrue( ( childBuild == null ) || ( childBuild.getPlugins() == null ) || childBuild.getPlugins().isEmpty() );
} }
} }
@ -628,9 +684,9 @@ public class DefaultModelInheritanceAssemblerTest
List referenceExecutions = reference.getExecutions(); List referenceExecutions = reference.getExecutions();
Map testExecutionsMap = test.getExecutionsAsMap(); Map testExecutionsMap = test.getExecutionsAsMap();
if ( referenceExecutions != null && !referenceExecutions.isEmpty() ) if ( ( referenceExecutions != null ) && !referenceExecutions.isEmpty() )
{ {
assertTrue( "Missing goals specification", ( testExecutionsMap != null && !testExecutionsMap.isEmpty() ) ); assertTrue( "Missing goals specification", ( ( testExecutionsMap != null ) && !testExecutionsMap.isEmpty() ) );
for ( Iterator it = referenceExecutions.iterator(); it.hasNext(); ) for ( Iterator it = referenceExecutions.iterator(); it.hasNext(); )
{ {
@ -648,7 +704,7 @@ public class DefaultModelInheritanceAssemblerTest
else else
{ {
assertTrue( "Unexpected goals specification", assertTrue( "Unexpected goals specification",
( testExecutionsMap == null || testExecutionsMap.isEmpty() ) ); ( ( testExecutionsMap == null ) || testExecutionsMap.isEmpty() ) );
} }
} }
@ -750,7 +806,7 @@ public class DefaultModelInheritanceAssemblerTest
{ {
Reporting childBuild = child.getReporting(); Reporting childBuild = child.getReporting();
if ( expectedPlugins != null && !expectedPlugins.isEmpty() ) if ( ( expectedPlugins != null ) && !expectedPlugins.isEmpty() )
{ {
assertNotNull( childBuild ); assertNotNull( childBuild );
@ -776,7 +832,7 @@ public class DefaultModelInheritanceAssemblerTest
} }
else else
{ {
assertTrue( childBuild == null || childBuild.getPlugins() == null || childBuild.getPlugins().isEmpty() ); assertTrue( ( childBuild == null ) || ( childBuild.getPlugins() == null ) || childBuild.getPlugins().isEmpty() );
} }
} }
@ -788,9 +844,9 @@ public class DefaultModelInheritanceAssemblerTest
List referenceReportSets = reference.getReportSets(); List referenceReportSets = reference.getReportSets();
Map testReportSetsMap = test.getReportSetsAsMap(); Map testReportSetsMap = test.getReportSetsAsMap();
if ( referenceReportSets != null && !referenceReportSets.isEmpty() ) if ( ( referenceReportSets != null ) && !referenceReportSets.isEmpty() )
{ {
assertTrue( "Missing goals specification", ( testReportSetsMap != null && !testReportSetsMap.isEmpty() ) ); assertTrue( "Missing goals specification", ( ( testReportSetsMap != null ) && !testReportSetsMap.isEmpty() ) );
for ( Iterator it = referenceReportSets.iterator(); it.hasNext(); ) for ( Iterator it = referenceReportSets.iterator(); it.hasNext(); )
{ {
@ -808,7 +864,7 @@ public class DefaultModelInheritanceAssemblerTest
else else
{ {
assertTrue( "Unexpected goals specification", assertTrue( "Unexpected goals specification",
( testReportSetsMap == null || testReportSetsMap.isEmpty() ) ); ( ( testReportSetsMap == null ) || testReportSetsMap.isEmpty() ) );
} }
} }
@ -851,7 +907,7 @@ public class DefaultModelInheritanceAssemblerTest
{ {
Model model = makeBaseModel( artifactId ); Model model = makeBaseModel( artifactId );
if ( connection != null || developerConnection != null || url != null ) if ( ( connection != null ) || ( developerConnection != null ) || ( url != null ) )
{ {
Scm scm = new Scm(); Scm scm = new Scm();