This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/master by this push:
     new a31c145ae9 [MNG-8006] Switch property contributors to use a lazy 
lookup (#1419)
a31c145ae9 is described below

commit a31c145ae9383cf9f252cf83f08ae71b7dbb8532
Author: Guillaume Nodet <gno...@gmail.com>
AuthorDate: Tue Feb 20 16:38:09 2024 +0100

    [MNG-8006] Switch property contributors to use a lazy lookup (#1419)
---
 .../aether/PropertyContributorExtender.java        | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git 
a/maven-core/src/main/java/org/apache/maven/internal/aether/PropertyContributorExtender.java
 
b/maven-core/src/main/java/org/apache/maven/internal/aether/PropertyContributorExtender.java
index 4d832bb2f5..1b967a12e0 100644
--- 
a/maven-core/src/main/java/org/apache/maven/internal/aether/PropertyContributorExtender.java
+++ 
b/maven-core/src/main/java/org/apache/maven/internal/aether/PropertyContributorExtender.java
@@ -26,6 +26,7 @@ import java.util.HashMap;
 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;
 
@@ -37,22 +38,25 @@ import org.apache.maven.execution.MavenExecutionRequest;
 @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);
     }
 }

Reply via email to