o Kept active external and POM profiles separate in model building result

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@784583 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-06-14 16:46:16 +00:00
parent 05a782b347
commit cd9056d1fd
4 changed files with 84 additions and 26 deletions

View File

@ -17,7 +17,8 @@ package org.apache.maven.project;
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.ModelBuilder;
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 @@ public class DefaultProjectBuilder
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;
}

View File

@ -117,6 +117,8 @@ public class DefaultModelBuilder
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 @@ public class DefaultModelBuilder
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 @@ public class DefaultModelBuilder
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 );

View File

@ -38,12 +38,15 @@ public class DefaultModelBuildingResult
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 @@ public class DefaultModelBuildingResult
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 @@ public class DefaultModelBuildingResult
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;
}
}

View File

@ -29,12 +29,44 @@ import java.util.List;
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();
}