maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bentm...@apache.org
Subject svn commit: r784583 - in /maven/components/trunk: maven-core/src/main/java/org/apache/maven/project/ maven-model-builder/src/main/java/org/apache/maven/model/
Date Sun, 14 Jun 2009 16:46:16 GMT
Author: bentmann
Date: Sun Jun 14 16:46:16 2009
New Revision: 784583

URL: http://svn.apache.org/viewvc?rev=784583&view=rev
Log:
o Kept active external and POM profiles separate in model building result

Modified:
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuildingResult.java
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/ModelBuildingResult.java

Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java?rev=784583&r1=784582&r2=784583&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
(original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
Sun Jun 14 16:46:16 2009
@@ -17,7 +17,8 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.util.Date;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.ArtifactUtils;
@@ -36,6 +37,7 @@
 import org.apache.maven.model.ModelBuildingException;
 import org.apache.maven.model.ModelBuildingRequest;
 import org.apache.maven.model.ModelBuildingResult;
+import org.apache.maven.model.Profile;
 import org.apache.maven.model.io.ModelReader;
 import org.apache.maven.model.resolution.ModelResolver;
 import org.apache.maven.project.artifact.ProjectArtifact;
@@ -141,7 +143,11 @@
         project.addCompileSourceRoot( build.getSourceDirectory() );
         project.addTestCompileSourceRoot( build.getTestSourceDirectory() );
         project.setFile( pomFile );
-        project.setActiveProfiles( result.getActiveProfiles( result.getRawModel() ) );
+
+        List<Profile> activeProfiles = new ArrayList<Profile>();
+        activeProfiles.addAll( result.getActivePomProfiles( result.getRawModel() ) );
+        activeProfiles.addAll( result.getActiveExternalProfiles() );
+        project.setActiveProfiles( activeProfiles );
                 
         return project;
     }

Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java?rev=784583&r1=784582&r2=784583&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java
(original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java
Sun Jun 14 16:46:16 2009
@@ -117,6 +117,8 @@
 
         List<Profile> activeExternalProfiles = getActiveExternalProfiles( request,
profileActivationContext, problems );
 
+        result.setActiveExternalProfiles( activeExternalProfiles );
+
         Model model = readModel( modelSource, pomFile, request, problems );
 
         List<Model> rawModels = new ArrayList<Model>();
@@ -132,23 +134,22 @@
 
             modelNormalizer.mergeDuplicates( resultModel, request );
 
-            List<Profile> activeProjectProfiles =
-                getActiveProjectProfiles( rawModel, profileActivationContext, problems );
+            List<Profile> activePomProfiles = getActivePomProfiles( rawModel, profileActivationContext,
problems );
 
-            List<Profile> activeProfiles = activeProjectProfiles;
-            if ( current == model )
-            {
-                activeProfiles = new ArrayList<Profile>( activeProjectProfiles.size()
+ activeExternalProfiles.size() );
-                activeProfiles.addAll( activeProjectProfiles );
-                activeProfiles.addAll( activeExternalProfiles );
-            }
+            result.setActivePomProfiles( rawModel, activePomProfiles );
 
-            for ( Profile activeProfile : activeProfiles )
+            for ( Profile activeProfile : activePomProfiles )
             {
                 profileInjector.injectProfile( resultModel, activeProfile, request );
             }
 
-            result.setActiveProfiles( rawModel, activeProfiles );
+            if ( current == model )
+            {
+                for ( Profile activeProfile : activeExternalProfiles )
+                {
+                    profileInjector.injectProfile( resultModel, activeProfile, request );
+                }
+            }
 
             configureResolver( request.getModelResolver(), resultModel, problems );
         }
@@ -265,8 +266,8 @@
         return result.getActiveProfiles();
     }
 
