diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileInjector.java b/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileInjector.java
index 1773587c06d8..558653c23bf5 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileInjector.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileInjector.java
@@ -42,15 +42,44 @@ public interface ProfileInjector {
*/
void injectProfile(Model model, Profile profile, ModelBuildingRequest request, ModelProblemCollector problems);
- org.apache.maven.api.model.Model injectProfile(
+ /**
+ * Merges values from the specified profile into the given model. Implementations are expected to keep the profile
+ * and model completely decoupled by injecting deep copies rather than the original objects from the profile.
+ *
+ * @param model The model into which to merge the values defined by the profile, must not be null
.
+ * @param profile The (read-only) profile whose values should be injected, may be null
.
+ * @param request The model building request that holds further settings, must not be {@code null}.
+ * @param problems The container used to collect problems that were encountered, must not be {@code null}.
+ */
+ default org.apache.maven.api.model.Model injectProfile(
org.apache.maven.api.model.Model model,
org.apache.maven.api.model.Profile profile,
ModelBuildingRequest request,
- ModelProblemCollector problems);
+ ModelProblemCollector problems) {
+ Model m = new Model(model);
+ injectProfile(m, profile != null ? new Profile(profile) : null, request, problems);
+ return m.getDelegate();
+ }
- org.apache.maven.api.model.Model injectProfiles(
+ /**
+ * Merges values from the specified profile into the given model. Implementations are expected to keep the profile
+ * and model completely decoupled by injecting deep copies rather than the original objects from the profile.
+ *
+ * @param model The model into which to merge the values defined by the profile, must not be null
.
+ * @param profiles The (read-only) list of profiles whose values should be injected, must not be null
.
+ * @param request The model building request that holds further settings, must not be {@code null}.
+ * @param problems The container used to collect problems that were encountered, must not be {@code null}.
+ */
+ default org.apache.maven.api.model.Model injectProfiles(
org.apache.maven.api.model.Model model,
List profiles,
ModelBuildingRequest request,
- ModelProblemCollector problems);
+ ModelProblemCollector problems) {
+ for (org.apache.maven.api.model.Profile profile : profiles) {
+ if (profile != null) {
+ model = injectProfile(model, profile, request, problems);
+ }
+ }
+ return model;
+ }
}
diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileSelector.java b/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileSelector.java
index 75b956e6f6a3..4a66309e22ef 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileSelector.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileSelector.java
@@ -20,6 +20,7 @@
import java.util.Collection;
import java.util.List;
+import java.util.stream.Collectors;
import org.apache.maven.model.Profile;
import org.apache.maven.model.building.ModelProblemCollector;
@@ -43,8 +44,23 @@ public interface ProfileSelector {
List getActiveProfiles(
Collection profiles, ProfileActivationContext context, ModelProblemCollector problems);
- List getActiveProfilesV4(
+ /**
+ * Determines the profiles which are active in the specified activation context. Active profiles will eventually be
+ * injected into the model.
+ *
+ * @param profiles The profiles whose activation status should be determined, must not be {@code null}.
+ * @param context The environmental context used to determine the activation status of a profile, must not be
+ * {@code null}.
+ * @param problems The container used to collect problems that were encountered, must not be {@code null}.
+ * @return The profiles that have been activated, never {@code null}.
+ */
+ default List getActiveProfilesV4(
Collection profiles,
ProfileActivationContext context,
- ModelProblemCollector problems);
+ ModelProblemCollector problems) {
+ return getActiveProfiles(profiles.stream().map(Profile::new).collect(Collectors.toList()), context, problems)
+ .stream()
+ .map(Profile::getDelegate)
+ .collect(Collectors.toList());
+ }
}