You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jd...@apache.org on 2007/01/17 02:36:08 UTC

svn commit: r496910 [1/2] - in /maven/components/trunk/maven-project: ./ src/main/java/org/apache/maven/profiles/ src/main/java/org/apache/maven/profiles/activation/ src/main/java/org/apache/maven/project/ src/main/java/org/apache/maven/project/build/ ...

Author: jdcasey
Date: Tue Jan 16 17:36:07 2007
New Revision: 496910

URL: http://svn.apache.org/viewvc?view=rev&rev=496910
Log:
Splitting model-lineage loading and profile-application out into separate components...profile-application, so the model-lineage builder can run properly, and the model-lineage builder, so we can pre-scan for models with extensions that may contain things like profile activators, which would be used during project-loading.

Added:
    maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/
    maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/
    maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineage.java   (with props)
    maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineageBuilder.java   (with props)
    maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/ModelLineage.java   (with props)
    maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/ModelLineageBuilder.java   (with props)
    maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/profile/
    maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/profile/DefaultProfileAdvisor.java   (with props)
    maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/profile/ProfileAdvisor.java   (with props)
    maven/components/trunk/maven-project/src/test/java/org/apache/maven/profiles/activation/
    maven/components/trunk/maven-project/src/test/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivatorTest.java   (with props)
    maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/build/
    maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/build/model/
    maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/build/model/AbstractModelLineageTest.java   (with props)
    maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/build/model/DefaultModelLineageBuilderTest.java   (with props)
    maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/build/model/DefaultModelLineageTest.java   (with props)
Modified:
    maven/components/trunk/maven-project/pom.xml
    maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java
    maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivator.java
    maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
    maven/components/trunk/maven-project/src/main/resources/META-INF/plexus/components.xml
    maven/components/trunk/maven-project/src/test/resources/inheritance-repo/t02/p0/p1/p2/p3/p4/p5/pom.xml
    maven/components/trunk/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml
    maven/components/trunk/maven-project/src/test/resources/org/apache/maven/project/canonical/CanonicalProjectBuilderTest.xml

Modified: maven/components/trunk/maven-project/pom.xml
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/pom.xml?view=diff&rev=496910&r1=496909&r2=496910
==============================================================================
--- maven/components/trunk/maven-project/pom.xml (original)
+++ maven/components/trunk/maven-project/pom.xml Tue Jan 16 17:36:07 2007
@@ -73,5 +73,10 @@
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-container-default</artifactId>
     </dependency>
+      <dependency>
+        <groupId>org.apache.maven.wagon</groupId>
+        <artifactId>wagon-file</artifactId>
+        <scope>test</scope>
+      </dependency>
   </dependencies>
 </project>

Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java?view=diff&rev=496910&r1=496909&r2=496910
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java Tue Jan 16 17:36:07 2007
@@ -246,7 +246,7 @@
         throws ProfileActivationException
     {
         List activators = null;
-        container.addContextValue("SystemProperties", systemProperties);
+        
         try
         {
             activators = container.lookupList( ProfileActivator.ROLE );

Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivator.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivator.java?view=diff&rev=496910&r1=496909&r2=496910
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivator.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivator.java Tue Jan 16 17:36:07 2007
@@ -6,6 +6,9 @@
 import org.apache.maven.model.Profile;
 import org.codehaus.plexus.context.Context;
 import org.codehaus.plexus.context.ContextException;
+import org.codehaus.plexus.logging.LogEnabled;
+import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.logging.console.ConsoleLogger;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
 import org.codehaus.plexus.util.StringUtils;
 
@@ -26,13 +29,14 @@
  */
 
 public class SystemPropertyProfileActivator
-    extends DetectedProfileActivator implements Contextualizable
+    extends DetectedProfileActivator implements Contextualizable, LogEnabled
 {
-    private Properties properties;
+    private Context context;
+    private Logger logger;
     
     public void contextualize(Context context) throws ContextException 
     {
-        properties = (Properties)context.get("SystemProperties");
+        this.context = context;
     }
     
     protected boolean canDetectActivation( Profile profile )
@@ -42,6 +46,24 @@
 
     public boolean isActive( Profile profile )
     {
+        Properties properties = null;
+        if ( context.contains( "SystemProperties" ) )
+        {
+            try
+            {
+                properties = (Properties) context.get("SystemProperties");
+            }
+            catch ( ContextException e )
+            {
+                getLogger().debug( "Failed to get system properties cache from context.", e );
+            }
+        }
+        
+        if ( properties == null )
+        {
+            properties = System.getProperties();
+        }
+        
         Activation activation = profile.getActivation();
 
         ActivationProperty property = activation.getProperty();
@@ -57,7 +79,7 @@
                 name = name.substring( 1 );
             }
             
-            String sysValue = properties.getProperty( name );
+            String sysValue = properties != null ? properties.getProperty( name ) : null;
 
             String propValue = property.getValue();
             if ( StringUtils.isNotEmpty( propValue ) )
@@ -97,6 +119,21 @@
         }
 
         return false;
+    }
+    
+    protected Logger getLogger()
+    {
+        if ( logger == null )
+        {
+            logger = new ConsoleLogger( Logger.LEVEL_DEBUG, "SystemPropertyProfileActivator:internal" );
+        }
+
+        return logger;
+    }
+
+    public void enableLogging( Logger logger )
+    {
+        this.logger = logger;
     }
 
 }

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=496910&r1=496909&r2=496910
==============================================================================
--- 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 Tue Jan 16 17:36:07 2007
@@ -16,6 +16,7 @@
  * limitations under the License.
  */
 
+import org.apache.maven.MavenTools;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.ArtifactStatus;
 import org.apache.maven.artifact.ArtifactUtils;
@@ -38,11 +39,9 @@
 import org.apache.maven.model.DistributionManagement;
 import org.apache.maven.model.Extension;
 import org.apache.maven.model.Model;
-import org.apache.maven.model.Parent;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.model.Profile;
 import org.apache.maven.model.ReportPlugin;
-import org.apache.maven.model.Repository;
 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
 import org.apache.maven.profiles.DefaultProfileManager;
 import org.apache.maven.profiles.MavenProfilesBuilder;
@@ -51,6 +50,10 @@
 import org.apache.maven.profiles.ProfilesRoot;
 import org.apache.maven.profiles.activation.ProfileActivationException;
 import org.apache.maven.project.artifact.InvalidDependencyVersionException;
+import org.apache.maven.project.build.model.DefaultModelLineage;
+import org.apache.maven.project.build.model.ModelLineage;
+import org.apache.maven.project.build.model.ModelLineageBuilder;
+import org.apache.maven.project.build.profile.ProfileAdvisor;
 import org.apache.maven.project.inheritance.ModelInheritanceAssembler;
 import org.apache.maven.project.injection.ModelDefaultsInjector;
 import org.apache.maven.project.injection.ProfileInjector;
@@ -60,7 +63,6 @@
 import org.apache.maven.project.validation.ModelValidationResult;
 import org.apache.maven.project.validation.ModelValidator;
 import org.apache.maven.wagon.events.TransferListener;
-import org.apache.maven.MavenTools;
 import org.codehaus.plexus.PlexusConstants;
 import org.codehaus.plexus.PlexusContainer;
 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
@@ -166,6 +168,10 @@
     private ModelInterpolator modelInterpolator;
 
     private ArtifactRepositoryFactory artifactRepositoryFactory;
+    
+    private ModelLineageBuilder modelLineageBuilder;
+    
+    private ProfileAdvisor profileAdvisor;
 
     private MavenTools mavenTools;
 
