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 
172         sessionBuilder.setOffline(request.isOffline());
173         sessionBuilder.setChecksumPolicy(request.getGlobalChecksumPolicy());
174         sessionBuilder.setUpdatePolicy(
175                 request.isNoSnapshotUpdates()
176                         ? RepositoryPolicy.UPDATE_POLICY_NEVER
177                         : request.isUpdateSnapshots() ? RepositoryPolicy.UPDATE_POLICY_ALWAYS : null);
178 
179         int errorPolicy = 0;
180         errorPolicy |= request.isCacheNotFound()
181                 ? ResolutionErrorPolicy.CACHE_NOT_FOUND
182                 : ResolutionErrorPolicy.CACHE_DISABLED;
183         errorPolicy |= request.isCacheTransferError()
184                 ? ResolutionErrorPolicy.CACHE_TRANSFER_ERROR
185                 : ResolutionErrorPolicy.CACHE_DISABLED;
186         sessionBuilder.setResolutionErrorPolicy(
187                 new SimpleResolutionErrorPolicy(errorPolicy, errorPolicy | ResolutionErrorPolicy.CACHE_NOT_FOUND));
188 
189         sessionBuilder.setArtifactDescriptorPolicy(new SimpleArtifactDescriptorPolicy(
190                 request.isIgnoreMissingArtifactDescriptor(), request.isIgnoreInvalidArtifactDescriptor()));
191 
192         VersionFilter versionFilter = buildVersionFilter(mergedProps.get(Constants.MAVEN_VERSION_FILTER));
193         if (versionFilter != null) {
194             sessionBuilder.setVersionFilter(versionFilter);
195         }
196 
197         DefaultMirrorSelector mirrorSelector = new DefaultMirrorSelector();
198         for (Mirror mirror : request.getMirrors()) {
199             mirrorSelector.add(
200                     mirror.getId(),
201                     mirror.getUrl(),
202                     mirror.getLayout(),
203                     false,
204                     mirror.isBlocked(),
205                     mirror.getMirrorOf(),
206                     mirror.getMirrorOfLayouts());
207         }
208         sessionBuilder.setMirrorSelector(mirrorSelector);
209 
210         DefaultProxySelector proxySelector = new DefaultProxySelector();
211         for (Proxy proxy : request.getProxies()) {
212             AuthenticationBuilder authBuilder = new AuthenticationBuilder();
213             authBuilder.addUsername(proxy.getUsername()).addPassword(proxy.getPassword());
214             proxySelector.add(
215                     new org.eclipse.aether.repository.Proxy(
216                             proxy.getProtocol(), proxy.getHost(), proxy.getPort(), authBuilder.build()),
217                     proxy.getNonProxyHosts());
218         }
219         sessionBuilder.setProxySelector(proxySelector);
220 
221         // Note: we do NOT use WagonTransportConfigurationKeys here as Maven Core does NOT depend on Wagon Transport
222         // and this is okay and "good thing".
223         DefaultAuthenticationSelector authSelector = new DefaultAuthenticationSelector();
224         for (Server server : request.getServers()) {
225             AuthenticationBuilder authBuilder = new AuthenticationBuilder();
226             authBuilder.addUsername(server.getUsername()).addPassword(server.getPassword());
227             authBuilder.addPrivateKey(server.getPrivateKey(), server.getPassphrase());
228             authSelector.add(server.getId(), authBuilder.build());
229 
230             if (server.getConfiguration() != null) {
231                 XmlNode dom = server.getDelegate().getConfiguration();
232                 List<XmlNode> children = dom.getChildren().stream()
233                         .filter(c -> !"wagonProvider".equals(c.getName()))
234                         .collect(Collectors.toList());
235                 dom = new XmlNodeImpl(dom.getName(), null, null, children, null);
236                 PlexusConfiguration config = XmlPlexusConfiguration.toPlexusConfiguration(dom);
237                 configProps.put("aether.transport.wagon.config." + server.getId(), config);
238 
239                 // Translate to proper resolver configuration properties as well (as Plexus XML above is Wagon specific
240                 // only) but support only configuration/httpConfiguration/all, see
241                 // https://maven.apache.org/guides/mini/guide-http-settings.html
242                 Map<String, String> headers = null;
243                 Integer connectTimeout = null;
244                 Integer requestTimeout = null;
245 
246                 PlexusConfiguration httpHeaders = config.getChild("httpHeaders", false);
247                 if (httpHeaders != null) {
248                     PlexusConfiguration[] properties = httpHeaders.getChildren("property");
249                     if (properties != null && properties.length > 0) {
250                         headers = new HashMap<>();
251                         for (PlexusConfiguration property : properties) {
252                             headers.put(
253                                     property.getChild("name").getValue(),
254                                     property.getChild("value").getValue());
255                         }
256                     }
257                 }
258 
259                 PlexusConfiguration connectTimeoutXml = config.getChild("connectTimeout", false);
260                 if (connectTimeoutXml != null) {
261                     connectTimeout = Integer.parseInt(connectTimeoutXml.getValue());
262                 } else {
263                     // fallback configuration name
264                     PlexusConfiguration httpConfiguration = config.getChild("httpConfiguration", false);
265                     if (httpConfiguration != null) {
266                         PlexusConfiguration httpConfigurationAll = httpConfiguration.getChild("all", false);
267                         if (httpConfigurationAll != null) {
268                             connectTimeoutXml = httpConfigurationAll.getChild("connectionTimeout", false);
269                             if (connectTimeoutXml != null) {
270                                 connectTimeout = Integer.parseInt(connectTimeoutXml.getValue());
271                                 logger.warn("Settings for server {} uses legacy format", server.getId());
272                             }
273                         }
274                     }
275                 }
276 
277                 PlexusConfiguration requestTimeoutXml = config.getChild("requestTimeout", false);
278                 if (requestTimeoutXml != null) {
279                     requestTimeout = Integer.parseInt(requestTimeoutXml.getValue());
280                 } else {
281                     // fallback configuration name
282                     PlexusConfiguration httpConfiguration = config.getChild("httpConfiguration", false);
283                     if (httpConfiguration != null) {
284                         PlexusConfiguration httpConfigurationAll = httpConfiguration.getChild("all", false);
285                         if (httpConfigurationAll != null) {
286                             requestTimeoutXml = httpConfigurationAll.getChild("readTimeout", false);
287                             if (requestTimeoutXml != null) {
288                                 requestTimeout = Integer.parseInt(requestTimeoutXml.getValue());
289                                 logger.warn("Settings for server {} uses legacy format", server.getId());
290                             }
291                         }
292                     }
293                 }
294 
295                 // org.eclipse.aether.ConfigurationProperties.HTTP_HEADERS => Map<String, String>
296                 if (headers != null) {
297                     configProps.put(ConfigurationProperties.HTTP_HEADERS + "." + server.getId(), headers);
298                 }
299                 // org.eclipse.aether.ConfigurationProperties.CONNECT_TIMEOUT => int
300                 if (connectTimeout != null) {
301                     configProps.put(ConfigurationProperties.CONNECT_TIMEOUT + "." + server.getId(), connectTimeout);
302                 }
303                 // org.eclipse.aether.ConfigurationProperties.REQUEST_TIMEOUT => int
304                 if (requestTimeout != null) {
305                     configProps.put(ConfigurationProperties.REQUEST_TIMEOUT + "." + server.getId(), requestTimeout);
306                 }
307             }
308 
309             configProps.put("aether.transport.wagon.perms.fileMode." + server.getId(), server.getFilePermissions());
310             configProps.put("aether.transport.wagon.perms.dirMode." + server.getId(), server.getDirectoryPermissions());
311         }
312         sessionBuilder.setAuthenticationSelector(authSelector);
313 
314         Object transport =
315                 mergedProps.getOrDefault(Constants.MAVEN_RESOLVER_TRANSPORT, MAVEN_RESOLVER_TRANSPORT_DEFAULT);
316         if (MAVEN_RESOLVER_TRANSPORT_DEFAULT.equals(transport)) {
317             // The "default" mode (user did not set anything) from now on defaults to AUTO
318         } else if (MAVEN_RESOLVER_TRANSPORT_JDK.equals(transport)) {
319             // Make sure (whatever extra priority is set) that resolver file/jdk is selected
320             configProps.put(FILE_TRANSPORTER_PRIORITY_KEY, RESOLVER_MAX_PRIORITY);
321             configProps.put(JDK_HTTP_TRANSPORTER_PRIORITY_KEY, RESOLVER_MAX_PRIORITY);
322         } else if (MAVEN_RESOLVER_TRANSPORT_APACHE.equals(transport)
323                 || MAVEN_RESOLVER_TRANSPORT_NATIVE.equals(transport)) {
324             if (MAVEN_RESOLVER_TRANSPORT_NATIVE.equals(transport)) {
325                 logger.warn(
326                         "Transport name '{}' is DEPRECATED/RENAMED, use '{}' instead",
327                         MAVEN_RESOLVER_TRANSPORT_NATIVE,
328                         MAVEN_RESOLVER_TRANSPORT_APACHE);
329             }
330             // Make sure (whatever extra priority is set) that resolver file/apache is selected
331             configProps.put(FILE_TRANSPORTER_PRIORITY_KEY, RESOLVER_MAX_PRIORITY);
332             configProps.put(APACHE_HTTP_TRANSPORTER_PRIORITY_KEY, RESOLVER_MAX_PRIORITY);
333         } else if (MAVEN_RESOLVER_TRANSPORT_WAGON.equals(transport)) {
334             // Make sure (whatever extra priority is set) that wagon is selected
335             configProps.put(WAGON_TRANSPORTER_PRIORITY_KEY, RESOLVER_MAX_PRIORITY);
336         } else if (!MAVEN_RESOLVER_TRANSPORT_AUTO.equals(transport)) {
337             throw new IllegalArgumentException("Unknown resolver transport '" + transport
338                     + "'. Supported transports are: " + MAVEN_RESOLVER_TRANSPORT_WAGON + ", "
339                     + MAVEN_RESOLVER_TRANSPORT_APACHE + ", " + MAVEN_RESOLVER_TRANSPORT_JDK + ", "
340                     + MAVEN_RESOLVER_TRANSPORT_AUTO);
341         }
342 
343         sessionBuilder.setIgnoreArtifactDescriptorRepositories(request.isIgnoreTransitiveRepositories());
344 
345         sessionBuilder.setTransferListener(request.getTransferListener());
346 
347         RepositoryListener repositoryListener = eventSpyDispatcher.chainListener(new LoggingRepositoryListener(logger));
348 
349         boolean recordReverseTree = Boolean.parseBoolean(
350                 mergedProps.getOrDefault(Constants.MAVEN_REPO_LOCAL_RECORD_REVERSE_TREE, Boolean.FALSE.toString()));
351         if (recordReverseTree) {
352             repositoryListener = new ChainedRepositoryListener(repositoryListener, new ReverseTreeRepositoryListener());
353         }
354         sessionBuilder.setRepositoryListener(repositoryListener);
355 
356         // may be overridden
357         String resolverDependencyManagerTransitivity = mergedProps.getOrDefault(
358                 Constants.MAVEN_RESOLVER_DEPENDENCY_MANAGER_TRANSITIVITY, Boolean.TRUE.toString());
359         sessionBuilder.setDependencyManager(
360                 supplier.getDependencyManager(Boolean.parseBoolean(resolverDependencyManagerTransitivity)));
361 
362         ArrayList<Path> paths = new ArrayList<>();
363         String localRepoHead = mergedProps.get(Constants.MAVEN_REPO_LOCAL_HEAD);
364         if (localRepoHead != null) {
365             Arrays.stream(localRepoHead.split(","))
366                     .filter(p -> p != null && !p.trim().isEmpty())
367                     .map(this::resolve)
368                     .forEach(paths::add);
369         }
370         paths.add(Paths.get(request.getLocalRepository().getBasedir()));
371         String localRepoTail = mergedProps.get(Constants.MAVEN_REPO_LOCAL_TAIL);
372         if (localRepoTail != null) {
373             Arrays.stream(localRepoTail.split(","))
374                     .filter(p -> p != null && !p.trim().isEmpty())
375                     .map(this::resolve)
376                     .forEach(paths::add);
377         }
378         sessionBuilder.withLocalRepositoryBaseDirectories(paths);
379         // Pass over property supported by Maven 3.9.x
380         if (mergedProps.containsKey(Constants.MAVEN_REPO_LOCAL_TAIL_IGNORE_AVAILABILITY)) {
381             configProps.put(
382                     ChainedLocalRepositoryManager.CONFIG_PROP_IGNORE_TAIL_AVAILABILITY,
383                     mergedProps.get(Constants.MAVEN_REPO_LOCAL_TAIL_IGNORE_AVAILABILITY));
384         }
385 
386         for (RepositorySystemSessionExtender extender : sessionExtenders.values()) {
387             extender.extend(request, configProps, mirrorSelector, proxySelector, authSelector);
388         }
389 
390         // at this point we have "config" with pure MANDATORY resolver config, so resolver final config properties are
391         // mergedProperties + configProperties
392         HashMap<String, Object> finalConfigProperties = new HashMap<>();
393         finalConfigProperties.putAll(mergedProps);
394         finalConfigProperties.putAll(configProps);
395 
396         sessionBuilder.setUserProperties(request.getUserProperties());
397         sessionBuilder.setSystemProperties(request.getSystemProperties());
398         sessionBuilder.setConfigProperties(finalConfigProperties);
399 
400         return sessionBuilder;
401     }
402 
403     private Path resolve(String string) {
404         if (string.startsWith("~/") || string.startsWith("~\\")) {
405             // resolve based on $HOME
406             return Paths.get(System.getProperty("user.home"))
407                     .resolve(string.substring(2))
408                     .normalize()
409                     .toAbsolutePath();
410         } else {
411             // resolve based on $CWD
412             return Paths.get(string).normalize().toAbsolutePath();
413         }
414     }
415 
416     private VersionFilter buildVersionFilter(String filterExpression) {
417         ArrayList<VersionFilter> filters = new ArrayList<>();
418         if (filterExpression != null) {
419             List<String> expressions = Arrays.stream(filterExpression.split(";"))
420                     .filter(s -> s != null && !s.trim().isEmpty())
421                     .toList();
422             for (String expression : expressions) {
423                 if ("h".equals(expression)) {
424                     filters.add(new HighestVersionFilter());
425                 } else if (expression.startsWith("h(") && expression.endsWith(")")) {
426                     int num = Integer.parseInt(expression.substring(2, expression.length() - 1));
427                     filters.add(new HighestVersionFilter(num));
428                 } else if ("l".equals(expression)) {
429                     filters.add(new LowestVersionFilter());
430                 } else if (expression.startsWith("l(") && expression.endsWith(")")) {
431                     int num = Integer.parseInt(expression.substring(2, expression.length() - 1));
432                     filters.add(new LowestVersionFilter(num));
433                 } else if ("s".equals(expression)) {
434                     filters.add(new ContextualSnapshotVersionFilter());
435                 } else if (expression.startsWith("e(") && expression.endsWith(")")) {
436                     Artifact artifact = new DefaultArtifact(expression.substring(2, expression.length() - 1));
437                     VersionRange versionRange =
438                             artifact.getVersion().contains(",") ? parseVersionRange(artifact.getVersion()) : null;
439                     Predicate<Artifact> predicate = a -> {
440                         if (artifact.getGroupId().equals(a.getGroupId())
441                                 && artifact.getArtifactId().equals(a.getArtifactId())) {
442                             if (versionRange != null) {
443                                 Version v = parseVersion(a.getVersion());
444                                 return !versionRange.containsVersion(v);
445                             } else {
446                                 return !artifact.getVersion().equals(a.getVersion());
447                             }
448                         }
449                         return true;
450                     };
451                     filters.add(new PredicateVersionFilter(predicate));
452                 } else {
453                     throw new IllegalArgumentException("Unsupported filter expression: " + expression);
454                 }
455             }
456         }
457         if (filters.isEmpty()) {
458             return null;
459         } else if (filters.size() == 1) {
460             return filters.get(0);
461         } else {
462             return ChainedVersionFilter.newInstance(filters);
463         }
464     }
465 
466     private Version parseVersion(String spec) {
467         try {
468             return versionScheme.parseVersion(spec);
469         } catch (InvalidVersionSpecificationException e) {
470             throw new RuntimeException(e);
471         }
472     }
473 
474     private VersionRange parseVersionRange(String spec) {
475         try {
476             return versionScheme.parseVersionRange(spec);
477         } catch (InvalidVersionSpecificationException e) {
478             throw new RuntimeException(e);
479         }
480     }
481 
482     @SuppressWarnings({"unchecked", "rawtypes"})
483     private Map<String, String> createMergedProperties(MavenExecutionRequest request) {
484         // this throwaway map is really ONLY to get config from (profiles + env + system + user)
485         Map<String, String> mergedProps = new HashMap<>();
486         mergedProps.putAll(getPropertiesFromRequestedProfiles(request));
487         mergedProps.putAll(new HashMap<String, String>((Map) request.getSystemProperties()));
488         mergedProps.putAll(new HashMap<String, String>((Map) request.getUserProperties()));
489         return mergedProps;
490     }
491 
492     private Map<String, String> getPropertiesFromRequestedProfiles(MavenExecutionRequest request) {
493         HashSet<String> activeProfileId =
494                 new HashSet<>(request.getProfileActivation().getRequiredActiveProfileIds());
495         activeProfileId.addAll(request.getProfileActivation().getOptionalActiveProfileIds());
496 
497         return request.getProfiles().stream()
498                 .filter(profile -> activeProfileId.contains(profile.getId()))
499                 .map(ModelBase::getProperties)
500                 .flatMap(properties -> properties.entrySet().stream())
501                 .filter(e -> e.getValue() != null)
502                 .collect(Collectors.toMap(
503                         e -> String.valueOf(e.getKey()), e -> String.valueOf(e.getValue()), (k1, k2) -> k2));
504     }
505 
506     private String getUserAgent() {
507         String version = runtimeInformation.getMavenVersion();
508         version = version.isEmpty() ? version : "/" + version;
509         return "Apache-Maven" + version + " (Java " + System.getProperty("java.version") + "; "
510                 + System.getProperty("os.name") + " " + System.getProperty("os.version") + ")";
511     }
512 }