Skip to content

Commit

Permalink
[MNG-8006] Switch property contributors to use a lazy lookup (#1419)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Feb 20, 2024
1 parent ff5fa9e commit a31c145
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Map;
import java.util.Properties;

import org.apache.maven.api.services.Lookup;
import org.apache.maven.api.spi.PropertyContributor;
import org.apache.maven.execution.MavenExecutionRequest;

Expand All @@ -37,22 +38,25 @@
@Named
@Singleton
class PropertyContributorExtender implements MavenExecutionRequestExtender {
private final Map<String, PropertyContributor> effectivePropertyContributors;
private final Lookup lookup;

@Inject
PropertyContributorExtender(Map<String, PropertyContributor> effectivePropertyContributors) {
this.effectivePropertyContributors = effectivePropertyContributors;
PropertyContributorExtender(Lookup lookup) {
this.lookup = lookup;
}

@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public void extend(MavenExecutionRequest mavenExecutionRequest) {
HashMap<String, String> userPropertiesMap = new HashMap<>((Map) mavenExecutionRequest.getUserProperties());
for (PropertyContributor contributor : effectivePropertyContributors.values()) {
contributor.contribute(userPropertiesMap);
Map<String, PropertyContributor> effectivePropertyContributors = lookup.lookupMap(PropertyContributor.class);
if (!effectivePropertyContributors.isEmpty()) {
HashMap<String, String> userPropertiesMap = new HashMap<>((Map) mavenExecutionRequest.getUserProperties());
for (PropertyContributor contributor : effectivePropertyContributors.values()) {
contributor.contribute(userPropertiesMap);
}
Properties newProperties = new Properties();
newProperties.putAll(userPropertiesMap);
mavenExecutionRequest.setUserProperties(newProperties);
}
Properties newProperties = new Properties();
newProperties.putAll(userPropertiesMap);
mavenExecutionRequest.setUserProperties(newProperties);
}
}

0 comments on commit a31c145

Please sign in to comment.