-    private List<Profile> getActiveProjectProfiles( Model model, ProfileActivationContext
context,
-                                                    List<ModelProblem> problems )
+    private List<Profile> getActivePomProfiles( Model model, ProfileActivationContext
context,
+                                                List<ModelProblem> problems )
     {
         ProfileSelectionResult result = profileSelector.getActiveProfiles( model.getProfiles(),
context );
 

Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuildingResult.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuildingResult.java?rev=784583&r1=784582&r2=784583&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuildingResult.java
(original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuildingResult.java
Sun Jun 14 16:46:16 2009
@@ -38,12 +38,15 @@
 
     private List<Model> rawModels;
 
-    private Map<Model, List<Profile>> activeProfiles;
+    private Map<Model, List<Profile>> activePomProfiles;
+
+    private List<Profile> activeExternalProfiles;
 
     public DefaultModelBuildingResult()
     {
         rawModels = new ArrayList<Model>();
-        activeProfiles = new HashMap<Model, List<Profile>>();
+        activePomProfiles = new HashMap<Model, List<Profile>>();
+        activeExternalProfiles = new ArrayList<Profile>();
     }
 
     public Model getEffectiveModel()
@@ -79,13 +82,13 @@
         return this;
     }
 
-    public List<Profile> getActiveProfiles( Model rawModel )
+    public List<Profile> getActivePomProfiles( Model rawModel )
     {
-        List<Profile> profiles = this.activeProfiles.get( rawModel );
+        List<Profile> profiles = this.activePomProfiles.get( rawModel );
         return ( profiles == null ) ? Collections.<Profile> emptyList() : Collections.unmodifiableList(
profiles );
     }
 
-    public DefaultModelBuildingResult setActiveProfiles( Model rawModel, List<Profile>
activeProfiles )
+    public DefaultModelBuildingResult setActivePomProfiles( Model rawModel, List<Profile>
activeProfiles )
     {
         if ( rawModel == null )
         {
@@ -94,32 +97,48 @@
 
         if ( activeProfiles != null )
         {
-            this.activeProfiles.put( rawModel, new ArrayList<Profile>( activeProfiles
) );
+            this.activePomProfiles.put( rawModel, new ArrayList<Profile>( activeProfiles
) );
         }
         else
         {
-            this.activeProfiles.remove( rawModel );
+            this.activePomProfiles.remove( rawModel );
         }
 
         return this;
     }
 
-    public DefaultModelBuildingResult addActiveProfiles( Model rawModel, List<Profile>
activeProfiles )
+    public DefaultModelBuildingResult addActivePomProfiles( Model rawModel, List<Profile>
activeProfiles )
     {
         if ( rawModel == null )
         {
             throw new IllegalArgumentException( "no model specified" );
         }
 
-        List<Profile> currentProfiles = this.activeProfiles.get( rawModel );
+        List<Profile> currentProfiles = this.activePomProfiles.get( rawModel );
         if ( currentProfiles == null )
         {
             currentProfiles = new ArrayList<Profile>( activeProfiles.size() );
-            this.activeProfiles.put( rawModel, currentProfiles );
+            this.activePomProfiles.put( rawModel, currentProfiles );
         }
         currentProfiles.addAll( activeProfiles );
 
         return this;
     }
 
+    public List<Profile> getActiveExternalProfiles()
+    {
+        return Collections.unmodifiableList( activeExternalProfiles );
+    }
+
+    public DefaultModelBuildingResult setActiveExternalProfiles( List<Profile> activeProfiles
)
+    {
+        this.activeExternalProfiles.clear();
+        if ( activeProfiles != null )
+        {
+            this.activeExternalProfiles.addAll( activeProfiles );
+        }
+
+        return this;
+    }
+
 }

Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/ModelBuildingResult.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/ModelBuildingResult.java?rev=784583&r1=784582&r2=784583&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/ModelBuildingResult.java
(original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/ModelBuildingResult.java
Sun Jun 14 16:46:16 2009
@@ -29,12 +29,44 @@
 public interface ModelBuildingResult
 {
 
+    /**
+     * Gets the fully assembled model.
+     * 
+     * @return The fully assembled model, never {@code null}.
+     */
     Model getEffectiveModel();
 
+    /**
+     * Gets the raw model as it was read from the model source. Apart from basic validation,
the raw model has not
+     * undergone any updates by the model builder, e.g. reflects neither inheritance or interpolation.
+     * 
+     * @return The raw model, never {@code null}.
+     */
     Model getRawModel();
 
+    /**
+     * Gets the lineage of raw models from which the effective model was constructed. The
first model is the model on
+     * which the model builder was originally invoked, the last model is the super POM.
+     * 
+     * @return The lineage of raw models, never {@code null}.
+     */
     List<Model> getRawModels();
 
-    List<Profile> getActiveProfiles( Model rawModel );
+    /**
+     * Gets the profiles from the specified (raw) model that were active during model building.
The input parameter
+     * should be a model from the collection obtained by {@link #getRawModels()}.
+     * 
+     * @param rawModel The (raw) model for whose active profiles should be retrieved, must
not be {@code null}.
+     * @return The active profiles of the model or an empty list if none, never {@code null}.
+     */
+    List<Profile> getActivePomProfiles( Model rawModel );
+
+    /**
+     * Gets the external profiles that were active during model building. External profiles
are those that were
+     * contributed by {@link ModelBuildingRequest#getProfiles()}.
+     * 
+     * @return The active external profiles or an empty list if none, never {@code null}.
+     */
+    List<Profile> getActiveExternalProfiles();
 
 }



Mime
View raw message