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

cstamas pushed a commit to branch maven-3.9.x
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/maven-3.9.x by this push:
     new 573a3e1ec [MNG-7614] Translate Plexus XML to proper resolver 
configuration (#895)
573a3e1ec is described below

commit 573a3e1ec51227dcde8d8f5987e701ca49b96018
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Fri Dec 2 16:12:01 2022 +0100

    [MNG-7614] Translate Plexus XML to proper resolver configuration (#895)
    
    Now that Maven 3.9.x contains other transports than Wagon, the Plexus XML 
is not just to be "stuffed", but translation should happen to proper resolver 
configuration to make them available to all transports.
    
    ---
    
    https://issues.apache.org/jira/browse/MNG-7614
---
 .../DefaultRepositorySystemSessionFactory.java     | 71 ++++++++++++++++++++++
 1 file changed, 71 insertions(+)

diff --git 
a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java
 
b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java
index 93e062a0b..bc0b4a4a6 100644
--- 
a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java
+++ 
b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java
@@ -18,6 +18,7 @@
  */
 package org.apache.maven.internal.aether;
 
+import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -39,6 +40,7 @@ import org.apache.maven.settings.building.SettingsProblem;
 import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest;
 import org.apache.maven.settings.crypto.SettingsDecrypter;
 import org.apache.maven.settings.crypto.SettingsDecryptionResult;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
 import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
 import org.codehaus.plexus.logging.Logger;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
@@ -209,6 +211,75 @@ public class DefaultRepositorySystemSessionFactory {
 
                 XmlPlexusConfiguration config = new 
XmlPlexusConfiguration(dom);
                 configProps.put("aether.connector.wagon.config." + 
server.getId(), config);
+
+                // Translate to proper resolver configuration properties as 
well (as Plexus XML above is Wagon specific
+                // only), but support only 
configuration/httpConfiguration/all, see
+                // 
https://maven.apache.org/guides/mini/guide-http-settings.html
+                Map<String, String> headers = null;
+                Integer connectTimeout = null;
+                Integer requestTimeout = null;
+
+                PlexusConfiguration httpHeaders = 
config.getChild("httpHeaders", false);
+                if (httpHeaders != null) {
+                    PlexusConfiguration[] properties = 
httpHeaders.getChildren("property");
+                    if (properties != null && properties.length > 0) {
+                        headers = new HashMap<>();
+                        for (PlexusConfiguration property : properties) {
+                            headers.put(
+                                    property.getChild("name").getValue(),
+                                    property.getChild("value").getValue());
+                        }
+                    }
+                }
+
+                PlexusConfiguration connectTimeoutXml = 
config.getChild("connectTimeout", false);
+                if (connectTimeoutXml != null) {
+                    connectTimeout = 
Integer.parseInt(connectTimeoutXml.getValue());
+                } else {
+                    // fallback configuration name
+                    PlexusConfiguration httpConfiguration = 
config.getChild("httpConfiguration", false);
+                    if (httpConfiguration != null) {
+                        PlexusConfiguration httpConfigurationAll = 
httpConfiguration.getChild("all", false);
+                        if (httpConfigurationAll != null) {
+                            connectTimeoutXml = 
httpConfigurationAll.getChild("connectionTimeout", false);
+                            if (connectTimeoutXml != null) {
+                                connectTimeout = 
Integer.parseInt(connectTimeoutXml.getValue());
+                                logger.warn("Settings for server " + 
server.getId() + " uses legacy format");
+                            }
+                        }
+                    }
+                }
+
+                PlexusConfiguration requestTimeoutXml = 
config.getChild("requestTimeout", false);
+                if (requestTimeoutXml != null) {
+                    requestTimeout = 
Integer.parseInt(requestTimeoutXml.getValue());
+                } else {
+                    // fallback configuration name
+                    PlexusConfiguration httpConfiguration = 
config.getChild("httpConfiguration", false);
+                    if (httpConfiguration != null) {
+                        PlexusConfiguration httpConfigurationAll = 
httpConfiguration.getChild("all", false);
+                        if (httpConfigurationAll != null) {
+                            requestTimeoutXml = 
httpConfigurationAll.getChild("readTimeout", false);
+                            if (requestTimeoutXml != null) {
+                                requestTimeout = 
Integer.parseInt(requestTimeoutXml.getValue());
+                                logger.warn("Settings for server " + 
server.getId() + " uses legacy format");
+                            }
+                        }
+                    }
+                }
+
+                // org.eclipse.aether.ConfigurationProperties.HTTP_HEADERS => 
Map<String, String>
+                if (headers != null) {
+                    configProps.put(ConfigurationProperties.HTTP_HEADERS + "." 
+ server.getId(), headers);
+                }
+                // org.eclipse.aether.ConfigurationProperties.CONNECT_TIMEOUT 
=> int
+                if (connectTimeout != null) {
+                    configProps.put(ConfigurationProperties.CONNECT_TIMEOUT + 
"." + server.getId(), connectTimeout);
+                }
+                // org.eclipse.aether.ConfigurationProperties.REQUEST_TIMEOUT 
=> int
+                if (requestTimeout != null) {
+                    configProps.put(ConfigurationProperties.REQUEST_TIMEOUT + 
"." + server.getId(), requestTimeout);
+                }
             }
 
             configProps.put("aether.connector.perms.fileMode." + 
server.getId(), server.getFilePermissions());

Reply via email to