o Decoupled model building request from profile activation context

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@781144 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-06-02 20:07:26 +00:00
parent 2b12aab7e1
commit 1d3df2ed0c
3 changed files with 48 additions and 44 deletions

View File

@ -37,6 +37,8 @@ import org.apache.maven.model.normalization.ModelNormalizer;
import org.apache.maven.model.path.ModelPathTranslator;
import org.apache.maven.model.plugin.LifecycleBindingsInjector;
import org.apache.maven.model.plugin.PluginConfigurationExpander;
import org.apache.maven.model.profile.DefaultProfileActivationContext;
import org.apache.maven.model.profile.ProfileActivationContext;
import org.apache.maven.model.profile.ProfileActivationException;
import org.apache.maven.model.profile.ProfileInjector;
import org.apache.maven.model.profile.ProfileSelector;
@ -109,7 +111,9 @@ public class DefaultModelBuilder
{
DefaultModelBuildingResult result = new DefaultModelBuildingResult();
List<Profile> activeExternalProfiles = getActiveExternalProfiles( request );
ProfileActivationContext profileActivationContext = getProfileActivationContext( request );
List<Profile> activeExternalProfiles = getActiveExternalProfiles( request, profileActivationContext );
Model model = readModel( modelSource, request );
model.setPomFile( pomFile );
@ -127,7 +131,7 @@ public class DefaultModelBuilder
modelNormalizer.mergeDuplicates( resultModel, request );
List<Profile> activeProjectProfiles = getActiveProjectProfiles( rawModel, request );
List<Profile> activeProjectProfiles = getActiveProjectProfiles( rawModel, profileActivationContext );
List<Profile> activeProfiles = activeProjectProfiles;
if ( current == model )
@ -181,6 +185,15 @@ public class DefaultModelBuilder
return result;
}
private ProfileActivationContext getProfileActivationContext( ModelBuildingRequest request )
{
ProfileActivationContext context = new DefaultProfileActivationContext();
context.setActiveProfileIds( request.getActiveProfileIds() );
context.setInactiveProfileIds( request.getInactiveProfileIds() );
context.setExecutionProperties( request.getExecutionProperties() );
return context;
}
private Model readModel( ModelSource modelSource, ModelBuildingRequest request )
throws ModelBuildingException
{
@ -228,12 +241,12 @@ public class DefaultModelBuilder
}
}
private List<Profile> getActiveExternalProfiles( ModelBuildingRequest request )
private List<Profile> getActiveExternalProfiles( ModelBuildingRequest request, ProfileActivationContext context )
throws ModelBuildingException
{
try
{
return profileSelector.getActiveProfiles( request.getProfiles(), request.getProfileActivationContext() );
return profileSelector.getActiveProfiles( request.getProfiles(), context );
}
catch ( ProfileActivationException e )
{
@ -242,12 +255,12 @@ public class DefaultModelBuilder
}
}
private List<Profile> getActiveProjectProfiles( Model model, ModelBuildingRequest request )
private List<Profile> getActiveProjectProfiles( Model model, ProfileActivationContext context )
throws ModelBuildingException
{
try
{
return profileSelector.getActiveProfiles( model.getProfiles(), request.getProfileActivationContext() );
return profileSelector.getActiveProfiles( model.getProfiles(), context );
}
catch ( ProfileActivationException e )
{

View File

@ -23,9 +23,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.apache.maven.model.profile.DefaultProfileActivationContext;
import org.apache.maven.model.profile.ProfileActivationContext;
/**
* Collects settings that control building of effective models.
*
@ -41,12 +38,18 @@ public class DefaultModelBuildingRequest
private List<Profile> profiles;
private ProfileActivationContext profileActivationContext;
private List<String> activeProfileIds;
private List<String> inactiveProfileIds;
private Properties executionProperties;
public DefaultModelBuildingRequest()
{
profiles = new ArrayList<Profile>();
profileActivationContext = new DefaultProfileActivationContext();
activeProfileIds = new ArrayList<String>();
inactiveProfileIds = new ArrayList<String>();
executionProperties = new Properties();
}
public boolean istLenientValidation()
@ -91,51 +94,49 @@ public class DefaultModelBuildingRequest
public List<String> getActiveProfileIds()
{
return profileActivationContext.getActiveProfileIds();
return activeProfileIds;
}
public ModelBuildingRequest setActiveProfileIds( List<String> activeProfileIds )
public DefaultModelBuildingRequest setActiveProfileIds( List<String> activeProfileIds )
{
profileActivationContext.setActiveProfileIds( activeProfileIds );
this.activeProfileIds.clear();
if ( activeProfileIds != null )
{
this.activeProfileIds.addAll( activeProfileIds );
}
return this;
}
public List<String> getInactiveProfileIds()
{
return profileActivationContext.getInactiveProfileIds();
return inactiveProfileIds;
}
public ModelBuildingRequest setInactiveProfileIds( List<String> inactiveProfileIds )
public DefaultModelBuildingRequest setInactiveProfileIds( List<String> inactiveProfileIds )
{
profileActivationContext.setInactiveProfileIds( inactiveProfileIds );
this.inactiveProfileIds.clear();
if ( inactiveProfileIds != null )
{
this.inactiveProfileIds.addAll( inactiveProfileIds );
}
return this;
}
public Properties getExecutionProperties()
{
return profileActivationContext.getExecutionProperties();
return executionProperties;
}
public ModelBuildingRequest setExecutionProperties( Properties executionProperties )
public DefaultModelBuildingRequest setExecutionProperties( Properties executionProperties )
{
profileActivationContext.setExecutionProperties( executionProperties );
return this;
}
public ProfileActivationContext getProfileActivationContext()
{
return profileActivationContext;
}
public DefaultModelBuildingRequest setProfileActivationContext( ProfileActivationContext profileActivationContext )
{
if ( profileActivationContext == null )
this.executionProperties.clear();
if ( executionProperties != null )
{
throw new IllegalArgumentException( "no profile activation context specified" );
this.executionProperties.putAll( executionProperties );
}
this.profileActivationContext = profileActivationContext;
return this;
}

View File

@ -22,8 +22,6 @@ package org.apache.maven.model;
import java.util.List;
import java.util.Properties;
import org.apache.maven.model.profile.ProfileActivationContext;
/**
* Collects settings that control the building of effective models.
*
@ -129,12 +127,4 @@ public interface ModelBuildingRequest
*/
ModelBuildingRequest setExecutionProperties( Properties executionProperties );
/**
* Gets the profile activation context for this request. The activation context is basically a view on a subset of
* settings from this request, manipulations to the request are reflected by the activation context and vice versa.
*
* @return The profile activation context for this request, never {@code null}.
*/
ProfileActivationContext getProfileActivationContext();
}