Skip to content

Commit

Permalink
[MNG-3309] Cascading profile activation
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Oct 25, 2024
1 parent 3b24de6 commit 3d21d5f
Show file tree
Hide file tree
Showing 11 changed files with 279 additions and 252 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.apache.maven.internal.impl.model.DefaultPluginManagementInjector;
import org.apache.maven.internal.impl.model.DefaultProfileInjector;
import org.apache.maven.internal.impl.model.DefaultProfileSelector;
import org.apache.maven.internal.impl.model.ProfileActivationFilePathInterpolator;
import org.apache.maven.internal.impl.model.rootlocator.DefaultRootLocator;
import org.apache.maven.internal.impl.resolver.DefaultArtifactDescriptorReader;
import org.apache.maven.internal.impl.resolver.DefaultModelResolver;
Expand Down Expand Up @@ -1049,14 +1048,12 @@ protected ModelBuilder createModelBuilder() {
new DefaultModelUrlNormalizer(new DefaultUrlNormalizer()),
new DefaultSuperPomProvider(modelProcessor),
new DefaultInheritanceAssembler(),
new DefaultProfileSelector(),
new DefaultProfileSelector(null, null),
new DefaultProfileInjector(),
new DefaultPluginManagementInjector(),
new DefaultDependencyManagementInjector(),
new DefaultDependencyManagementImporter(),
new DefaultPluginConfigurationExpander(),
new ProfileActivationFilePathInterpolator(
new DefaultPathTranslator(), new DefaultRootLocator(), new DefaultInterpolator()),
new DefaultModelVersionParser(getVersionScheme()),
List.of(),
new DefaultModelCacheFactory(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
*/
package org.apache.maven.api.services.model;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.model.Model;
import org.apache.maven.api.model.Profile;

/**
* Describes the environmental context used to determine the activation status of profiles.
Expand Down Expand Up @@ -68,6 +70,20 @@ public interface ProfileActivationContext {
@Nonnull
Map<String, String> getUserProperties();

/**
* Gets current calculated project properties
*
* @return The project properties, never {@code null}.
*/
Map<String, String> getProjectProperties();

/**
* Inject properties from newly activated profiles in order to trigger the cascading mechanism.
*
* @param activatedProfiles The collection of profiles that have been activated that may trigger the cascading effect.
*/
void addProfileProperties(Collection<Profile> activatedProfiles);

/**
* Gets the model which is being activated.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ public interface ProfileSelector {
* @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}.
* @param cascade Indicates whether profile activation should cascade, i.e. properties from an activated profile may
* trigger the activation of other profiles.
* @return The profiles that have been activated, never {@code null}.
*/
List<Profile> getActiveProfiles(
Collection<Profile> profiles, ProfileActivationContext context, ModelProblemCollector problems);
Collection<Profile> profiles,
ProfileActivationContext context,
ModelProblemCollector problems,
boolean cascade);
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public static org.apache.maven.api.model.Profile convertFromSettingsProfile(Prof
}

org.apache.maven.api.model.Profile value = profile.build();
value.setSource("settings.xml");
value.setSource(org.apache.maven.api.model.Profile.SOURCE_SETTINGS);
return value;
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
*/
package org.apache.maven.internal.impl.model;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;

import org.apache.maven.api.model.Model;
import org.apache.maven.api.model.Profile;
import org.apache.maven.api.services.model.ProfileActivationContext;

/**
Expand All @@ -41,6 +44,8 @@ public class DefaultProfileActivationContext implements ProfileActivationContext

private Map<String, String> userProperties = Collections.emptyMap();

private Map<String, String> projectProperties = Collections.emptyMap();

private Model model;

@Override
Expand Down Expand Up @@ -142,10 +147,23 @@ public Model getModel() {

public DefaultProfileActivationContext setModel(Model model) {
this.model = model;

this.projectProperties = unmodifiable(model.getProperties());
return this;
}

@Override
public Map<String, String> getProjectProperties() {
return projectProperties;
}

public void addProfileProperties(Collection<Profile> profiles) {
Map<String, String> props = new HashMap<>(this.projectProperties);
for (var profile : profiles) {
props.putAll(profile.getProperties());
}
this.projectProperties = unmodifiable(props);
}

private static List<String> unmodifiable(List<String> list) {
return list != null ? Collections.unmodifiableList(list) : Collections.emptyList();
}
Expand Down
Loading

0 comments on commit 3d21d5f

Please sign in to comment.