View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.internal.aether;
20  
21  import java.nio.file.Path;
22  import java.nio.file.Paths;
23  import java.util.ArrayList;
24  import java.util.Arrays;
25  import java.util.HashMap;
26  import java.util.HashSet;
27  import java.util.LinkedHashMap;
28  import java.util.List;
29  import java.util.Map;
30  import java.util.function.Predicate;
31  import java.util.stream.Collectors;
32  
33  import org.apache.maven.api.Constants;
34  import org.apache.maven.api.di.Inject;
35  import org.apache.maven.api.di.Named;
36  import org.apache.maven.api.di.Singleton;
37  import org.apache.maven.api.services.TypeRegistry;
38  import org.apache.maven.api.xml.XmlNode;
39  import org.apache.maven.eventspy.internal.EventSpyDispatcher;
40  import org.apache.maven.execution.MavenExecutionRequest;
41  import org.apache.maven.internal.impl.resolver.MavenSessionBuilderSupplier;
42  import org.apache.maven.internal.xml.XmlNodeImpl;
43  import org.apache.maven.internal.xml.XmlPlexusConfiguration;
44  import org.apache.maven.model.ModelBase;
45  import org.apache.maven.resolver.RepositorySystemSessionFactory;
46  import org.apache.maven.rtinfo.RuntimeInformation;
47  import org.apache.maven.settings.Mirror;
48  import org.apache.maven.settings.Proxy;
49  import org.apache.maven.settings.Server;
50  import org.codehaus.plexus.configuration.PlexusConfiguration;
51  import org.eclipse.aether.ConfigurationProperties;
52  import org.eclipse.aether.RepositoryListener;
53  import org.eclipse.aether.RepositorySystem;
54  import org.eclipse.aether.RepositorySystemSession;
55  import org.eclipse.aether.RepositorySystemSession.SessionBuilder;
56  import org.eclipse.aether.artifact.Artifact;
57  import org.eclipse.aether.artifact.DefaultArtifact;
58  import org.eclipse.aether.collection.VersionFilter;
59  import org.eclipse.aether.repository.RepositoryPolicy;
60  import org.eclipse.aether.resolution.ResolutionErrorPolicy;
61  import org.eclipse.aether.util.graph.version.ChainedVersionFilter;
62  import org.eclipse.aether.util.graph.version.ContextualSnapshotVersionFilter;
63  import org.eclipse.aether.util.graph.version.HighestVersionFilter;
64  import org.eclipse.aether.util.graph.version.LowestVersionFilter;
65  import org.eclipse.aether.util.graph.version.PredicateVersionFilter;
66  import org.eclipse.aether.util.listener.ChainedRepositoryListener;
67  import org.eclipse.aether.util.repository.AuthenticationBuilder;
68  import org.eclipse.aether.util.repository.ChainedLocalRepositoryManager;
69  import org.eclipse.aether.util.repository.DefaultAuthenticationSelector;
70  import org.eclipse.aether.util.repository.DefaultMirrorSelector;
71  import org.eclipse.aether.util.repository.DefaultProxySelector;
72  import org.eclipse.aether.util.repository.SimpleArtifactDescriptorPolicy;
73  import org.eclipse.aether.util.repository.SimpleResolutionErrorPolicy;
74  import org.eclipse.aether.version.InvalidVersionSpecificationException;
75  import org.eclipse.aether.version.Version;
76  import org.eclipse.aether.version.VersionRange;
77  import org.eclipse.aether.version.VersionScheme;
78  import org.slf4j.Logger;
79  import org.slf4j.LoggerFactory;
80  
81  import static java.util.Objects.requireNonNull;
82  
83  /**
84   * @since 3.3.0
85   */
86  @Named
87  @Singleton
88  public class DefaultRepositorySystemSessionFactory implements RepositorySystemSessionFactory {
89  
90      public static final String MAVEN_RESOLVER_TRANSPORT_DEFAULT = "default";
91  
92      public static final String MAVEN_RESOLVER_TRANSPORT_WAGON = "wagon";
93  
94      public static final String MAVEN_RESOLVER_TRANSPORT_APACHE = "apache";
95  
96      public static final String MAVEN_RESOLVER_TRANSPORT_JDK = "jdk";
97  
98      /**
99       * This name for Apache HttpClient transport is deprecated.
100      *
101      * @deprecated Renamed to {@link #MAVEN_RESOLVER_TRANSPORT_APACHE}
102      */
103     @Deprecated
104     private static final String MAVEN_RESOLVER_TRANSPORT_NATIVE = "native";
105 
106     public static final String MAVEN_RESOLVER_TRANSPORT_AUTO = "auto";
107 
108     private static final String WAGON_TRANSPORTER_PRIORITY_KEY = "aether.priority.WagonTransporterFactory";
109 
110     private static final String APACHE_HTTP_TRANSPORTER_PRIORITY_KEY = "aether.priority.ApacheTransporterFactory";
111 
112     private static final String JDK_HTTP_TRANSPORTER_PRIORITY_KEY = "aether.priority.JdkTransporterFactory";
113 
114     private static final String FILE_TRANSPORTER_PRIORITY_KEY = "aether.priority.FileTransporterFactory";
115 
116     private static final String RESOLVER_MAX_PRIORITY = String.valueOf(Float.MAX_VALUE);
117 
118     private final Logger logger = LoggerFactory.getLogger(getClass());
119 
120     private final RepositorySystem repoSystem;
121 
122     private final EventSpyDispatcher eventSpyDispatcher;
123 
124     private final RuntimeInformation runtimeInformation;
125 
126     private final TypeRegistry typeRegistry;
127 
128     private final VersionScheme versionScheme;
129 
130     private final Map<String, RepositorySystemSessionExtender> sessionExtenders;
131 
132     @SuppressWarnings("checkstyle:ParameterNumber")
133     @Inject
134     DefaultRepositorySystemSessionFactory(
135             RepositorySystem repoSystem,
136             EventSpyDispatcher eventSpyDispatcher,
137             RuntimeInformation runtimeInformation,
138             TypeRegistry typeRegistry,
139             VersionScheme versionScheme,
140             Map<String, RepositorySystemSessionExtender> sessionExtenders) {
141         this.repoSystem = repoSystem;
142         this.eventSpyDispatcher = eventSpyDispatcher;
143         this.runtimeInformation = runtimeInformation;
144         this.typeRegistry = typeRegistry;
145         this.versionScheme = versionScheme;
146         this.sessionExtenders = sessionExtenders;
147     }
148 
149     @Deprecated
150     public RepositorySystemSession newRepositorySession(MavenExecutionRequest request) {
151         return newRepositorySessionBuilder(request).build();
152     }
153 
154     @SuppressWarnings({"checkstyle:methodLength"})
155     public SessionBuilder newRepositorySessionBuilder(MavenExecutionRequest request) {
156         requireNonNull(request, "request");
157 
158         MavenSessionBuilderSupplier supplier = new MavenSessionBuilderSupplier(repoSystem);
159         SessionBuilder sessionBuilder = supplier.get();
160         sessionBuilder.setArtifactTypeRegistry(new TypeRegistryAdapter(typeRegistry)); // dynamic
161         sessionBuilder.setCache(request.getRepositoryCache());
162 
163         // this map is read ONLY to get config from (profiles + env + system + user)
164         Map<String, String> mergedProps = createMergedProperties(request);
165 
166         // configProps map is kept "pristine", is written ONLY, the mandatory resolver config
167         Map<String, Object> configProps = new LinkedHashMap<>();
168         configProps.put(ConfigurationProperties.USER_AGENT, getUserAgent());
169         configProps.put(ConfigurationProperties.INTERACTIVE, request.isInteractiveMode());
170         configProps.put("maven.startTime", request.getStartTime());
171         configProps.put(Constants.MAVEN_START_INSTANT, request.getStartInstant());
172 
173         sessionBuilder.setOffline(request.isOffline());
174         sessionBuilder.setChecksumPolicy(request.getGlobalChecksumPolicy());
175         sessionBuilder.setUpdatePolicy(
176                 request.isNoSnapshotUpdates()
177                         ? RepositoryPolicy.UPDATE_POLICY_NEVER
178                         : request.isUpdateSnapshots() ? RepositoryPolicy.UPDATE_POLICY_ALWAYS : null);
179 
180         int errorPolicy = 0;
181         errorPolicy |= request.isCacheNotFound()
182                 ? ResolutionErrorPolicy.CACHE_NOT_FOUND
183                 : ResolutionErrorPolicy.CACHE_DISABLED;
184         errorPolicy |= request.isCacheTransferError()
185                 ? ResolutionErrorPolicy.CACHE_TRANSFER_ERROR
186                 : ResolutionErrorPolicy.CACHE_DISABLED;
187         sessionBuilder.setResolutionErrorPolicy(
188                 new SimpleResolutionErrorPolicy(errorPolicy, errorPolicy | ResolutionErrorPolicy.CACHE_NOT_FOUND));
189 
190         sessionBuilder.setArtifactDescriptorPolicy(new SimpleArtifactDescriptorPolicy(
191                 request.isIgnoreMissingArtifactDescriptor(), request.isIgnoreInvalidArtifactDescriptor()));
192 
193         VersionFilter versionFilter = buildVersionFilter(mergedProps.get(Constants.MAVEN_VERSION_FILTER));
194         if (versionFilter != null) {
195             sessionBuilder.setVersionFilter(versionFilter);
196         }
197 
198         DefaultMirrorSelector mirrorSelector = new DefaultMirrorSelector();
199         for (Mirror mirror : request.getMirrors()) {
200             mirrorSelector.add(
201                     mirror.getId(),
202                     mirror.getUrl(),
203                     mirror.getLayout(),
204                     false,
205                     mirror.isBlocked(),
206                     mirror.getMirrorOf(),
207                     mirror.getMirrorOfLayouts());
208         }
209         sessionBuilder.setMirrorSelector(mirrorSelector);
210 
211         DefaultProxySelector proxySelector = new DefaultProxySelector();
212         for (Proxy proxy : request.getProxies()) {
213             AuthenticationBuilder authBuilder = new AuthenticationBuilder();
214             authBuilder.addUsername(proxy.getUsername()).addPassword(proxy.getPassword());
215             proxySelector.add(
216                     new org.eclipse.aether.repository.Proxy(
217                             proxy.getProtocol(), proxy.getHost(), proxy.getPort(), authBuilder.build()),
218                     proxy.getNonProxyHosts());
219         }
220         sessionBuilder.setProxySelector(proxySelector);
221 
222         // Note: we do NOT use WagonTransportConfigurationKeys here as Maven Core does NOT depend on Wagon Transport
223         // and this is okay and "good thing".
224         DefaultAuthenticationSelector authSelector = new DefaultAuthenticationSelector();
225         for (Server server : request.getServers()) {
226             AuthenticationBuilder authBuilder = new AuthenticationBuilder();
227             authBuilder.addUsername(server.getUsername()).addPassword(server.getPassword());
228             authBuilder.addPrivateKey(server.getPrivateKey(), server.getPassphrase());
229             authSelector.add(server.getId(), authBuilder.build());
230 
231             if (server.getConfiguration() != null) {
232                 XmlNode dom = server.getDelegate().getConfiguration();
233                 List<XmlNode> children = dom.getChildren().stream()
234                         .filter(c -> !"wagonProvider".equals(c.getName()))
235                         .collect(Collectors.toList());
236                 dom = new XmlNodeImpl(dom.getName(), null, null, children, null);
237                 PlexusConfiguration config = XmlPlexusConfiguration.toPlexusConfiguration(dom);
238                 configProps.put("aether.transport.wagon.config." + server.getId(), config);
239 
240                 // Translate to proper resolver configuration properties as well (as Plexus XML above is Wagon specific
241                 // only) but support only configuration/httpConfiguration/all, see
242                 // https://maven.apache.org/guides/mini/guide-http-settings.html
243                 Map<String, String> headers = null;
244                 Integer connectTimeout = null;
245                 Integer requestTimeout = null;
246 
247                 PlexusConfiguration httpHeaders = config.getChild("httpHeaders", false);
248                 if (httpHeaders != null) {
249                     PlexusConfiguration[] properties = httpHeaders.getChildren("property");
250                     if (properties != null && properties.length > 0) {
251                         headers = new HashMap<>();
252                         for (PlexusConfiguration property : properties) {
253                             headers.put(
254                                     property.getChild("name").getValue(),
255                                     property.getChild("value").getValue());
256                         }
257                     }
258                 }
259 
260                 PlexusConfiguration connectTimeoutXml = config.getChild("connectTimeout", false);
261                 if (connectTimeoutXml != null) {
262                     connectTimeout = Integer.parseInt(connectTimeoutXml.getValue());
263                 } else {
264                     // fallback configuration name
265                     PlexusConfiguration httpConfiguration = config.getChild("httpConfiguration", false);
266                     if (httpConfiguration != null) {
267                         PlexusConfiguration httpConfigurationAll = httpConfiguration.getChild("all", false);
268                         if (httpConfigurationAll != null) {
269                             connectTimeoutXml = httpConfigurationAll.getChild("connectionTimeout", false);
270                             if (connectTimeoutXml != null) {
271                                 connectTimeout = Integer.parseInt(connectTimeoutXml.getValue());
272                                 logger.warn("Settings for server {} uses legacy format", server.getId());
273                             }
274                         }
275                     }
276                 }
277 
278                 PlexusConfiguration requestTimeoutXml = config.getChild("requestTimeout", false);
279                 if (requestTimeoutXml != null) {
280                     requestTimeout = Integer.parseInt(requestTimeoutXml.getValue());
281                 } else {
282                     // fallback configuration name
283                     PlexusConfiguration httpConfiguration = config.getChild("httpConfiguration", false);
284                     if (httpConfiguration != null) {
285                         PlexusConfiguration httpConfigurationAll = httpConfiguration.getChild("all", false);
286                         if (httpConfigurationAll != null) {
287                             requestTimeoutXml = httpConfigurationAll.getChild("readTimeout", false);
288                             if (requestTimeoutXml != null) {
289                                 requestTimeout = Integer.parseInt(requestTimeoutXml.getValue());
290                                 logger.warn("Settings for server {} uses legacy format", server.getId());
291                             }
292                         }
293                     }
294                 }
295 
296                 // org.eclipse.aether.ConfigurationProperties.HTTP_HEADERS => Map<String, String>
297                 if (headers != null) {
298                     configProps.put(ConfigurationProperties.HTTP_HEADERS + "." + server.getId(), headers);
299                 }
300                 // org.eclipse.aether.ConfigurationProperties.CONNECT_TIMEOUT => int
301                 if (connectTimeout != null) {
302                     configProps.put(ConfigurationProperties.CONNECT_TIMEOUT + "." + server.getId(), connectTimeout);
303                 }
304                 // org.eclipse.aether.ConfigurationProperties.REQUEST_TIMEOUT => int
305                 if (requestTimeout != null) {
306                     configProps.put(ConfigurationProperties.REQUEST_TIMEOUT + "." + server.getId(), requestTimeout);
307                 }
308             }
309 
310             configProps.put("aether.transport.wagon.perms.fileMode." + server.getId(), server.getFilePermissions());
311             configProps.put("aether.transport.wagon.perms.dirMode." + server.getId(), server.getDirectoryPermissions());
312         }
313         sessionBuilder.setAuthenticationSelector(authSelector);
314 
315         Object transport =
316                 mergedProps.getOrDefault(Constants.MAVEN_RESOLVER_TRANSPORT, MAVEN_RESOLVER_TRANSPORT_DEFAULT);
317         if (MAVEN_RESOLVER_TRANSPORT_DEFAULT.equals(transport)) {
318             // The "default" mode (user did not set anything) from now on defaults to AUTO
319         } else if (MAVEN_RESOLVER_TRANSPORT_JDK.equals(transport)) {
320             // Make sure (whatever extra priority is set) that resolver file/jdk is selected
321             configProps.put(FILE_TRANSPORTER_PRIORITY_KEY, RESOLVER_MAX_PRIORITY);
322             configProps.put(JDK_HTTP_TRANSPORTER_PRIORITY_KEY, RESOLVER_MAX_PRIORITY);
323         } else if (MAVEN_RESOLVER_TRANSPORT_APACHE.equals(transport)
324                 || MAVEN_RESOLVER_TRANSPORT_NATIVE.equals(transport)) {
325             if (MAVEN_RESOLVER_TRANSPORT_NATIVE.equals(transport)) {
326                 logger.warn(
327                         "Transport name '{}' is DEPRECATED/RENAMED, use '{}' instead",
328                         MAVEN_RESOLVER_TRANSPORT_NATIVE,
329                         MAVEN_RESOLVER_TRANSPORT_APACHE);
330             }
331             // Make sure (whatever extra priority is set) that resolver file/apache is selected
332             configProps.put(FILE_TRANSPORTER_PRIORITY_KEY, RESOLVER_MAX_PRIORITY);
333             configProps.put(APACHE_HTTP_TRANSPORTER_PRIORITY_KEY, RESOLVER_MAX_PRIORITY);
334         } else if (MAVEN_RESOLVER_TRANSPORT_WAGON.equals(transport)) {
335             // Make sure (whatever extra priority is set) that wagon is selected
336             configProps.put(WAGON_TRANSPORTER_PRIORITY_KEY, RESOLVER_MAX_PRIORITY);
337         } else if (!MAVEN_RESOLVER_TRANSPORT_AUTO.equals(transport)) {
338             throw new IllegalArgumentException("Unknown resolver transport '" + transport
339                     + "'. Supported transports are: " + MAVEN_RESOLVER_TRANSPORT_WAGON + ", "
340                     + MAVEN_RESOLVER_TRANSPORT_APACHE + ", " + MAVEN_RESOLVER_TRANSPORT_JDK + ", "
341                     + MAVEN_RESOLVER_TRANSPORT_AUTO);
342         }
343 
344         sessionBuilder.setIgnoreArtifactDescriptorRepositories(request.isIgnoreTransitiveRepositories());
345 
346         sessionBuilder.setTransferListener(request.getTransferListener());
347 
348         RepositoryListener repositoryListener = eventSpyDispatcher.chainListener(new LoggingRepositoryListener(logger));
349 
350         boolean recordReverseTree = Boolean.parseBoolean(
351                 mergedProps.getOrDefault(Constants.MAVEN_REPO_LOCAL_RECORD_REVERSE_TREE, Boolean.FALSE.toString()));
352         if (recordReverseTree) {
353             repositoryListener = new ChainedRepositoryListener(repositoryListener, new ReverseTreeRepositoryListener());
354         }
355         sessionBuilder.setRepositoryListener(repositoryListener);
356 
357         // may be overridden
358         String resolverDependencyManagerTransitivity = mergedProps.getOrDefault(
359                 Constants.MAVEN_RESOLVER_DEPENDENCY_MANAGER_TRANSITIVITY, Boolean.TRUE.toString());
360         sessionBuilder.setDependencyManager(
361                 supplier.getDependencyManager(Boolean.parseBoolean(resolverDependencyManagerTransitivity)));
362 
363         ArrayList<Path> paths = new ArrayList<>();
364         String localRepoHead = mergedProps.get(Constants.MAVEN_REPO_LOCAL_HEAD);
365         if (localRepoHead != null) {
366             Arrays.stream(localRepoHead.split(","))
367                     .filter(p -> p != null && !p.trim().isEmpty())
368                     .map(this::resolve)
369                     .forEach(paths::add);
370         }
371         paths.add(Paths.get(request.getLocalRepository().getBasedir()));
372         String localRepoTail = mergedProps.get(Constants.MAVEN_REPO_LOCAL_TAIL);
373         if (localRepoTail != null) {
374             Arrays.stream(localRepoTail.split(","))
375                     .filter(p -> p != null && !p.trim().isEmpty())
376                     .map(this::resolve)
377                     .forEach(paths::add);
378         }
379         sessionBuilder.withLocalRepositoryBaseDirectories(paths);
380         // Pass over property supported by Maven 3.9.x
381         if (mergedProps.containsKey(Constants.MAVEN_REPO_LOCAL_TAIL_IGNORE_AVAILABILITY)) {
382             configProps.put(
383                     ChainedLocalRepositoryManager.CONFIG_PROP_IGNORE_TAIL_AVAILABILITY,
384                     mergedProps.get(Constants.MAVEN_REPO_LOCAL_TAIL_IGNORE_AVAILABILITY));
385         }
386 
387         for (RepositorySystemSessionExtender extender : sessionExtenders.values()) {
388             extender.extend(request, configProps, mirrorSelector, proxySelector, authSelector);
389         }
390 
391         // at this point we have "config" with pure MANDATORY resolver config, so resolver final config properties are
392         // mergedProperties + configProperties
393         HashMap<String, Object> finalConfigProperties = new HashMap<>();
394         finalConfigProperties.putAll(mergedProps);
395         finalConfigProperties.putAll(configProps);
396 
397         sessionBuilder.setUserProperties(request.getUserProperties());
398         sessionBuilder.setSystemProperties(request.getSystemProperties());
399         sessionBuilder.setConfigProperties(finalConfigProperties);
400 
401         return sessionBuilder;
402     }
403 
404     private Path resolve(String string) {
405         if (string.startsWith("~/") || string.startsWith("~\\")) {
406             // resolve based on $HOME
407             return Paths.get(System.getProperty("user.home"))
408                     .resolve(string.substring(2))
409                     .normalize()
410                     .toAbsolutePath();
411         } else {
412             // resolve based on $CWD
413             return Paths.get(string).normalize().toAbsolutePath();
414         }
415     }
416 
417     private VersionFilter buildVersionFilter(String filterExpression) {
418         ArrayList<VersionFilter> filters = new ArrayList<>();
419         if (filterExpression != null) {
420             List<String> expressions = Arrays.stream(filterExpression.split(";"))
421                     .filter(s -> s != null && !s.trim().isEmpty())
422                     .toList();
423             for (String expression : expressions) {
424                 if ("h".equals(expression)) {
425                     filters.add(new HighestVersionFilter());
426                 } else if (expression.startsWith("h(") && expression.endsWith(")")) {
427                     int num = Integer.parseInt(expression.substring(2, expression.length() - 1));
428                     filters.add(new HighestVersionFilter(num));
429                 } else if ("l".equals(expression)) {
430                     filters.add(new LowestVersionFilter());
431                 } else if (expression.startsWith("l(") && expression.endsWith(")")) {
432                     int num = Integer.parseInt(expression.substring(2, expression.length() - 1));
433                     filters.add(new LowestVersionFilter(num));
434                 } else if ("s".equals(expression)) {
435                     filters.add(new ContextualSnapshotVersionFilter());
436                 } else if (expression.startsWith("e(") && expression.endsWith(")")) {
437                     Artifact artifact = new DefaultArtifact(expression.substring(2, expression.length() - 1));
438                     VersionRange versionRange =
439                             artifact.getVersion().contains(",") ? parseVersionRange(artifact.getVersion()) : null;
440                     Predicate<Artifact> predicate = a -> {
441                         if (artifact.getGroupId().equals(a.getGroupId())
442                                 && artifact.getArtifactId().equals(a.getArtifactId())) {
443                             if (versionRange != null) {
444                                 Version v = parseVersion(a.getVersion());
445                                 return !versionRange.containsVersion(v);
446                             } else {
447                                 return !artifact.getVersion().equals(a.getVersion());
448                             }
449                         }
450                         return true;
451                     };
452                     filters.add(new PredicateVersionFilter(predicate));
453                 } else {
454                     throw new IllegalArgumentException("Unsupported filter expression: " + expression);
455                 }
456             }
457         }
458         if (filters.isEmpty()) {
459             return null;
460         } else if (filters.size() == 1) {
461             return filters.get(0);
462         } else {
463             return ChainedVersionFilter.newInstance(filters);
464         }
465     }
466 
467     private Version parseVersion(String spec) {
468         try {
469             return versionScheme.parseVersion(spec);
470         } catch (InvalidVersionSpecificationException e) {
471             throw new RuntimeException(e);
472         }
473     }
474 
475     private VersionRange parseVersionRange(String spec) {
476         try {
477             return versionScheme.parseVersionRange(spec);
478         } catch (InvalidVersionSpecificationException e) {
479             throw new RuntimeException(e);
480         }
481     }
482 
483     @SuppressWarnings({"unchecked", "rawtypes"})
484     private Map<String, String> createMergedProperties(MavenExecutionRequest request) {
485         // this throwaway map is really ONLY to get config from (profiles + env + system + user)
486         Map<String, String> mergedProps = new HashMap<>();
487         mergedProps.putAll(getPropertiesFromRequestedProfiles(request));
488         mergedProps.putAll(new HashMap<String, String>((Map) request.getSystemProperties()));
489         mergedProps.putAll(new HashMap<String, String>((Map) request.getUserProperties()));
490         return mergedProps;
491     }
492 
493     private Map<String, String> getPropertiesFromRequestedProfiles(MavenExecutionRequest request) {
494         HashSet<String> activeProfileId =
495                 new HashSet<>(request.getProfileActivation().getRequiredActiveProfileIds());
496         activeProfileId.addAll(request.getProfileActivation().getOptionalActiveProfileIds());
497 
498         return request.getProfiles().stream()
499                 .filter(profile -> activeProfileId.contains(profile.getId()))
500                 .map(ModelBase::getProperties)
501                 .flatMap(properties -> properties.entrySet().stream())
502                 .filter(e -> e.getValue() != null)
503                 .collect(Collectors.toMap(
504                         e -> String.valueOf(e.getKey()), e -> String.valueOf(e.getValue()), (k1, k2) -> k2));
505     }
506 
507     private String getUserAgent() {
508         String version = runtimeInformation.getMavenVersion();
509         version = version.isEmpty() ? version : "/" + version;
510         return "Apache-Maven" + version + " (Java " + System.getProperty("java.version") + "; "
511                 + System.getProperty("os.name") + " " + System.getProperty("os.version") + ")";
512     }
513 }