mirror of https://github.com/apache/maven.git
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:
parent
1d58a421ce
commit
c5a74a8242
|
@ -330,7 +330,7 @@ public class DefaultBuildExtensionScanner
|
|||
getLogger().debug( "Building model-lineage for: " + pom + " to pre-scan for extensions." );
|
||||
|
||||
lineage = modelLineageBuilder.buildModelLineage( pom, localRepository, originalRemoteRepositories,
|
||||
globalProfileManager );
|
||||
globalProfileManager, false );
|
||||
}
|
||||
catch ( ProjectBuildingException e )
|
||||
{
|
||||
|
|
|
@ -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( "[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 );
|
||||
|
||||
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;
|
||||
previousProject = currentProject;
|
||||
|
@ -1054,7 +1054,8 @@ public class DefaultMavenProjectBuilder
|
|||
ModelLineage modelLineage = new DefaultModelLineage();
|
||||
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 );
|
||||
|
||||
|
@ -1080,8 +1081,6 @@ public class DefaultMavenProjectBuilder
|
|||
{
|
||||
Model currentModel = (Model) it.next();
|
||||
|
||||
getLogger().debug( "[assembleLineage] Assembling MavenProject instance for: " + currentModel.getId() );
|
||||
|
||||
File currentPom = it.getPOMFile();
|
||||
|
||||
MavenProject project = new MavenProject( currentModel );
|
||||
|
|
|
@ -45,7 +45,7 @@ public class DefaultModelLineage
|
|||
{
|
||||
throw new IllegalStateException( "You must call setOrigin(..) before adding a parent to the lineage." );
|
||||
}
|
||||
|
||||
|
||||
tuples.add( new ModelLineageTuple( model, pomFile, artifactRepositories ) );
|
||||
}
|
||||
|
||||
|
@ -123,18 +123,18 @@ public class DefaultModelLineage
|
|||
{
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
|
||||
List tuplesInReverse = new ArrayList( tuples );
|
||||
Collections.reverse( tuplesInReverse );
|
||||
|
||||
|
||||
List results = new ArrayList( tuplesInReverse.size() );
|
||||
for ( Iterator it = tuplesInReverse.iterator(); it.hasNext(); )
|
||||
{
|
||||
ModelLineageTuple tuple = (ModelLineageTuple) it.next();
|
||||
|
||||
|
||||
results.add( tuple.remoteRepositories );
|
||||
}
|
||||
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
|
@ -156,18 +156,18 @@ public class DefaultModelLineage
|
|||
{
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
|
||||
List tuplesInReverse = new ArrayList( tuples );
|
||||
Collections.reverse( tuplesInReverse );
|
||||
|
||||
|
||||
List results = new ArrayList( tuplesInReverse.size() );
|
||||
for ( Iterator it = tuplesInReverse.iterator(); it.hasNext(); )
|
||||
{
|
||||
ModelLineageTuple tuple = (ModelLineageTuple) it.next();
|
||||
|
||||
|
||||
results.add( tuple.file );
|
||||
}
|
||||
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
|
@ -177,18 +177,18 @@ public class DefaultModelLineage
|
|||
{
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
|
||||
List tuplesInReverse = new ArrayList( tuples );
|
||||
Collections.reverse( tuplesInReverse );
|
||||
|
||||
|
||||
List results = new ArrayList( tuplesInReverse.size() );
|
||||
for ( Iterator it = tuplesInReverse.iterator(); it.hasNext(); )
|
||||
{
|
||||
ModelLineageTuple tuple = (ModelLineageTuple) it.next();
|
||||
|
||||
|
||||
results.add( tuple.model );
|
||||
}
|
||||
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
|
@ -198,9 +198,9 @@ public class DefaultModelLineage
|
|||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( 0 );
|
||||
|
||||
|
||||
return tuple.remoteRepositories;
|
||||
}
|
||||
|
||||
|
@ -210,9 +210,9 @@ public class DefaultModelLineage
|
|||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( 0 );
|
||||
|
||||
|
||||
return tuple.model;
|
||||
}
|
||||
|
||||
|
@ -222,45 +222,45 @@ public class DefaultModelLineage
|
|||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( 0 );
|
||||
|
||||
|
||||
return tuple.file;
|
||||
}
|
||||
|
||||
public List getDeepestArtifactRepositoryList()
|
||||
public List getDeepestAncestorArtifactRepositoryList()
|
||||
{
|
||||
if ( tuples.isEmpty() )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( tuples.size() - 1 );
|
||||
|
||||
|
||||
return tuple.remoteRepositories;
|
||||
}
|
||||
|
||||
public File getDeepestFile()
|
||||
public File getDeepestAncestorFile()
|
||||
{
|
||||
if ( tuples.isEmpty() )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( tuples.size() - 1 );
|
||||
|
||||
|
||||
return tuple.file;
|
||||
}
|
||||
|
||||
public Model getDeepestModel()
|
||||
public Model getDeepestAncestorModel()
|
||||
{
|
||||
if ( tuples.isEmpty() )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( tuples.size() - 1 );
|
||||
|
||||
|
||||
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." );
|
||||
}
|
||||
|
||||
|
||||
tuples.add( new ModelLineageTuple( model, pomFile, artifactRepositories ) );
|
||||
}
|
||||
|
||||
|
@ -309,7 +309,7 @@ public class DefaultModelLineage
|
|||
{
|
||||
return tuples.size();
|
||||
}
|
||||
|
||||
|
||||
private static final class ModelLineageTuple
|
||||
{
|
||||
private Model model;
|
||||
|
|
|
@ -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)
|
||||
*/
|
||||
public ModelLineage buildModelLineage( File pom, ArtifactRepository localRepository, List remoteRepositories,
|
||||
ProfileManager profileManager )
|
||||
ProfileManager profileManager, boolean allowStubs )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
ProjectBuildCache projectBuildCache = ProjectBuildCache.read( buildContextManager );
|
||||
|
@ -99,7 +99,7 @@ public class DefaultModelLineageBuilder
|
|||
|
||||
ModelAndFile current = new ModelAndFile( readModel( pom, projectBuildCache ), pom );
|
||||
|
||||
while ( current != null )
|
||||
do
|
||||
{
|
||||
if ( lineage.size() == 0 )
|
||||
{
|
||||
|
@ -112,44 +112,43 @@ public class DefaultModelLineageBuilder
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
public void resumeBuildingModelLineage( ModelLineage lineage, ArtifactRepository localRepository,
|
||||
ProfileManager profileManager )
|
||||
ProfileManager profileManager, boolean allowStubs )
|
||||
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 );
|
||||
|
||||
List currentRemoteRepositories = lineage.getDeepestArtifactRepositoryList();
|
||||
List currentRemoteRepositories = lineage.getDeepestAncestorArtifactRepositoryList();
|
||||
|
||||
if ( currentRemoteRepositories == null )
|
||||
{
|
||||
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...
|
||||
current = resolveParentPom( current, currentRemoteRepositories, localRepository, projectBuildCache );
|
||||
current = resolveParentPom( current, currentRemoteRepositories, localRepository, projectBuildCache, allowStubs );
|
||||
|
||||
while ( current != null )
|
||||
{
|
||||
if ( lineage.size() == 0 )
|
||||
{
|
||||
lineage.setOrigin( current.model, current.file, currentRemoteRepositories );
|
||||
}
|
||||
else
|
||||
{
|
||||
lineage.addParent( current.model, current.file, currentRemoteRepositories );
|
||||
}
|
||||
lineage.addParent( current.model, current.file, currentRemoteRepositories );
|
||||
|
||||
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
|
||||
* resolve that artifact...then, return the resolved POM file for the parent.
|
||||
* @param projectBuildCache
|
||||
* @param allowStubs
|
||||
*/
|
||||
private ModelAndFile resolveParentPom( ModelAndFile child, List remoteRepositories, ArtifactRepository localRepository,
|
||||
ProjectBuildCache projectBuildCache )
|
||||
ProjectBuildCache projectBuildCache, boolean allowStubs )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
Model model = child.model;
|
||||
|
@ -304,9 +304,7 @@ public class DefaultModelLineageBuilder
|
|||
|
||||
if ( modelParent != null )
|
||||
{
|
||||
validateParentDeclaration( modelParent, model );
|
||||
|
||||
// getLogger().debug( "Looking for cached parent POM under: " + cacheKey );
|
||||
validateParentDeclaration( modelParent, model );
|
||||
|
||||
File parentPomFile = projectBuildCache.getCachedModelFile( modelParent );
|
||||
|
||||
|
@ -317,26 +315,48 @@ public class DefaultModelLineageBuilder
|
|||
|
||||
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 )
|
||||
{
|
||||
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.setArtifactId( modelParent.getArtifactId() );
|
||||
parent.setVersion( modelParent.getVersion() );
|
||||
parent.setGroupId( modelParent.getGroupId() );
|
||||
parent.setArtifactId( modelParent.getArtifactId() );
|
||||
parent.setVersion( modelParent.getVersion() );
|
||||
|
||||
result = new ModelAndFile( parent, parentPomFile );
|
||||
}
|
||||
else
|
||||
{
|
||||
getLogger().error( "Cannot find parent POM: " + modelParent.getId() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
parent = readModel( parentPomFile );
|
||||
Model parent = readModel( parentPomFile );
|
||||
result = new ModelAndFile( parent, parentPomFile );
|
||||
}
|
||||
|
||||
result = new ModelAndFile( parent, parentPomFile );
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -28,56 +28,56 @@ import java.util.List;
|
|||
/**
|
||||
* Tracks information from a current POM and its ancestors, including Model instances, associated
|
||||
* POM files, and repository lists used to resolve each model.
|
||||
*
|
||||
*
|
||||
* @author jdcasey
|
||||
*
|
||||
*/
|
||||
public interface ModelLineage
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the Model instance for the deepest ancestor which has been resolved so far in this
|
||||
* lineage.
|
||||
*/
|
||||
Model getDeepestModel();
|
||||
|
||||
Model getDeepestAncestorModel();
|
||||
|
||||
/**
|
||||
* Retrieve the POM file for the deepest ancestor which has been resolved so far in this
|
||||
* 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.
|
||||
*/
|
||||
List getDeepestArtifactRepositoryList();
|
||||
|
||||
List getDeepestAncestorArtifactRepositoryList();
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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
|
||||
* thing).
|
||||
*/
|
||||
Model getOriginatingModel();
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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
|
||||
* thing).
|
||||
*/
|
||||
File getOriginatingPOMFile();
|
||||
|
||||
|
||||
/**
|
||||
* 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,
|
||||
* 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,
|
||||
* or the current POM, or the child (all means the same thing).
|
||||
*/
|
||||
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.
|
||||
*
|
||||
*
|
||||
* @throws IllegalStateException When the originating POM information has already been set.
|
||||
*/
|
||||
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.
|
||||
* 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.
|
||||
*/
|
||||
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
|
||||
* POM at the last index.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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
|
||||
* 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.
|
||||
*/
|
||||
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
|
||||
* 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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
Iterator artifactRepositoryListIterator();
|
||||
|
@ -149,7 +149,7 @@ public interface ModelLineage
|
|||
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().
|
||||
*/
|
||||
List getArtifactRepositories( Model model );
|
||||
|
|
|
@ -29,7 +29,7 @@ import java.util.List;
|
|||
/**
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
@ -39,33 +39,37 @@ public interface ModelLineageBuilder
|
|||
String ROLE = ModelLineageBuilder.class.getName();
|
||||
|
||||
/**
|
||||
* Construct a lineage of the current POM plus all of its ancestors.
|
||||
*
|
||||
* COMING: Also, set ProjectBuildContext.currentModelLineage build-context to the result of this
|
||||
* Construct a lineage of the current POM plus all of its ancestors.
|
||||
*
|
||||
* COMING: Also, set ProjectBuildContext.currentModelLineage build-context to the result of this
|
||||
* method before returning.
|
||||
*
|
||||
*
|
||||
* @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 remoteRepositories List of ArtifactRepository instances against which parent POMs
|
||||
* @param remoteRepositories List of ArtifactRepository instances against which parent POMs
|
||||
* should be resolved
|
||||
* @param profileManager The profile manager containing information about global profiles to be
|
||||
* 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,
|
||||
ProfileManager profileManager )
|
||||
ProfileManager profileManager, boolean allowStubs )
|
||||
throws ProjectBuildingException;
|
||||
|
||||
/**
|
||||
* Resume the process of constructing a lineage of inherited models, picking up using the deepest
|
||||
* parent already in the lineage.
|
||||
*
|
||||
*
|
||||
* @param lineage The ModelLineage instance in progress, which should be completed.
|
||||
* @param localRepository The local repository against which parent POMs should be resolved
|
||||
* @param profileManager The profile manager containing information about global profiles to be
|
||||
* 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,
|
||||
ProfileManager profileManager )
|
||||
ProfileManager profileManager, boolean allowStubs )
|
||||
throws ProjectBuildingException;
|
||||
|
||||
}
|
||||
|
|
|
@ -58,13 +58,13 @@ public class DefaultModelLineageBuilderTest
|
|||
|
||||
defaultLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
|
||||
}
|
||||
|
||||
|
||||
public void tearDown()
|
||||
throws Exception
|
||||
{
|
||||
BuildContextManager ctxMgr = (BuildContextManager) lookup( BuildContextManager.ROLE );
|
||||
ctxMgr.clearBuildContext();
|
||||
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ public class DefaultModelLineageBuilderTest
|
|||
IOUtil.close( writer );
|
||||
}
|
||||
|
||||
ModelLineage lineage = modelLineageBuilder.buildModelLineage( pomFile, null, null, null );
|
||||
ModelLineage lineage = modelLineageBuilder.buildModelLineage( pomFile, null, null, null, false );
|
||||
|
||||
assertEquals( 1, lineage.size() );
|
||||
|
||||
|
@ -150,11 +150,13 @@ public class DefaultModelLineageBuilderTest
|
|||
writeModel( current, currentPOM );
|
||||
|
||||
// 7. build the lineage.
|
||||
ArtifactRepository localRepository = new DefaultArtifactRepository( "local", localRepoDirectory.toURL()
|
||||
.toExternalForm(), defaultLayout );
|
||||
ArtifactRepository localRepository = new DefaultArtifactRepository(
|
||||
"local",
|
||||
localRepoDirectory.toURL().toExternalForm(),
|
||||
defaultLayout );
|
||||
|
||||
ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM, localRepository,
|
||||
Collections.EMPTY_LIST, null );
|
||||
Collections.EMPTY_LIST, null, false );
|
||||
|
||||
assertEquals( 3, lineage.size() );
|
||||
|
||||
|
@ -165,6 +167,54 @@ public class DefaultModelLineageBuilderTest
|
|||
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()
|
||||
throws IOException, ProjectBuildingException
|
||||
{
|
||||
|
@ -219,14 +269,19 @@ public class DefaultModelLineageBuilderTest
|
|||
writeModel( current, currentPOM );
|
||||
|
||||
// 7. build the lineage.
|
||||
ArtifactRepository localRepository = new DefaultArtifactRepository( "local", localRepoDirectory.toURL()
|
||||
.toExternalForm(), defaultLayout );
|
||||
ArtifactRepository localRepository = new DefaultArtifactRepository(
|
||||
"local",
|
||||
localRepoDirectory.toURL().toExternalForm(),
|
||||
defaultLayout );
|
||||
|
||||
ArtifactRepository remoteRepository = new DefaultArtifactRepository( "test", remoteRepoDirectory.toURL()
|
||||
.toExternalForm(), defaultLayout );
|
||||
ArtifactRepository remoteRepository = new DefaultArtifactRepository( "test",
|
||||
remoteRepoDirectory.toURL()
|
||||
.toExternalForm(),
|
||||
defaultLayout );
|
||||
|
||||
ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM, localRepository, Collections
|
||||
.singletonList( remoteRepository ), null );
|
||||
ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM, localRepository,
|
||||
Collections.singletonList( remoteRepository ),
|
||||
null, false );
|
||||
|
||||
assertEquals( 3, lineage.size() );
|
||||
|
||||
|
@ -277,11 +332,13 @@ public class DefaultModelLineageBuilderTest
|
|||
writeModel( current, currentPOM );
|
||||
|
||||
// 7. build the lineage.
|
||||
ArtifactRepository localRepository = new DefaultArtifactRepository( "local", projectRootDirectory.toURL()
|
||||
.toExternalForm(), defaultLayout );
|
||||
ArtifactRepository localRepository = new DefaultArtifactRepository( "local",
|
||||
projectRootDirectory.toURL()
|
||||
.toExternalForm(),
|
||||
defaultLayout );
|
||||
|
||||
ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM, localRepository,
|
||||
Collections.EMPTY_LIST, null );
|
||||
Collections.EMPTY_LIST, null, false );
|
||||
|
||||
assertEquals( 2, lineage.size() );
|
||||
|
||||
|
@ -341,9 +398,9 @@ public class DefaultModelLineageBuilderTest
|
|||
|
||||
// 4. write the parent model to the local repo directory
|
||||
writeModel( parent, parentPOM );
|
||||
|
||||
|
||||
BuildContextManager buildContextManager = (BuildContextManager) lookup( BuildContextManager.ROLE, "default" );
|
||||
|
||||
|
||||
ProjectBuildCache cache = ProjectBuildCache.read( buildContextManager );
|
||||
cache.cacheModelFileForModel( parentPOM, parent );
|
||||
cache.store( buildContextManager );
|
||||
|
@ -366,8 +423,8 @@ public class DefaultModelLineageBuilderTest
|
|||
writeModel( current, currentPOM );
|
||||
|
||||
// 7. build the lineage.
|
||||
ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM, null, Collections
|
||||
.EMPTY_LIST, null );
|
||||
ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM, null, Collections.EMPTY_LIST, null,
|
||||
false );
|
||||
|
||||
assertEquals( 2, lineage.size() );
|
||||
|
||||
|
|
|
@ -52,129 +52,129 @@ public class DefaultModelInheritanceAssemblerTest
|
|||
extends TestCase
|
||||
{
|
||||
private ModelInheritanceAssembler assembler = new DefaultModelInheritanceAssembler();
|
||||
|
||||
|
||||
public void testShouldAdjustChildUrlBasedOnParentAndModulePathInSiblingDir()
|
||||
{
|
||||
Model parent = makeBaseModel( "parent" );
|
||||
|
||||
|
||||
parent.setUrl( "http://www.google.com/parent" );
|
||||
|
||||
|
||||
Model child = makeBaseModel( "child" );
|
||||
|
||||
|
||||
// TODO: this is probably what we should be appending...
|
||||
// child.setUrl( "/child.dir" );
|
||||
|
||||
|
||||
parent.addModule( "../child" );
|
||||
|
||||
|
||||
assembler.assembleModelInheritance( child, parent, ".." );
|
||||
|
||||
|
||||
String resultingUrl = child.getUrl();
|
||||
|
||||
|
||||
System.out.println( resultingUrl );
|
||||
|
||||
|
||||
assertEquals( "http://www.google.com/child", resultingUrl );
|
||||
}
|
||||
|
||||
|
||||
public void testShouldAdjustPathsThreeLevelsDeepAncestryInRepoAndNonStandardModulePaths()
|
||||
{
|
||||
Model top = makeBaseModel( "top" );
|
||||
|
||||
|
||||
top.setUrl( "http://www.google.com/top" );
|
||||
|
||||
|
||||
Model middle = makeBaseModel( "middle" );
|
||||
|
||||
|
||||
top.addModule( "../middle" );
|
||||
|
||||
|
||||
Model bottom = makeBaseModel( "bottom" );
|
||||
|
||||
|
||||
middle.addModule( "../bottom" );
|
||||
|
||||
|
||||
assembler.assembleModelInheritance( middle, top, ".." );
|
||||
assembler.assembleModelInheritance( bottom, middle, ".." );
|
||||
|
||||
|
||||
String resultingUrl = bottom.getUrl();
|
||||
|
||||
|
||||
System.out.println( resultingUrl );
|
||||
|
||||
|
||||
assertEquals( "http://www.google.com/bottom", resultingUrl );
|
||||
}
|
||||
|
||||
|
||||
public void testShouldMergeSuccessiveDependencyManagementSectionsOverThreeLevels()
|
||||
{
|
||||
Model top = makeBaseModel( "top" );
|
||||
|
||||
|
||||
DependencyManagement topMgmt = new DependencyManagement();
|
||||
|
||||
|
||||
topMgmt.addDependency( makeDep( "top-dep" ) );
|
||||
|
||||
|
||||
top.setDependencyManagement( topMgmt );
|
||||
|
||||
|
||||
Model mid = makeBaseModel( "mid" );
|
||||
|
||||
|
||||
DependencyManagement midMgmt = new DependencyManagement();
|
||||
|
||||
|
||||
midMgmt.addDependency( makeDep( "mid-dep" ) );
|
||||
|
||||
|
||||
mid.setDependencyManagement( midMgmt );
|
||||
|
||||
|
||||
Model bottom = makeBaseModel( "bottom" );
|
||||
|
||||
|
||||
DependencyManagement bottomMgmt = new DependencyManagement();
|
||||
|
||||
|
||||
bottomMgmt.addDependency( makeDep( "bottom-dep" ) );
|
||||
|
||||
|
||||
bottom.setDependencyManagement( bottomMgmt );
|
||||
|
||||
|
||||
assembler.assembleModelInheritance( mid, top );
|
||||
|
||||
|
||||
assembler.assembleModelInheritance( bottom, mid );
|
||||
|
||||
|
||||
DependencyManagement result = bottom.getDependencyManagement();
|
||||
|
||||
|
||||
List resultDeps = result.getDependencies();
|
||||
|
||||
|
||||
assertEquals( 3, resultDeps.size() );
|
||||
}
|
||||
|
||||
|
||||
public void testShouldMergeDependencyManagementSectionsFromTopTwoLevelsToBottomLevel()
|
||||
{
|
||||
Model top = makeBaseModel( "top" );
|
||||
|
||||
|
||||
DependencyManagement topMgmt = new DependencyManagement();
|
||||
|
||||
|
||||
topMgmt.addDependency( makeDep( "top-dep" ) );
|
||||
|
||||
|
||||
top.setDependencyManagement( topMgmt );
|
||||
|
||||
|
||||
Model mid = makeBaseModel( "mid" );
|
||||
|
||||
|
||||
DependencyManagement midMgmt = new DependencyManagement();
|
||||
|
||||
|
||||
midMgmt.addDependency( makeDep( "mid-dep" ) );
|
||||
|
||||
|
||||
mid.setDependencyManagement( midMgmt );
|
||||
|
||||
|
||||
Model bottom = makeBaseModel( "bottom" );
|
||||
|
||||
|
||||
assembler.assembleModelInheritance( mid, top );
|
||||
|
||||
|
||||
assembler.assembleModelInheritance( bottom, mid );
|
||||
|
||||
|
||||
DependencyManagement result = bottom.getDependencyManagement();
|
||||
|
||||
|
||||
List resultDeps = result.getDependencies();
|
||||
|
||||
|
||||
assertEquals( 2, resultDeps.size() );
|
||||
}
|
||||
|
||||
|
||||
private Dependency makeDep( String artifactId )
|
||||
{
|
||||
Dependency dep = new Dependency();
|
||||
|
||||
|
||||
dep.setGroupId( "maven" );
|
||||
dep.setArtifactId( artifactId );
|
||||
dep.setVersion( "1.0" );
|
||||
|
||||
|
||||
return dep;
|
||||
}
|
||||
|
||||
|
@ -274,6 +274,62 @@ public class DefaultModelInheritanceAssemblerTest
|
|||
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 )
|
||||
{
|
||||
assertNotNull( "Check repository inherited", childRepository );
|
||||
|
@ -590,7 +646,7 @@ public class DefaultModelInheritanceAssemblerTest
|
|||
{
|
||||
Build childBuild = child.getBuild();
|
||||
|
||||
if ( expectedPlugins != null && !expectedPlugins.isEmpty() )
|
||||
if ( ( expectedPlugins != null ) && !expectedPlugins.isEmpty() )
|
||||
{
|
||||
assertNotNull( childBuild );
|
||||
|
||||
|
@ -616,7 +672,7 @@ public class DefaultModelInheritanceAssemblerTest
|
|||
}
|
||||
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();
|
||||
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(); )
|
||||
{
|
||||
|
@ -648,7 +704,7 @@ public class DefaultModelInheritanceAssemblerTest
|
|||
else
|
||||
{
|
||||
assertTrue( "Unexpected goals specification",
|
||||
( testExecutionsMap == null || testExecutionsMap.isEmpty() ) );
|
||||
( ( testExecutionsMap == null ) || testExecutionsMap.isEmpty() ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -750,7 +806,7 @@ public class DefaultModelInheritanceAssemblerTest
|
|||
{
|
||||
Reporting childBuild = child.getReporting();
|
||||
|
||||
if ( expectedPlugins != null && !expectedPlugins.isEmpty() )
|
||||
if ( ( expectedPlugins != null ) && !expectedPlugins.isEmpty() )
|
||||
{
|
||||
assertNotNull( childBuild );
|
||||
|
||||
|
@ -776,7 +832,7 @@ public class DefaultModelInheritanceAssemblerTest
|
|||
}
|
||||
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();
|
||||
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(); )
|
||||
{
|
||||
|
@ -808,7 +864,7 @@ public class DefaultModelInheritanceAssemblerTest
|
|||
else
|
||||
{
|
||||
assertTrue( "Unexpected goals specification",
|
||||
( testReportSetsMap == null || testReportSetsMap.isEmpty() ) );
|
||||
( ( testReportSetsMap == null ) || testReportSetsMap.isEmpty() ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -851,7 +907,7 @@ public class DefaultModelInheritanceAssemblerTest
|
|||
{
|
||||
Model model = makeBaseModel( artifactId );
|
||||
|
||||
if ( connection != null || developerConnection != null || url != null )
|
||||
if ( ( connection != null ) || ( developerConnection != null ) || ( url != null ) )
|
||||
{
|
||||
Scm scm = new Scm();
|
||||
|
||||
|
|
Loading…
Reference in New Issue