Author: jdcasey
Date: Fri Aug 10 13:49:14 2007
New Revision: 564761

URL: http://svn.apache.org/viewvc?view=rev&rev=564761
Log:
Fixing a few problems with the model-lineage builder, where it was stubbing 
models inappropriately and other minor logical problems.

Modified:
    
maven/components/trunk/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java
    
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
    
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineage.java
    
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineageBuilder.java
    
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/ModelLineage.java
    
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/ModelLineageBuilder.java
    
maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/build/model/DefaultModelLineageBuilderTest.java
    
maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssemblerTest.java

Modified: 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java
URL: 
http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java?view=diff&rev=564761&r1=564760&r2=564761
==============================================================================
--- 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java
 (original)
+++ 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java
 Fri Aug 10 13:49:14 2007
@@ -330,7 +330,7 @@
             getLogger().debug( "Building model-lineage for: " + pom + " to 
pre-scan for extensions." );
 
             lineage = modelLineageBuilder.buildModelLineage( pom, 
localRepository, originalRemoteRepositories,
-                                                             
globalProfileManager );
+                                                             
globalProfileManager, false );
         }
         catch ( ProjectBuildingException e )
         {

Modified: 
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
URL: 
http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java?view=diff&rev=564761&r1=564760&r2=564761
==============================================================================
--- 
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
 (original)
+++ 
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
 Fri Aug 10 13:49:14 2007
@@ -754,11 +754,11 @@
                 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 @@
         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 );
 
