[MNG-6609] Maven 3.9: profile activation by packaging (#849)

Generate raw model before profile activation context is generated
This commit is contained in:
Konrad Windszus 2022-11-27 16:49:43 +01:00 committed by GitHub
parent eb66f225db
commit e921f1564e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 8 deletions

View File

@ -276,6 +276,14 @@ public class DefaultModelBuilder
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 );
request.setRawModel( inputModel );
}
// profile activation
DefaultProfileActivationContext profileActivationContext = getProfileActivationContext( request );
@ -296,13 +304,6 @@ public class DefaultModelBuilder
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 );
ModelData resultData = new ModelData( request.getModelSource(), inputModel );
@ -707,7 +708,11 @@ public class DefaultModelBuilder
context.setActiveProfileIds( request.getActiveProfileIds() );
context.setInactiveProfileIds( request.getInactiveProfileIds() );
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) request.getRawModel().getPackaging() );
context.setUserProperties( userProperties );
context.setProjectDirectory( ( request.getPomFile() != null ) ? request.getPomFile().getParentFile() : null );
return context;

View File

@ -30,6 +30,12 @@ import java.util.Map;
*/
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.