Skip to content

Commit

Permalink
Use default methods and add javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Dec 5, 2022
1 parent 0ceb5b1 commit 7d7e278
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>null</code>.
* @param profile The (read-only) profile whose values should be injected, may be <code>null</code>.
* @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 <code>null</code>.
* @param profiles The (read-only) list of profiles whose values should be injected, must not be <code>null</code>.
* @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<org.apache.maven.api.model.Profile> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -43,8 +44,23 @@ public interface ProfileSelector {
List<Profile> getActiveProfiles(
Collection<Profile> profiles, ProfileActivationContext context, ModelProblemCollector problems);

List<org.apache.maven.api.model.Profile> 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<org.apache.maven.api.model.Profile> getActiveProfilesV4(
Collection<org.apache.maven.api.model.Profile> 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());
}
}

0 comments on commit 7d7e278

Please sign in to comment.