You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by cs...@apache.org on 2022/12/01 11:51:28 UTC
[maven] branch maven-3.9.x updated: [MNG-6609] Profile activation based on packaging (#883)
This is an automated email from the ASF dual-hosted git repository.
cstamas pushed a commit to branch maven-3.9.x
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/maven-3.9.x by this push:
new 4c95a5033 [MNG-6609] Profile activation based on packaging (#883)
4c95a5033 is described below
commit 4c95a50332f9f0acd853d977a618629431430e4d
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Thu Dec 1 12:51:18 2022 +0100
[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
---
.../maven/model/building/DefaultModelBuilder.java | 24 +++++++++++++---------
.../model/profile/ProfileActivationContext.java | 6 ++++++
2 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index a2faac300..5c79caea4 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -276,8 +276,15 @@ 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 );
+ }
+
// profile activation
- DefaultProfileActivationContext profileActivationContext = getProfileActivationContext( request );
+ DefaultProfileActivationContext profileActivationContext = getProfileActivationContext( request, inputModel );
problems.setSource( "(external profiles)" );
List<Profile> activeExternalProfiles = profileSelector.getActiveProfiles( request.getProfiles(),
@@ -296,13 +303,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 );
@@ -700,14 +700,18 @@ public class DefaultModelBuilder
return model;
}
- private DefaultProfileActivationContext getProfileActivationContext( ModelBuildingRequest request )
+ private DefaultProfileActivationContext getProfileActivationContext( ModelBuildingRequest request, Model rawModel )
{
DefaultProfileActivationContext context = new DefaultProfileActivationContext();
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) rawModel.getPackaging() );
+ context.setUserProperties( userProperties );
context.setProjectDirectory( ( request.getPomFile() != null ) ? request.getPomFile().getParentFile() : null );
return context;
diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileActivationContext.java b/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileActivationContext.java
index d501e660a..cd6bd48ac 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileActivationContext.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileActivationContext.java
@@ -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.