@@ -420,6 +426,12 @@
                                                       boolean checkDistributionManagementStatus )
         throws ProjectBuildingException
     {
+        // TODO: Remove this once we have build-context stuff working...
+        if ( !container.getContext().contains( "SystemProperties" ) )
+        {
+            container.addContextValue("SystemProperties", System.getProperties());
+        }
+        
         Model model = readModel( "unknown", projectDescriptor, STRICT_MODEL_PARSING );
 
         MavenProject project = buildInternal( projectDescriptor.getAbsolutePath(),
@@ -613,76 +625,44 @@
 
         Model superModel = getSuperModel();
 
-        //TODO mkleint - use the (Container, Properties) constructor to make system properties embeddable
-        // shall the ProfileManager intefrace expose the properties?
-        
-        ProfileManager superProjectProfileManager;
-        if (externalProfileManager instanceof DefaultProfileManager) {
-            superProjectProfileManager = new DefaultProfileManager( container, ((DefaultProfileManager) externalProfileManager).getSystemProperties() );
-        } else {
-            superProjectProfileManager = new DefaultProfileManager( container );
-        }
-
-        List activeProfiles;
-
-        superProjectProfileManager.addProfiles( superModel.getProfiles() );
-
-        activeProfiles = injectActiveProfiles( superProjectProfileManager, superModel );
-
         MavenProject superProject = new MavenProject( superModel );
-
-        superProject.setActiveProfiles( activeProfiles );
-
-        //noinspection CollectionDeclaredAsConcreteClass
-        LinkedList lineage = new LinkedList();
-
-        // TODO: the aRWR can get out of sync with project.model.repositories. We should do all the processing of
-        // profiles, etc on the models then recreate the aggregated sets at the end from the project repositories (they
-        // must still be created along the way so that parent poms can be discovered, however)
-        // Use a TreeSet to ensure ordering is retained
-        Set aggregatedRemoteWagonRepositories = new LinkedHashSet();
-
+        
         String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
 
-        List activeExternalProfiles;
-        try
+        List explicitlyActive;
+        List explicitlyInactive;
+        
+        if ( externalProfileManager != null )
         {
-            if ( externalProfileManager != null )
+            // used to trigger the caching of SystemProperties in the container context...
+            try
             {
-                activeExternalProfiles = externalProfileManager.getActiveProfiles();
+                externalProfileManager.getActiveProfiles();
             }
-            else
+            catch ( ProfileActivationException e )
             {
-                activeExternalProfiles = Collections.EMPTY_LIST;
+                throw new ProjectBuildingException( projectId, "Failed to activate external profiles.", e );
             }
+            
+            explicitlyActive = externalProfileManager.getExplicitlyActivatedIds();
+            explicitlyInactive = externalProfileManager.getExplicitlyDeactivatedIds();
         }
-        catch ( ProfileActivationException e )
+        else
         {
-            throw new ProjectBuildingException( projectId, "Failed to calculate active external profiles.", e );
+            explicitlyActive = Collections.EMPTY_LIST;
+            explicitlyInactive = Collections.EMPTY_LIST;
         }
+        
+        superProject.setActiveProfiles( profileAdvisor.applyActivatedProfiles( superModel, null, explicitlyActive, explicitlyInactive ) );
 
-        for ( Iterator i = activeExternalProfiles.iterator(); i.hasNext(); )
-        {
-            Profile externalProfile = (Profile) i.next();
-
-            for ( Iterator repoIterator = externalProfile.getRepositories().iterator(); repoIterator.hasNext(); )
-            {
-                Repository mavenRepo = (Repository) repoIterator.next();
-
-                ArtifactRepository artifactRepo = null;
-                try
-                {
-                    artifactRepo = mavenTools.buildArtifactRepository( mavenRepo );
-                }
-                catch ( InvalidRepositoryException e )
-                {
-                    throw new ProjectBuildingException( projectId, e.getMessage(), e );
-                }
-
-                aggregatedRemoteWagonRepositories.add( artifactRepo );
-            }
-        }
+        //noinspection CollectionDeclaredAsConcreteClass
+        LinkedList lineage = new LinkedList();
 
+        LinkedHashSet aggregatedRemoteWagonRepositories = collectInitialRepositories( model, superModel,
+                                                                                      parentSearchRepositories,
+                                                                                      projectDir, explicitlyActive,
+                                                                                      explicitlyInactive );
+        
         Model originalModel = ModelUtils.cloneModel( model );
 
         MavenProject project = null;
@@ -801,6 +781,62 @@
         return project;
     }
     
+    /*
+     * Order is:
+     * 
+     * 1. model profile repositories
+     * 2. model repositories
+     * 3. superModel profile repositories
+     * 4. superModel repositories
+     * 5. parentSearchRepositories
+     */
+    private LinkedHashSet collectInitialRepositories( Model model, Model superModel, List parentSearchRepositories,
+                                                      File projectDir, List explicitlyActive, List explicitlyInactive )
+        throws ProjectBuildingException
+    {
+        LinkedHashSet collected = new LinkedHashSet();
+        
+        collectInitialRepositoriesFromModel( collected, model, projectDir, explicitlyActive, explicitlyInactive );
+
+        collectInitialRepositoriesFromModel( collected, superModel, projectDir, explicitlyActive, explicitlyInactive );
+
+        if ( parentSearchRepositories != null && !parentSearchRepositories.isEmpty() )
+        {
+            collected.addAll( parentSearchRepositories );
+        }
+        
+        return collected;
+    }
+
+    private void collectInitialRepositoriesFromModel( LinkedHashSet collected, Model model, File projectDir,
+                                                      List explicitlyActive, List explicitlyInactive )
+        throws ProjectBuildingException
+    {
+        Set reposFromProfiles = profileAdvisor.getArtifactRepositoriesFromActiveProfiles( model, projectDir,
+                                                                                          explicitlyActive,
+                                                                                          explicitlyInactive );
+
+        if ( reposFromProfiles != null && !reposFromProfiles.isEmpty() )
+        {
+            collected.addAll( reposFromProfiles );
+        }
+
+        List modelRepos = model.getRepositories();
+        if ( modelRepos != null && !modelRepos.isEmpty() )
+        {
+            try
+            {
+                collected.addAll( mavenTools.buildArtifactRepositories( modelRepos ) );
+            }
+            catch ( InvalidRepositoryException e )
+            {
+                throw new ProjectBuildingException( safeVersionlessKey( model.getGroupId(), model.getArtifactId() ),
+                                                    "Failed to construct ArtifactRepository instances for repositories declared in: "
+                                                        + model.getId(), e );
+            }
+        }
+    }
+
     private String safeVersionlessKey( String groupId, String artifactId )
     {
         String gid = groupId;
@@ -851,16 +887,29 @@
     {
         Model model = project.getModel();
 
-        List activeProfiles = project.getActiveProfiles();
-
-        if ( activeProfiles == null )
+        List explicitlyActive;
+        List explicitlyInactive;
+        
+        if ( profileMgr != null )
         {
-            activeProfiles = new ArrayList();
+            explicitlyActive = profileMgr.getExplicitlyActivatedIds();
+            explicitlyInactive = profileMgr.getExplicitlyDeactivatedIds();
         }
-
-        List injectedProfiles = injectActiveProfiles( profileMgr, model );
-
-        activeProfiles.addAll( injectedProfiles );
+        else
+        {
+            explicitlyActive = Collections.EMPTY_LIST;
+            explicitlyInactive = Collections.EMPTY_LIST;
+        }
+        
+        List active = profileAdvisor.applyActivatedProfiles( model, projectDir, explicitlyActive, explicitlyInactive );
+        
+        LinkedHashSet activated = new LinkedHashSet();
+        
+        activated.addAll( project.getActiveProfiles() );
+        activated.addAll( active );
+        
+        List activeProfiles = new ArrayList( activated );
+        project.setActiveProfiles( activeProfiles );
 
         // TODO: Clean this up...we're using this to 'jump' the interpolation step for model properties not expressed in XML.
         //  [BP] - Can this above comment be explained?
@@ -971,251 +1020,69 @@
                                           boolean strict )
         throws ProjectBuildingException, InvalidRepositoryException
     {
-        if ( !model.getRepositories().isEmpty() )
-        {
-            List respositories = buildArtifactRepositories( model );
-
-            for ( Iterator it = respositories.iterator(); it.hasNext(); )
-            {
-                ArtifactRepository repository = (ArtifactRepository) it.next();
-
-                if ( !aggregatedRemoteWagonRepositories.contains( repository ) )
-                {
-                    aggregatedRemoteWagonRepositories.add( repository );
-                }
-            }
-        }
-
-        //TODO mkleint - use the (Container, Properties constructor to make system properties embeddable
-        ProfileManager profileManager;
-        if (externalProfileManager != null && externalProfileManager instanceof DefaultProfileManager ) {
-            profileManager = new DefaultProfileManager( container, ((DefaultProfileManager)externalProfileManager).getSystemProperties() );
-        } else {
-            profileManager = new DefaultProfileManager( container );
-        }
-
+        ModelLineage modelLineage = new DefaultModelLineage();
+        modelLineage.setOrigin( model, new File( projectDir, "pom.xml" ), new ArrayList( aggregatedRemoteWagonRepositories ) );
+        
+        modelLineageBuilder.resumeBuildingModelLineage( modelLineage, localRepository, externalProfileManager );
+        
+        List explicitlyActive;
+        List explicitlyInactive;
+        
         if ( externalProfileManager != null )
         {
-            profileManager.explicitlyActivate( externalProfileManager.getExplicitlyActivatedIds() );
-
-            profileManager.explicitlyDeactivate( externalProfileManager.getExplicitlyDeactivatedIds() );
+            explicitlyActive = externalProfileManager.getExplicitlyActivatedIds();
+            explicitlyInactive = externalProfileManager.getExplicitlyDeactivatedIds();
         }
-
-        List activeProfiles;
-
-        try
+        else
         {
-            profileManager.addProfiles( model.getProfiles() );
-
-            loadProjectExternalProfiles( profileManager, projectDir );
-
-            activeProfiles = injectActiveProfiles( profileManager, model );
+            explicitlyActive = Collections.EMPTY_LIST;
+            explicitlyInactive = Collections.EMPTY_LIST;
         }
-        catch ( ProfileActivationException e )
-        {
-            String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
-
-            throw new ProjectBuildingException( projectId, "Failed to activate local (project-level) build profiles: " + e.getMessage(), e );
-        }
-
-        MavenProject project = new MavenProject( model );
-
-        project.setActiveProfiles( activeProfiles );
-
-        lineage.addFirst( project );
-
-        Parent parentModel = model.getParent();
-
-        if ( parentModel != null )
+        
+        List models = modelLineage.getModelsInDescendingOrder();
+        List poms = modelLineage.getFilesInDescendingOrder();
+        
+        MavenProject lastProject = null;
+        for( int i = 0; i < models.size(); i++ )
         {
-            String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
-
-            if ( StringUtils.isEmpty( parentModel.getGroupId() ) )
-            {
-                throw new ProjectBuildingException( projectId, "Missing groupId element from parent element" );
-            }
-            else if ( StringUtils.isEmpty( parentModel.getArtifactId() ) )
-            {
-                throw new ProjectBuildingException( projectId, "Missing artifactId element from parent element" );
-            }
-            else if ( parentModel.getGroupId().equals( model.getGroupId() ) &&
-                parentModel.getArtifactId().equals( model.getArtifactId() ) )
-            {
-                throw new ProjectBuildingException( projectId, "Parent element is a duplicate of " + "the current project " );
-            }
-            else if ( StringUtils.isEmpty( parentModel.getVersion() ) )
-            {
-                throw new ProjectBuildingException( projectId, "Missing version element from parent element" );
-            }
-
-            // the only way this will have a value is if we find the parent on disk...
-            File parentDescriptor = null;
+            Model currentModel = (Model) models.get( i );
+            File currentPom = (File) poms.get( i );
+            
+            MavenProject project = new MavenProject( currentModel );
+            project.setFile( currentPom );
 
-            model = null;
+            project.setActiveProfiles( profileAdvisor.applyActivatedProfiles( model, projectDir, explicitlyActive,
+                                                                              explicitlyInactive ) );
             
-            String parentKey = createCacheKey( parentModel.getGroupId(), parentModel.getArtifactId(), parentModel.getVersion() );
-            MavenProject parentProject = (MavenProject) rawProjectCache.get( parentKey );
-    
-            if ( parentProject != null )
+            if ( lastProject != null )
             {
-                model = ModelUtils.cloneModel( parentProject.getModel() );
+                project.setParent( lastProject );
                 
-                parentDescriptor = parentProject.getFile();
+                project.setParentArtifact( artifactFactory.createParentArtifact( lastProject.getGroupId(), lastProject
+                    .getArtifactId(), lastProject.getVersion() ) );
             }
             
-            String parentRelativePath = parentModel.getRelativePath();
-
-            // if we can't find a cached model matching the parent spec, then let's try to look on disk using
-            // <relativePath/>
-            if ( model == null && projectDir != null && StringUtils.isNotEmpty( parentRelativePath ) )
-            {
-                parentDescriptor = new File( projectDir, parentRelativePath );
-
-                if ( getLogger().isDebugEnabled() )
-                {
-                    getLogger().debug( "Searching for parent-POM: " + parentModel.getId() + " of project: " + project.getId() + " in relative path: " + parentRelativePath );
-                }
-
-                if ( parentDescriptor.isDirectory() )
-                {
-                    if ( getLogger().isDebugEnabled() )
-                    {
-                        getLogger().debug( "Path specified in <relativePath/> (" + parentRelativePath +
-                            ") is a directory. Searching for 'pom.xml' within this directory." );
-                    }
-
-                    parentDescriptor = new File( parentDescriptor, "pom.xml" );
-
-                    if ( !parentDescriptor.exists() )
-                    {
-                        if ( getLogger().isDebugEnabled() )
-                        {
-                            getLogger().debug( "Parent-POM: " + parentModel.getId() + " for project: " + project.getId() + " cannot be loaded from relative path: " + parentDescriptor + "; path does not exist." );
-                        }
-                    }
-                }
-
-                if ( parentDescriptor != null )
-                {
-                    try
-                    {
-                        parentDescriptor = parentDescriptor.getCanonicalFile();
-                    }
-                    catch ( IOException e )
-                    {
-                        getLogger().debug( "Failed to canonicalize potential parent POM: \'" + parentDescriptor + "\'",
-                                           e );
-
-                        parentDescriptor = null;
-                    }
-                }
-
-                if ( parentDescriptor != null && parentDescriptor.exists() )
-                {
-                    Model candidateParent = readModel( projectId, parentDescriptor, strict );
-
-                    String candidateParentGroupId = candidateParent.getGroupId();
-                    if ( candidateParentGroupId == null && candidateParent.getParent() != null )
-                    {
-                        candidateParentGroupId = candidateParent.getParent().getGroupId();
-                    }
-
-                    String candidateParentVersion = candidateParent.getVersion();
-                    if ( candidateParentVersion == null && candidateParent.getParent() != null )
-                    {
-                        candidateParentVersion = candidateParent.getParent().getVersion();
-                    }
-
-                    if ( parentModel.getGroupId().equals( candidateParentGroupId ) &&
-                        parentModel.getArtifactId().equals( candidateParent.getArtifactId() ) &&
-                        parentModel.getVersion().equals( candidateParentVersion ) )
-                    {
-                        model = candidateParent;
-
-                        getLogger().debug( "Using parent-POM from the project hierarchy at: \'" +
-                            parentModel.getRelativePath() + "\' for project: " + project.getId() );
-                    }
-                    else
-                    {
-                        getLogger().debug( "Invalid parent-POM referenced by relative path '" +
-                            parentModel.getRelativePath() + "' in parent specification in " + project.getId() + ":" +
-                            "\n  Specified: " + parentModel.getId() + "\n  Found:     " + candidateParent.getId() );
-                    }
-                }
-                else if ( getLogger().isDebugEnabled() )
-                {
-                    getLogger().debug( "Parent-POM: " + parentModel.getId() + " not found in relative path: " + parentRelativePath );
-                }
-            }
-
-            Artifact parentArtifact = null;
-
-            // only resolve the parent model from the repository system if we didn't find it on disk...
-            if ( model == null )
-            {
-                // MNG-2302: parent's File was being populated incorrectly when parent is loaded from repo.
-                // keep this in line with other POMs loaded from the repository...the file should be null.
-                parentDescriptor = null;
-                
-                //!! (**)
-                // ----------------------------------------------------------------------
-                // Do we have the necessary information to actually find the parent
-                // POMs here?? I don't think so ... Say only one remote repository is
-                // specified and that is ibiblio then this model that we just read doesn't
-                // have any repository information ... I think we might have to inherit
-                // as we go in order to do this.
-                // ----------------------------------------------------------------------
-
-                // we must add the repository this POM was found in too, by chance it may be located where the parent is
-                // we can't query the parent to ask where it is :)
-                List remoteRepositories = new ArrayList( aggregatedRemoteWagonRepositories );
-                remoteRepositories.addAll( parentSearchRepositories );
-
-                if ( getLogger().isDebugEnabled() )
-                {
-                    getLogger().debug(
-                                       "Retrieving parent-POM: " + parentModel.getId() + " for project: "
-                                           + project.getId() + " from the repository." );
-                }
-
-                parentArtifact = artifactFactory.createParentArtifact( parentModel.getGroupId(),
-                                                                       parentModel.getArtifactId(),
-                                                                       parentModel.getVersion() );
-
-                try
-                {
-                    model = findModelFromRepository( parentArtifact, remoteRepositories, localRepository, false );
-                }
-                catch( ProjectBuildingException e )
-                {
-                    throw new ProjectBuildingException( project.getId(), "Cannot find parent: " + e.getProjectId() + " for project: " + project.getId(), e );
-                }
-            }
-
-            if ( model != null && !"pom".equals( model.getPackaging() ) )
-            {
-                throw new ProjectBuildingException( projectId, "Parent: " + model.getId() + " of project: " +
-                    projectId + " has wrong packaging: " + model.getPackaging() + ". Must be 'pom'." );
-            }
+            lineage.addLast( project );
+            
+            lastProject = project;
+        }
 
-            File parentProjectDir = null;
-            if ( parentDescriptor != null )
+        MavenProject result = (MavenProject) lineage.get( lineage.size() - 1 );
+        
+        if ( externalProfileManager != null )
+        {
+            LinkedHashSet active = new LinkedHashSet();
+            
+            List existingActiveProfiles = result.getActiveProfiles();
+            if ( existingActiveProfiles != null && !existingActiveProfiles.isEmpty() )
             {
-                parentProjectDir = parentDescriptor.getParentFile();
+                active.addAll( existingActiveProfiles );
             }
             
-            MavenProject parent = assembleLineage( model, lineage, localRepository, parentProjectDir,
-                                                   parentSearchRepositories, aggregatedRemoteWagonRepositories,
-                                                   externalProfileManager, strict );
-            
-            parent.setFile( parentDescriptor );
-
-            project.setParent( parent );
-
-            project.setParentArtifact( parentArtifact );
+            profileAdvisor.applyActivatedExternalProfiles( result.getModel(), projectDir, externalProfileManager );
         }
-
-        return project;
+        
+        return result;
     }
 
     private List injectActiveProfiles( ProfileManager profileManager, Model model )

Added: 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=auto&rev=496910
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineage.java (added)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineage.java Tue Jan 16 17:36:07 2007
@@ -0,0 +1,331 @@
+package org.apache.maven.project.build.model;
+
+import org.apache.maven.model.Model;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @see org.apache.maven.project.build.model.ModelLineage
+ */
+public class DefaultModelLineage
+    implements ModelLineage
+{
+
+    private List tuples = new ArrayList();
+
+    /**
+     * @see org.apache.maven.project.build.model.ModelLineage#addParent(org.apache.maven.model.Model, java.io.File, java.util.List)
+     */
+    public void addParent( Model model, File pomFile, List artifactRepositories )
+    {
+        if ( tuples.isEmpty() )
+        {
+            throw new IllegalStateException( "You must call setOrigin(..) before adding a parent to the lineage." );
+        }
+        
+        tuples.add( new ModelLineageTuple( model, pomFile, artifactRepositories ) );
+    }
+
+    /**
+     * @see org.apache.maven.project.build.model.ModelLineage#artifactRepositoryListIterator()
+     */
+    public Iterator artifactRepositoryListIterator()
+    {
+        return new Iterator()
+        {
+
+            private int idx = 0;
+
+            public boolean hasNext()
+            {
+                return tuples.size() > idx;
+            }
+
+            public Object next()
+            {
+                return ( (ModelLineageTuple) tuples.get( idx++ ) ).remoteRepositories;
+            }
+
+            public void remove()
+            {
+                tuples.remove( idx );
+            }
+
+        };
+    }
+
+    /**
+     * @see org.apache.maven.project.build.model.ModelLineage#fileIterator()
+     */
+    public Iterator fileIterator()
+    {
+        return new Iterator()
+        {
+
+            private int idx = 0;
+
+            public boolean hasNext()
+            {
+                return tuples.size() > idx;
+            }
+
+            public Object next()
+            {
+                return ( (ModelLineageTuple) tuples.get( idx++ ) ).file;
+            }
+
+            public void remove()
+            {
+                tuples.remove( idx );
+            }
+
+        };
+    }
+
+    /**
+     * @see org.apache.maven.project.build.model.ModelLineage#getArtifactRepositories(org.apache.maven.model.Model)
+     */
+    public List getArtifactRepositories( Model model )
+    {
+        int index = tuples.indexOf( new ModelLineageTuple( model ) );
+
+        ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( index );
+
+        return tuple != null ? tuple.remoteRepositories : null;
+    }
+
+    public List getArtifactRepositoryListsInDescendingOrder()
+    {
+        if ( tuples.isEmpty() )
+        {
+            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;
+    }
+
+    /**
+     * @see org.apache.maven.project.build.model.ModelLineage#getFile(org.apache.maven.model.Model)
+     */
+    public File getFile( Model model )
+    {
+        int index = tuples.indexOf( new ModelLineageTuple( model ) );
+
+        ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( index );
+
+        return tuple != null ? tuple.file : null;
+    }
+
+    public List getFilesInDescendingOrder()
+    {
+        if ( tuples.isEmpty() )
+        {
+            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;
+    }
+
+    public List getModelsInDescendingOrder()
+    {
+        if ( tuples.isEmpty() )
+        {
+            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;
+    }
+
+    public List getOriginatingArtifactRepositoryList()
+    {
+        if ( tuples.isEmpty() )
+        {
+            return null;
+        }
+        
+        ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( 0 );
+        
+        return tuple.remoteRepositories;
+    }
+
+    public Model getOriginatingModel()
+    {
+        if ( tuples.isEmpty() )
+        {
+            return null;
+        }
+        
+        ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( 0 );
+        
+        return tuple.model;
+    }
+
+    public File getOriginatingPOMFile()
+    {
+        if ( tuples.isEmpty() )
+        {
+            return null;
+        }
+        
+        ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( 0 );
+        
+        return tuple.file;
+    }
+
+    public List getDeepestArtifactRepositoryList()
+    {
+        if ( tuples.isEmpty() )
+        {
+            return null;
+        }
+        
+        ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( tuples.size() - 1 );
+        
+        return tuple.remoteRepositories;
+    }
+
+    public File getDeepestFile()
+    {
+        if ( tuples.isEmpty() )
+        {
+            return null;
+        }
+        
+        ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( tuples.size() - 1 );
+        
+        return tuple.file;
+    }
+
+    public Model getDeepestModel()
+    {
+        if ( tuples.isEmpty() )
+        {
+            return null;
+        }
+        
+        ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( tuples.size() - 1 );
+        
+        return tuple.model;
+    }
+
+    /**
+     * @see org.apache.maven.project.build.model.ModelLineage#modelIterator()
+     */
+    public Iterator modelIterator()
+    {
+        return new Iterator()
+        {
+
+            private int idx = 0;
+
+            public boolean hasNext()
+            {
+                return tuples.size() > idx;
+            }
+
+            public Object next()
+            {
+                return ( (ModelLineageTuple) tuples.get( idx++ ) ).model;
+            }
+
+            public void remove()
+            {
+                tuples.remove( idx );
+            }
+
+        };
+    }
+
+    public void setOrigin( Model model, File pomFile, List artifactRepositories )
+    {
+        if ( !tuples.isEmpty() )
+        {
+            throw new IllegalStateException( "Origin already set; you must use addParent(..) for successive additions to the lineage." );
+        }
+        
+        tuples.add( new ModelLineageTuple( model, pomFile, artifactRepositories ) );
+    }
+
+    /**
+     * @see org.apache.maven.project.build.model.ModelLineage#size()
+     */
+    public int size()
+    {
+        return tuples.size();
+    }
+    
+    private static final class ModelLineageTuple
+    {
+        private Model model;
+
+        private File file;
+
+        private List remoteRepositories;
+
+        private ModelLineageTuple( Model model )
+        {
+            this.model = model;
+        }
+
+        private ModelLineageTuple( Model model, File file, List remoteRepositories )
+        {
+            this.model = model;
+            this.file = file;
+            this.remoteRepositories = remoteRepositories;
+        }
+
+        public boolean equals( Object other )
+        {
+            if ( this == other )
+            {
+                return true;
+            }
+            else if ( other instanceof ModelLineageTuple )
+            {
+                ModelLineageTuple otherTuple = (ModelLineageTuple) other;
+
+                return model.getId().equals( otherTuple.model.getId() );
+            }
+
+            return false;
+        }
+    }
+
+}

Propchange: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineage.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: 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=auto&rev=496910
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineageBuilder.java (added)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineageBuilder.java Tue Jan 16 17:36:07 2007
@@ -0,0 +1,361 @@
+package org.apache.maven.project.build.model;
+
+import org.apache.maven.MavenTools;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.InvalidRepositoryException;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Parent;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.profiles.ProfileManager;
+import org.apache.maven.project.ProjectBuildingException;
+import org.apache.maven.project.build.profile.ProfileAdvisor;
+import org.codehaus.plexus.logging.LogEnabled;
+import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.logging.console.ConsoleLogger;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @see org.apache.maven.project.build.model.ModelLineageBuilder
+ */
+public class DefaultModelLineageBuilder
+    implements ModelLineageBuilder, LogEnabled
+{
+
+    public static final String ROLE_HINT = "default";
+
+    private ArtifactFactory artifactFactory;
+
+    private ArtifactResolver artifactResolver;
+
+    private MavenTools mavenTools;
+
+    private ProfileAdvisor profileAdvisor;
+
+    private Logger logger;
+
+    public DefaultModelLineageBuilder()
+    {
+    }
+
+    public DefaultModelLineageBuilder( ArtifactResolver resolver, ArtifactFactory artifactFactory )
+    {
+        this.artifactResolver = resolver;
+        this.artifactFactory = artifactFactory;
+    }
+
+    /**
+     * @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 )
+        throws ProjectBuildingException
+    {
+        ModelLineage lineage = new DefaultModelLineage();
+
+        File pomFile = pom;
+        List currentRemoteRepositories = remoteRepositories == null ? new ArrayList()
+                                                                   : new ArrayList( remoteRepositories );
+
+        while ( pomFile != null )
+        {
+            Model model = readModel( pomFile );
+
+            if ( lineage.size() == 0 )
+            {
+                lineage.setOrigin( model, pomFile, currentRemoteRepositories );
+            }
+            else
+            {
+                lineage.addParent( model, pomFile, currentRemoteRepositories );
+            }
+
+            currentRemoteRepositories = updateRepositorySet( model, currentRemoteRepositories, pomFile, profileManager );
+
+            pomFile = resolveParentPom( model, currentRemoteRepositories, localRepository, pomFile );
+        }
+
+        return lineage;
+    }
+
+    public void resumeBuildingModelLineage( ModelLineage lineage, ArtifactRepository localRepository,
+                                            ProfileManager profileManager )
+        throws ProjectBuildingException
+    {
+        File pomFile = lineage.getDeepestFile();
+        List currentRemoteRepositories = lineage.getDeepestArtifactRepositoryList();
+
+        if ( currentRemoteRepositories == null )
+        {
+            currentRemoteRepositories = new ArrayList();
+        }
+
+        Model model = lineage.getDeepestModel();
+
+        // use the above information to re-bootstrap the resolution chain...
+        pomFile = resolveParentPom( model, currentRemoteRepositories, localRepository, pomFile );
+
+        while ( pomFile != null )
+        {
+            model = readModel( pomFile );
+
+            if ( lineage.size() == 0 )
+            {
+                lineage.setOrigin( model, pomFile, currentRemoteRepositories );
+            }
+            else
+            {
+                lineage.addParent( model, pomFile, currentRemoteRepositories );
+            }
+
+            currentRemoteRepositories = updateRepositorySet( model, currentRemoteRepositories, pomFile, profileManager );
+
+            pomFile = resolveParentPom( model, currentRemoteRepositories, localRepository, pomFile );
+        }
+    }
+
+    /**
+     * Read the Model instance from the given POM file.
+     */
+    private Model readModel( File pomFile )
+        throws ProjectBuildingException
+    {
+        Model model;
+        FileReader reader = null;
+
+        try
+        {
+            reader = new FileReader( pomFile );
+            model = new MavenXpp3Reader().read( reader );
+        }
+        catch ( IOException e )
+        {
+            throw new ProjectBuildingException( "unknown", "Failed to read model from: " + pomFile, e );
+        }
+        catch ( XmlPullParserException e )
+        {
+            throw new ProjectBuildingException( "unknown", "Failed to parse model from: " + pomFile, e );
+        }
+        finally
+        {
+            IOUtil.close( reader );
+        }
+
+        return model;
+    }
+
+    /**
+     * Update the remote repository set used to resolve parent POMs, by adding those declared in 
+     * the given model to the HEAD of a new list, then appending the old remote repositories list.
+     * The specified pomFile is used for error reporting.
+     * @param profileManager 
+     */
+    private List updateRepositorySet( Model model, List oldArtifactRepositories, File pomFile,
+                                      ProfileManager externalProfileManager )
+        throws ProjectBuildingException
+    {
+        List repositories = model.getRepositories();
+
+        loadActiveProfileRepositories( repositories, model, externalProfileManager, pomFile.getParentFile() );
+
+        Set artifactRepositories = null;
+
+        if ( repositories != null )
+        {
+            try
+            {
+                List lastRemoteRepos = oldArtifactRepositories;
+                List remoteRepos = mavenTools.buildArtifactRepositories( repositories );
+
+                artifactRepositories = new LinkedHashSet( remoteRepos.size() + oldArtifactRepositories.size() );
+
+                artifactRepositories.addAll( remoteRepos );
+                artifactRepositories.addAll( lastRemoteRepos );
+            }
+            catch ( InvalidRepositoryException e )
+            {
+                throw new ProjectBuildingException( model.getId(), "Failed to create ArtifactRepository list for: "
+                    + pomFile, e );
+            }
+        }
+
+        return new ArrayList( artifactRepositories );
+    }
+
+    private void loadActiveProfileRepositories( List repositories, Model model, ProfileManager profileManager,
+                                                File projectDir )
+        throws ProjectBuildingException
+    {
+        List explicitlyActive;
+        List explicitlyInactive;
+        
+        if ( profileManager != null )
+        {
+            explicitlyActive = profileManager.getExplicitlyActivatedIds();
+            explicitlyInactive = profileManager.getExplicitlyDeactivatedIds();
+        }
+        else
+        {
+            explicitlyActive = Collections.EMPTY_LIST;
+            explicitlyInactive = Collections.EMPTY_LIST;
+        }
+        
+        LinkedHashSet profileRepos = profileAdvisor.getArtifactRepositoriesFromActiveProfiles( model, projectDir, explicitlyActive, explicitlyInactive );
+
+        if ( !profileRepos.isEmpty() )
+        {
+            repositories.addAll( profileRepos );
+        }
+    }
+
+    /**
+     * 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.
+     */
+    private File resolveParentPom( Model model, List remoteRepositories, ArtifactRepository localRepository,
+                                   File modelPomFile )
+        throws ProjectBuildingException
+    {
+        Parent modelParent = model.getParent();
+
+        File pomFile = null;
+
+        if ( modelParent != null )
+        {
+            validateParentDeclaration( modelParent, model );
+
+            pomFile = resolveParentWithRelativePath( modelParent, modelPomFile );
+
+            if ( pomFile == null )
+            {
+                pomFile = resolveParentFromRepositories( modelParent, localRepository, remoteRepositories, modelPomFile );
+            }
+        }
+
+        return pomFile;
+    }
+
+    private void validateParentDeclaration( Parent modelParent, Model model )
+        throws ProjectBuildingException
+    {
+        if ( StringUtils.isEmpty( modelParent.getGroupId() ) )
+        {
+            throw new ProjectBuildingException( model.getId(), "Missing groupId element from parent element" );
+        }
+        else if ( StringUtils.isEmpty( modelParent.getArtifactId() ) )
+        {
+            throw new ProjectBuildingException( model.getId(), "Missing artifactId element from parent element" );
+        }
+        else if ( modelParent.getGroupId().equals( model.getGroupId() )
+            && modelParent.getArtifactId().equals( model.getArtifactId() ) )
+        {
+            throw new ProjectBuildingException( model.getId(), "Parent element is a duplicate of "
+                + "the current project " );
+        }
+        else if ( StringUtils.isEmpty( modelParent.getVersion() ) )
+        {
+            throw new ProjectBuildingException( model.getId(), "Missing version element from parent element" );
+        }
+    }
+
+    private File resolveParentFromRepositories( Parent modelParent, ArtifactRepository localRepository,
+                                                List remoteRepositories, File pomFile )
+        throws ProjectBuildingException
+    {
+        Artifact parentPomArtifact = artifactFactory.createBuildArtifact( modelParent.getGroupId(), modelParent
+            .getArtifactId(), modelParent.getVersion(), "pom" );
+
+        getLogger().debug( "Looking for parent: " + modelParent.getId() + " using artifact: " + parentPomArtifact );
+        getLogger().debug( "\tLocal repository: " + localRepository.getBasedir() + "\n" );
+        getLogger().debug( "\tRemote repositories:\n" + remoteRepositories.toString().replace( ',', '\n' ) + "\n" );
+        
+        try
+        {
+            artifactResolver.resolve( parentPomArtifact, remoteRepositories, localRepository );
+        }
+        catch ( ArtifactResolutionException e )
+        {
+            throw new ProjectBuildingException( "Parent: " + modelParent.getId(),
+                                                "Failed to resolve POM for parent of: " + pomFile, e );
+        }
+        catch ( ArtifactNotFoundException e )
+        {
+            throw new ProjectBuildingException( "Parent: " + modelParent.getId(), "Cannot find parent: " + parentPomArtifact.getId() + " of: "
+                + pomFile, e );
+        }
+
+        if ( parentPomArtifact.isResolved() )
+        {
+            return parentPomArtifact.getFile();
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+    private File resolveParentWithRelativePath( Parent modelParent, File modelPomFile )
+        throws ProjectBuildingException
+    {
+        String relativePath = modelParent.getRelativePath();
+        File modelDir = modelPomFile.getParentFile();
+
+        File parentPomFile = new File( modelDir, relativePath );
+        
+        if ( parentPomFile.isDirectory() )
+        {
+            getLogger().debug( "Parent relative-path is a directory; assuming \'pom.xml\' file exists within." );
+            parentPomFile = new File( parentPomFile, "pom.xml" );
+        }
+        
+        getLogger().debug( "Looking for parent: " + modelParent.getId() + " in: " + parentPomFile );
+
+        if ( parentPomFile.exists() )
+        {
+            Model parentModel = readModel( parentPomFile );
+
+            boolean groupsMatch = parentModel.getGroupId() == null
+                || parentModel.getGroupId().equals( modelParent.getGroupId() );
+            boolean versionsMatch = parentModel.getVersion() == null
+                || parentModel.getVersion().equals( modelParent.getVersion() );
+
+            if ( groupsMatch && versionsMatch && parentModel.getArtifactId().equals( modelParent.getArtifactId() ) )
+            {
+                return parentPomFile;
+            }
+        }
+
+        return null;
+    }
+
+    private Logger getLogger()
+    {
+        if ( logger == null )
+        {
+            logger = new ConsoleLogger( Logger.LEVEL_DEBUG, "DefaultModelLineageBuilder:internal" );
+        }
+        
+        return logger;
+    }
+
+    public void enableLogging( Logger logger )
+    {
+        this.logger = logger;
+    }
+
+}

Propchange: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineageBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineageBuilder.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: 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=auto&rev=496910
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/ModelLineage.java (added)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/ModelLineage.java Tue Jan 16 17:36:07 2007
@@ -0,0 +1,127 @@
+package org.apache.maven.project.build.model;
+
+import org.apache.maven.model.Model;
+
+import java.io.File;
+import java.util.Iterator;
+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();
+    
+    /**
+     * Retrieve the POM file for the deepest ancestor which has been resolved so far in this
+     * lineage.
+     */
+    File getDeepestFile();
+    
+    /**
+     * Retrieve the remote-repository list for the deepest ancestor which has been resolved so far 
+     * in this lineage.
+     */
+    List getDeepestArtifactRepositoryList();
+    
+    /**
+     * 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 
+     * 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, 
+     * 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 
+     * "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 );
+
+    /**
+     * 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 
+     * 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 
+     * that of the deepest parent at the zero index, and that of the current POM at the last index.
+     */
+    List getArtifactRepositoryListsInDescendingOrder();
+
+    /**
+     * 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 
+     * the deepest ancestor.
+     */
+    Iterator fileIterator();
+
+    /**
+     * 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();
+
+    /**
+     * Retrieve the File from which the given Model instance was read. If the model itself doesn't
+     * belong to this lineage, match it in the lineage by Model.getId().
+     */
+    File getFile( Model model );
+
+    /**
+     * 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 );
+
+    /**
+     * Retrieve the number of entries (POMs) in this lineage.
+     */
+    int size();
+
+}
\ No newline at end of file

Propchange: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/ModelLineage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/ModelLineage.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: 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=auto&rev=496910
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/ModelLineageBuilder.java (added)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/ModelLineageBuilder.java Tue Jan 16 17:36:07 2007
@@ -0,0 +1,44 @@
+package org.apache.maven.project.build.model;
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.profiles.ProfileManager;
+import org.apache.maven.project.ProjectBuildingException;
+
+import java.io.File;
+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.
+ */
+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 
+     * 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 
+     *   should be resolved
+     */
+    ModelLineage buildModelLineage( File pom, ArtifactRepository localRepository, List remoteRepositories, ProfileManager profileManager )
+        throws ProjectBuildingException;
+    
+    /**
+     * Resume the process of constructing a lineage of inherited models, picking up using the deepest
+     * parent already in the lineage.
+     * 
+     */
+    void resumeBuildingModelLineage( ModelLineage lineage, ArtifactRepository localRepository, ProfileManager profileManager )
+        throws ProjectBuildingException;
+
+}

Propchange: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/ModelLineageBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/model/ModelLineageBuilder.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/profile/DefaultProfileAdvisor.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/profile/DefaultProfileAdvisor.java?view=auto&rev=496910
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/profile/DefaultProfileAdvisor.java (added)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/profile/DefaultProfileAdvisor.java Tue Jan 16 17:36:07 2007
@@ -0,0 +1,222 @@
+package org.apache.maven.project.build.profile;
+
+import org.apache.maven.MavenTools;
+import org.apache.maven.artifact.ArtifactUtils;
+import org.apache.maven.artifact.InvalidRepositoryException;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Profile;
+import org.apache.maven.model.Repository;
+import org.apache.maven.profiles.DefaultProfileManager;
+import org.apache.maven.profiles.MavenProfilesBuilder;
+import org.apache.maven.profiles.ProfileManager;
+import org.apache.maven.profiles.ProfilesConversionUtils;
+import org.apache.maven.profiles.ProfilesRoot;
+import org.apache.maven.profiles.activation.ProfileActivationException;
+import org.apache.maven.project.ProjectBuildingException;
+import org.apache.maven.project.injection.ProfileInjector;
+import org.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.context.Context;
+import org.codehaus.plexus.context.ContextException;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Properties;
+
+public class DefaultProfileAdvisor
+    implements ProfileAdvisor, Contextualizable
+{
+
+    public static final String ROLE_HINT = "default";
+
+    private MavenTools mavenTools;
+
+    private MavenProfilesBuilder profilesBuilder;
+
+    private ProfileInjector profileInjector;
+
+    private PlexusContainer container;
+
+    public List applyActivatedProfiles( Model model, File projectDir, List explicitlyActiveIds,
+                                        List explicitlyInactiveIds )
+        throws ProjectBuildingException
+    {
+        ProfileManager profileManager = buildProfileManager( model, projectDir, explicitlyActiveIds,
+                                                             explicitlyInactiveIds );
+
+        return applyActivatedProfiles( model, projectDir, profileManager );
+    }
+
+    public List applyActivatedExternalProfiles( Model model, File projectDir, ProfileManager externalProfileManager )
+        throws ProjectBuildingException
+    {
+        return applyActivatedProfiles( model, projectDir, externalProfileManager );
+    }
+
+    private List applyActivatedProfiles( Model model, File projectDir, ProfileManager profileManager )
+        throws ProjectBuildingException
+    {
+        List activeProfiles;
+
+        if ( profileManager != null )
+        {
+            try
+            {
+                activeProfiles = profileManager.getActiveProfiles();
+            }
+            catch ( ProfileActivationException e )
+            {
+                String groupId = model.getGroupId();
+                if ( groupId == null )
+                {
+                    groupId = "unknown";
+                }
+
+                String artifactId = model.getArtifactId();
+                if ( artifactId == null )
+                {
+                    artifactId = "unknown";
+                }
+
+                String projectId = ArtifactUtils.versionlessKey( groupId, artifactId );
+
+                throw new ProjectBuildingException( projectId, e.getMessage(), e );
+            }
+
+            for ( Iterator it = activeProfiles.iterator(); it.hasNext(); )
+            {
+                Profile profile = (Profile) it.next();
+
+                profileInjector.inject( profile, model );
+            }
+        }
+        else
+        {
+            activeProfiles = Collections.EMPTY_LIST;
+        }
+
+        return activeProfiles;
+    }
+
+    private ProfileManager buildProfileManager( Model model, File projectDir, List explicitlyActiveIds,
+                                                List explicitlyInactiveIds )
+        throws ProjectBuildingException
+    {
+        ProfileManager profileManager = new DefaultProfileManager( container, new Properties() );
+
+        profileManager.explicitlyActivate( explicitlyActiveIds );
+        profileManager.explicitlyDeactivate( explicitlyInactiveIds );
+
+        profileManager.addProfiles( model.getProfiles() );
+
+        if ( projectDir != null )
+        {
+            loadExternalProjectProfiles( profileManager, model, projectDir );
+        }
+
+        return profileManager;
+    }
+
+    public LinkedHashSet getArtifactRepositoriesFromActiveProfiles( Model model, File projectDir,
+                                                                    List explicitlyActiveIds, List explicitlyInactiveIds )
+        throws ProjectBuildingException
+    {
+        ProfileManager profileManager = buildProfileManager( model, projectDir, explicitlyActiveIds,
+                                                             explicitlyInactiveIds );
+
+        List activeExternalProfiles;
+        {
+            try
+            {
+                activeExternalProfiles = profileManager.getActiveProfiles();
+            }
+            catch ( ProfileActivationException e )
+            {
+                throw new ProjectBuildingException( model.getId(),
+                                                    "Failed to compute active profiles for repository aggregation.", e );
+            }
+
+            LinkedHashSet remoteRepositories = new LinkedHashSet();
+
+            for ( Iterator i = activeExternalProfiles.iterator(); i.hasNext(); )
+            {
+                Profile externalProfile = (Profile) i.next();
+
+                for ( Iterator repoIterator = externalProfile.getRepositories().iterator(); repoIterator.hasNext(); )
+                {
+                    Repository mavenRepo = (Repository) repoIterator.next();
+
+                    ArtifactRepository artifactRepo = null;
+                    try
+                    {
+                        artifactRepo = mavenTools.buildArtifactRepository( mavenRepo );
+                    }
+                    catch ( InvalidRepositoryException e )
+                    {
+                        throw new ProjectBuildingException( model.getId(), e.getMessage(), e );
+                    }
+
+                    remoteRepositories.add( artifactRepo );
+                }
+            }
+
+            return remoteRepositories;
+        }
+    }
+
+    private void loadExternalProjectProfiles( ProfileManager profileManager, Model model, File projectDir )
+        throws ProjectBuildingException
+    {
+        if ( projectDir != null )
+        {
+            try
+            {
+                ProfilesRoot root = profilesBuilder.buildProfiles( projectDir );
+
+                if ( root != null )
+                {
+                    List active = root.getActiveProfiles();
+
+                    if ( active != null && !active.isEmpty() )
+                    {
+                        profileManager.explicitlyActivate( root.getActiveProfiles() );
+                    }
+
+                    for ( Iterator it = root.getProfiles().iterator(); it.hasNext(); )
+                    {
+                        org.apache.maven.profiles.Profile rawProfile = (org.apache.maven.profiles.Profile) it.next();
+
+                        Profile converted = ProfilesConversionUtils.convertFromProfileXmlProfile( rawProfile );
+
+                        profileManager.addProfile( converted );
+                    }
+                }
+            }
+            catch ( IOException e )
+            {
+                throw new ProjectBuildingException( model.getId(), "Cannot read profiles.xml resource from directory: "
+                    + projectDir, e );
+            }
+            catch ( XmlPullParserException e )
+            {
+                throw new ProjectBuildingException( model.getId(),
+                                                    "Cannot parse profiles.xml resource from directory: " + projectDir,
+                                                    e );
+            }
+        }
+    }
+
+    public void contextualize( Context context )
+        throws ContextException
+    {
+        this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
+    }
+
+}

Propchange: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/profile/DefaultProfileAdvisor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/profile/DefaultProfileAdvisor.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/profile/ProfileAdvisor.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/profile/ProfileAdvisor.java?view=auto&rev=496910
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/profile/ProfileAdvisor.java (added)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/profile/ProfileAdvisor.java Tue Jan 16 17:36:07 2007
@@ -0,0 +1,30 @@
+package org.apache.maven.project.build.profile;
+
+import org.apache.maven.model.Model;
+import org.apache.maven.profiles.ProfileManager;
+import org.apache.maven.project.ProjectBuildingException;
+
+import java.io.File;
+import java.util.LinkedHashSet;
+import java.util.List;
+
+/**
+ * 
+ * @author jdcasey
+ *
+ */
+public interface ProfileAdvisor
+{
+    
+    String ROLE = ProfileAdvisor.class.getName();
+    
+    LinkedHashSet getArtifactRepositoriesFromActiveProfiles( Model model, File projectDir, List explicitlyActiveIds, List explicitlyInactiveIds )
+        throws ProjectBuildingException;
+    
+    List applyActivatedProfiles( Model model, File projectDir, List explicitlyActiveIds, List explicitlyInactiveIds )
+        throws ProjectBuildingException;
+
+    List applyActivatedExternalProfiles( Model model, File projectDir, ProfileManager externalProfileManager )
+        throws ProjectBuildingException;
+
+}

Propchange: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/profile/ProfileAdvisor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/build/profile/ProfileAdvisor.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/components/trunk/maven-project/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/resources/META-INF/plexus/components.xml?view=diff&rev=496910&r1=496909&r2=496910
==============================================================================
--- maven/components/trunk/maven-project/src/main/resources/META-INF/plexus/components.xml (original)
+++ maven/components/trunk/maven-project/src/main/resources/META-INF/plexus/components.xml Tue Jan 16 17:36:07 2007
@@ -1,5 +1,45 @@
 <component-set>
   <components>
+    <component>
+      <role>org.apache.maven.project.build.profile.ProfileAdvisor</role>
+      <role-hint>default</role-hint>
+      <implementation>org.apache.maven.project.build.profile.DefaultProfileAdvisor</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.MavenTools</role>
+        </requirement>
+        <requirement>
+          <role>org.apache.maven.profiles.MavenProfilesBuilder</role>
+        </requirement>
+        <requirement>
+          <role>org.apache.maven.project.injection.ProfileInjector</role>
+        </requirement>
+      </requirements>
+    </component>
+    
+    
+    
+    
+    <component>
+      <role>org.apache.maven.project.build.model.ModelLineageBuilder</role>
+      <role-hint>default</role-hint>
+      <implementation>org.apache.maven.project.build.model.DefaultModelLineageBuilder</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.project.build.profile.ProfileAdvisor</role>
+          <role-hint>default</role-hint>
+        </requirement>
+        <requirement>
+          <role>org.apache.maven.artifact.factory.ArtifactFactory</role>
+        </requirement>
+        <requirement>
+          <role>org.apache.maven.MavenTools</role>
+        </requirement>
+        <requirement>
+          <role>org.apache.maven.artifact.resolver.ArtifactResolver</role>
+        </requirement>
+      </requirements>
+    </component>
 <!--
      |
      |
@@ -50,6 +90,14 @@
       <role>org.apache.maven.project.MavenProjectBuilder</role>
       <implementation>org.apache.maven.project.DefaultMavenProjectBuilder</implementation>
       <requirements>
+        <requirement>
+          <role>org.apache.maven.project.build.model.ModelLineageBuilder</role>
+          <role-hint>default</role-hint>
+        </requirement>
+        <requirement>
+          <role>org.apache.maven.project.build.profile.ProfileAdvisor</role>
+          <role-hint>default</role-hint>
+        </requirement>
         <requirement>
           <role>org.apache.maven.profiles.MavenProfilesBuilder</role>
         </requirement>

Added: maven/components/trunk/maven-project/src/test/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivatorTest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/test/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivatorTest.java?view=auto&rev=496910
==============================================================================
--- maven/components/trunk/maven-project/src/test/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivatorTest.java (added)
+++ maven/components/trunk/maven-project/src/test/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivatorTest.java Tue Jan 16 17:36:07 2007
@@ -0,0 +1,95 @@
+package org.apache.maven.profiles.activation;
+
+import org.apache.maven.model.Activation;
+import org.apache.maven.model.ActivationProperty;
+import org.apache.maven.model.Profile;
+import org.codehaus.plexus.context.ContextException;
+import org.codehaus.plexus.context.DefaultContext;
+
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+public class SystemPropertyProfileActivatorTest
+    extends TestCase
+{
+
+    public void testCanDetect_ShouldReturnTrueWhenActivationPropertyIsPresent()
+        throws ContextException
+    {
+        ActivationProperty prop = new ActivationProperty();
+        prop.setName( "test" );
+
+        Activation activation = new Activation();
+
+        activation.setProperty( prop );
+
+        Profile profile = new Profile();
+
+        profile.setActivation( activation );
+
+        assertTrue( buildProfileActivator().canDetermineActivation( profile ) );
+    }
+
+    public void testCanDetect_ShouldReturnFalseWhenActivationPropertyIsNotPresent()
+        throws ContextException
+    {
+        Activation activation = new Activation();
+
+        Profile profile = new Profile();
+
+        profile.setActivation( activation );
+
+        assertFalse( buildProfileActivator().canDetermineActivation( profile ) );
+    }
+
+    public void testIsActive_ShouldReturnTrueWhenPropertyNameSpecifiedAndPresent()
+        throws ContextException
+    {
+        ActivationProperty prop = new ActivationProperty();
+        prop.setName( "test" );
+
+        Activation activation = new Activation();
+
+        activation.setProperty( prop );
+
+        Profile profile = new Profile();
+
+        profile.setActivation( activation );
+
+        System.setProperty( "test", "true" );
+
+        assertTrue( buildProfileActivator().isActive( profile ) );
+    }
+
+    public void testIsActive_ShouldReturnFalseWhenPropertyNameSpecifiedAndMissing()
+        throws ContextException
+    {
+        ActivationProperty prop = new ActivationProperty();
+        prop.setName( "test" );
+
+        Activation activation = new Activation();
+
+        activation.setProperty( prop );
+
+        Profile profile = new Profile();
+
+        profile.setActivation( activation );
+
+        Properties props = System.getProperties();
+        props.remove( "test" );
+        System.setProperties( props );
+
+        assertFalse( buildProfileActivator().isActive( profile ) );
+    }
+
+    private SystemPropertyProfileActivator buildProfileActivator()
+        throws ContextException
+    {
+        SystemPropertyProfileActivator activator = new SystemPropertyProfileActivator();
+        activator.contextualize( new DefaultContext() );
+
+        return activator;
+    }
+
+}

Propchange: maven/components/trunk/maven-project/src/test/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-project/src/test/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivatorTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"