@@ -1079,8 +1080,6 @@
         for ( ModelLineageIterator it = modelLineage.lineageIterator(); 
it.hasNext(); )
         {
             Model currentModel = (Model) it.next();
-
-            getLogger().debug( "[assembleLineage] Assembling MavenProject 
instance for: " + currentModel.getId() );
 
             File currentPom = it.getPOMFile();
 

Modified: 
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineage.java
URL: 
http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineage.java?view=diff&rev=564761&r1=564760&r2=564761
==============================================================================
--- 
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineage.java
 (original)
+++ 
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineage.java
 Fri Aug 10 13:49:14 2007
@@ -45,7 +45,7 @@
         {
             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 @@
         {
             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 @@
         {
             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 @@
         {
             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 @@
         {
             return null;
         }
-        
+
         ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( 0 );
-        
+
         return tuple.remoteRepositories;
     }
 
@@ -210,9 +210,9 @@
         {
             return null;
         }
-        
+
         ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( 0 );
-        
+
         return tuple.model;
     }
 
@@ -222,45 +222,45 @@
         {
             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 @@
         {
             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 @@
     {
         return tuples.size();
     }
-    
+
     private static final class ModelLineageTuple
     {
         private Model model;

Modified: 
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineageBuilder.java
URL: 
http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineageBuilder.java?view=diff&rev=564761&r1=564760&r2=564761
==============================================================================
--- 
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineageBuilder.java
 (original)
+++ 
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineageBuilder.java
 Fri Aug 10 13:49:14 2007
@@ -87,7 +87,7 @@
      * @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 @@
 
         ModelAndFile current = new ModelAndFile( readModel( pom, 
projectBuildCache ), pom );
 
-        while ( current != null )
+        do
         {
             if ( lineage.size() == 0 )
             {
@@ -112,44 +112,43 @@
 
             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 @@
      * 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 @@
 
         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 @@
 
             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." );
-
-                parent = new Model();
-
-                parent.setGroupId( modelParent.getGroupId() );
-                parent.setArtifactId( modelParent.getArtifactId() );
-                parent.setVersion( modelParent.getVersion() );
+                if ( allowStubs )
+                {
+                    getLogger().warn( "Cannot find parent POM: " + 
modelParent.getId() + " for child: " + model.getId() + ". Using stub model 
instead." );
+
+                    Model parent = new Model();
+
+                    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;

Modified: 
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/ModelLineage.java
URL: 
http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/ModelLineage.java?view=diff&rev=564761&r1=564760&r2=564761
==============================================================================
--- 
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/ModelLineage.java
 (original)
+++ 
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/ModelLineage.java
 Fri Aug 10 13:49:14 2007
@@ -28,56 +28,56 @@
 /**
  * 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 @@
     /**
      * 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 @@
     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 );

Modified: 
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/ModelLineageBuilder.java
URL: 
http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/ModelLineageBuilder.java?view=diff&rev=564761&r1=564760&r2=564761
==============================================================================
--- 
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/ModelLineageBuilder.java
 (original)
+++ 
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/ModelLineageBuilder.java
 Fri Aug 10 13:49:14 2007
@@ -29,7 +29,7 @@
 /**
  * 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 @@
     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;
 
 }

Modified: 
maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/build/model/DefaultModelLineageBuilderTest.java
URL: 
http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/build/model/DefaultModelLineageBuilderTest.java?view=diff&rev=564761&r1=564760&r2=564761
==============================================================================
--- 
maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/build/model/DefaultModelLineageBuilderTest.java
 (original)
+++ 
maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/build/model/DefaultModelLineageBuilderTest.java
 Fri Aug 10 13:49:14 2007
@@ -58,13 +58,13 @@
 
         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 @@
             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 @@
         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 @@
         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 @@
         writeModel( current, currentPOM );
 
         // 7. build the lineage.
-        ArtifactRepository localRepository = new DefaultArtifactRepository( 
"local", localRepoDirectory.toURL()
-            .toExternalForm(), defaultLayout );
-
-        ArtifactRepository remoteRepository = new DefaultArtifactRepository( 
"test", remoteRepoDirectory.toURL()
-            .toExternalForm(), defaultLayout );
+        ArtifactRepository localRepository = new DefaultArtifactRepository(
+                                                                            
"local",
+                                                                            
localRepoDirectory.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 @@
         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 @@
 
         // 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 @@
         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() );
 

Modified: 
maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssemblerTest.java
URL: 
http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssemblerTest.java?view=diff&rev=564761&r1=564760&r2=564761
==============================================================================
--- 
maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssemblerTest.java
 (original)
+++ 
maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssemblerTest.java
 Fri Aug 10 13:49:14 2007
@@ -52,129 +52,129 @@
     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 @@
                       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 @@
     {
         Build childBuild = child.getBuild();
 
-        if ( expectedPlugins != null && !expectedPlugins.isEmpty() )
+        if ( ( expectedPlugins != null ) && !expectedPlugins.isEmpty() )
         {
             assertNotNull( childBuild );
 
@@ -616,7 +672,7 @@
         }
         else
         {
-            assertTrue( childBuild == null || childBuild.getPlugins() == null 
|| childBuild.getPlugins().isEmpty() );
+            assertTrue( ( childBuild == null ) || ( childBuild.getPlugins() == 
null ) || childBuild.getPlugins().isEmpty() );
         }
     }
 
@@ -628,9 +684,9 @@
         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 @@
         else
         {
             assertTrue( "Unexpected goals specification",
-                        ( testExecutionsMap == null || 
testExecutionsMap.isEmpty() ) );
+                        ( ( testExecutionsMap == null ) || 
testExecutionsMap.isEmpty() ) );
         }
     }
 
@@ -750,7 +806,7 @@
     {
         Reporting childBuild = child.getReporting();
 
-        if ( expectedPlugins != null && !expectedPlugins.isEmpty() )
+        if ( ( expectedPlugins != null ) && !expectedPlugins.isEmpty() )
         {
             assertNotNull( childBuild );
 
@@ -776,7 +832,7 @@
         }
         else
         {
-            assertTrue( childBuild == null || childBuild.getPlugins() == null 
|| childBuild.getPlugins().isEmpty() );
+            assertTrue( ( childBuild == null ) || ( childBuild.getPlugins() == 
null ) || childBuild.getPlugins().isEmpty() );
         }
     }
 
@@ -788,9 +844,9 @@
         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 @@
         else
         {
             assertTrue( "Unexpected goals specification",
-                        ( testReportSetsMap == null || 
testReportSetsMap.isEmpty() ) );
+                        ( ( testReportSetsMap == null ) || 
testReportSetsMap.isEmpty() ) );
         }
     }
 
@@ -851,7 +907,7 @@
     {
         Model model = makeBaseModel( artifactId );
 
-        if ( connection != null || developerConnection != null || url != null )
+        if ( ( connection != null ) || ( developerConnection != null ) || ( 
url != null ) )
         {
             Scm scm = new Scm();
 


Reply via email to