mirror of https://github.com/apache/maven.git
[MNG-6609] Profile activation based on packaging (#883)
In short: do NOT set request.setRawModel as NOTHING sets it. The Maven4 vs Maven3 is different, in Maven 3 NOTHING calls request.setRawModel Full explanation: as ModelBuildingRequest is REUSED, and nothing sets this value in Maven3, once you set it here (as in original PR https://github.com/apache/maven/pull/849 ) results in awkward situation in Maven3: it will not load any other model... --- https://issues.apache.org/jira/browse/MNG-6609
This commit is contained in:
parent
36ff9a65e6
commit
4c95a50332
|
@ -276,8 +276,15 @@ public class DefaultModelBuilder
|
||||||
|
|
||||||
DefaultModelProblemCollector problems = new DefaultModelProblemCollector( result );
|
DefaultModelProblemCollector problems = new DefaultModelProblemCollector( result );
|
||||||
|
|
||||||
|
// read and validate raw model
|
||||||
|
Model inputModel = request.getRawModel();
|
||||||
|
if ( inputModel == null )
|
||||||
|
{
|
||||||
|
inputModel = readModel( request.getModelSource(), request.getPomFile(), request, problems );
|
||||||
|
}
|
||||||
|
|
||||||
// profile activation
|
// profile activation
|
||||||
DefaultProfileActivationContext profileActivationContext = getProfileActivationContext( request );
|
DefaultProfileActivationContext profileActivationContext = getProfileActivationContext( request, inputModel );
|
||||||
|
|
||||||
problems.setSource( "(external profiles)" );
|
problems.setSource( "(external profiles)" );
|
||||||
List<Profile> activeExternalProfiles = profileSelector.getActiveProfiles( request.getProfiles(),
|
List<Profile> activeExternalProfiles = profileSelector.getActiveProfiles( request.getProfiles(),
|
||||||
|
@ -296,13 +303,6 @@ public class DefaultModelBuilder
|
||||||
profileActivationContext.setUserProperties( profileProps );
|
profileActivationContext.setUserProperties( profileProps );
|
||||||
}
|
}
|
||||||
|
|
||||||
// read and validate raw model
|
|
||||||
Model inputModel = request.getRawModel();
|
|
||||||
if ( inputModel == null )
|
|
||||||
{
|
|
||||||
inputModel = readModel( request.getModelSource(), request.getPomFile(), request, problems );
|
|
||||||
}
|
|
||||||
|
|
||||||
problems.setRootModel( inputModel );
|
problems.setRootModel( inputModel );
|
||||||
|
|
||||||
ModelData resultData = new ModelData( request.getModelSource(), inputModel );
|
ModelData resultData = new ModelData( request.getModelSource(), inputModel );
|
||||||
|
@ -700,14 +700,18 @@ public class DefaultModelBuilder
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
private DefaultProfileActivationContext getProfileActivationContext( ModelBuildingRequest request )
|
private DefaultProfileActivationContext getProfileActivationContext( ModelBuildingRequest request, Model rawModel )
|
||||||
{
|
{
|
||||||
DefaultProfileActivationContext context = new DefaultProfileActivationContext();
|
DefaultProfileActivationContext context = new DefaultProfileActivationContext();
|
||||||
|
|
||||||
context.setActiveProfileIds( request.getActiveProfileIds() );
|
context.setActiveProfileIds( request.getActiveProfileIds() );
|
||||||
context.setInactiveProfileIds( request.getInactiveProfileIds() );
|
context.setInactiveProfileIds( request.getInactiveProfileIds() );
|
||||||
context.setSystemProperties( request.getSystemProperties() );
|
context.setSystemProperties( request.getSystemProperties() );
|
||||||
context.setUserProperties( request.getUserProperties() );
|
// enrich user properties with project packaging
|
||||||
|
Properties userProperties = request.getUserProperties();
|
||||||
|
userProperties.computeIfAbsent( (Object) ProfileActivationContext.PROPERTY_NAME_PACKAGING,
|
||||||
|
( p ) -> (Object) rawModel.getPackaging() );
|
||||||
|
context.setUserProperties( userProperties );
|
||||||
context.setProjectDirectory( ( request.getPomFile() != null ) ? request.getPomFile().getParentFile() : null );
|
context.setProjectDirectory( ( request.getPomFile() != null ) ? request.getPomFile().getParentFile() : null );
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
|
|
|
@ -30,6 +30,12 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public interface ProfileActivationContext
|
public interface ProfileActivationContext
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Key of the property containing the project's packaging.
|
||||||
|
* Available in {@link #getUserProperties()}.
|
||||||
|
* @since 3.9
|
||||||
|
*/
|
||||||
|
String PROPERTY_NAME_PACKAGING = "packaging";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the identifiers of those profiles that should be activated by explicit demand.
|
* Gets the identifiers of those profiles that should be activated by explicit demand.
|
||||||
|
|
Loading…
Reference in New Issue