Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNG-8222] Extend PropertyContributor #1679

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.maven.api.spi;

import java.nio.file.Path;
import java.util.Map;

import org.apache.maven.api.annotations.Consumer;
Expand All @@ -33,9 +34,12 @@
@Consumer
public interface PropertyContributor extends SpiService {
/**
* Invoked just before session is created with a mutable map that carries collected user properties so far.
* Invoked just before session is created.
*
* @param userProperties The mutable user properties, never {@code null}.
* @param systemProperties Immutable map of system properties, never {@code null}.
* @param userProperties Immutable map of user properties, never {@code null}.
* @param topDirectory The path of top directory, never {@code null}.
*/
void contribute(Map<String, String> userProperties);
Map<String, String> contribute(
Map<String, String> systemProperties, Map<String, String> userProperties, Path topDirectory);
gnodet marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import javax.inject.Named;
import javax.inject.Singleton;

import java.util.HashMap;
import java.nio.file.Path;
import java.util.Map;
import java.util.Properties;

Expand Down Expand Up @@ -50,13 +50,26 @@ class PropertyContributorExtender implements MavenExecutionRequestExtender {
public void extend(MavenExecutionRequest mavenExecutionRequest) {
Map<String, PropertyContributor> effectivePropertyContributors = lookup.lookupMap(PropertyContributor.class);
if (!effectivePropertyContributors.isEmpty()) {
HashMap<String, String> userPropertiesMap = new HashMap<>((Map) mavenExecutionRequest.getUserProperties());
final Map<String, String> systemPropertiesMap =
Map.copyOf((Map) mavenExecutionRequest.getSystemProperties());
final Map<String, String> userPropertiesMap = Map.copyOf((Map) mavenExecutionRequest.getUserProperties());
final Path topDirectory = mavenExecutionRequest.getTopDirectory();
final Properties newProperties = new Properties();

for (PropertyContributor contributor : effectivePropertyContributors.values()) {
contributor.contribute(userPropertiesMap);
Map<String, String> contribution =
contributor.contribute(systemPropertiesMap, userPropertiesMap, topDirectory);
if (contribution != null && !contribution.isEmpty()) {
newProperties.putAll(contribution);
}
}

if (!newProperties.isEmpty()) {
Properties newUserProperties = new Properties();
newUserProperties.putAll(userPropertiesMap);
newUserProperties.putAll(newProperties);
mavenExecutionRequest.setUserProperties(newUserProperties);
}
Properties newProperties = new Properties();
newProperties.putAll(userPropertiesMap);
mavenExecutionRequest.setUserProperties(newProperties);
}
}
}
Loading