in impl/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java [154:401]
public SessionBuilder newRepositorySessionBuilder(MavenExecutionRequest request) {
requireNonNull(request, "request");
MavenSessionBuilderSupplier supplier = new MavenSessionBuilderSupplier(repoSystem);
SessionBuilder sessionBuilder = supplier.get();
sessionBuilder.setArtifactTypeRegistry(new TypeRegistryAdapter(typeRegistry)); // dynamic
sessionBuilder.setCache(request.getRepositoryCache());
// this map is read ONLY to get config from (profiles + env + system + user)
Map<String, String> mergedProps = createMergedProperties(request);
// configProps map is kept "pristine", is written ONLY, the mandatory resolver config
Map<String, Object> configProps = new LinkedHashMap<>();
configProps.put(ConfigurationProperties.USER_AGENT, getUserAgent());
configProps.put(ConfigurationProperties.INTERACTIVE, request.isInteractiveMode());
configProps.put("maven.startTime", request.getStartTime());
configProps.put(Constants.MAVEN_START_INSTANT, request.getStartInstant());
sessionBuilder.setOffline(request.isOffline());
sessionBuilder.setChecksumPolicy(request.getGlobalChecksumPolicy());
sessionBuilder.setUpdatePolicy(
request.isNoSnapshotUpdates()
? RepositoryPolicy.UPDATE_POLICY_NEVER
: request.isUpdateSnapshots() ? RepositoryPolicy.UPDATE_POLICY_ALWAYS : null);
int errorPolicy = 0;
errorPolicy |= request.isCacheNotFound()
? ResolutionErrorPolicy.CACHE_NOT_FOUND
: ResolutionErrorPolicy.CACHE_DISABLED;
errorPolicy |= request.isCacheTransferError()
? ResolutionErrorPolicy.CACHE_TRANSFER_ERROR
: ResolutionErrorPolicy.CACHE_DISABLED;
sessionBuilder.setResolutionErrorPolicy(
new SimpleResolutionErrorPolicy(errorPolicy, errorPolicy | ResolutionErrorPolicy.CACHE_NOT_FOUND));
sessionBuilder.setArtifactDescriptorPolicy(new SimpleArtifactDescriptorPolicy(
request.isIgnoreMissingArtifactDescriptor(), request.isIgnoreInvalidArtifactDescriptor()));
VersionFilter versionFilter = buildVersionFilter(mergedProps.get(Constants.MAVEN_VERSION_FILTER));
if (versionFilter != null) {
sessionBuilder.setVersionFilter(versionFilter);
}
DefaultMirrorSelector mirrorSelector = new DefaultMirrorSelector();
for (Mirror mirror : request.getMirrors()) {
mirrorSelector.add(
mirror.getId(),
mirror.getUrl(),
mirror.getLayout(),
false,
mirror.isBlocked(),
mirror.getMirrorOf(),
mirror.getMirrorOfLayouts());
}
sessionBuilder.setMirrorSelector(mirrorSelector);
DefaultProxySelector proxySelector = new DefaultProxySelector();
for (Proxy proxy : request.getProxies()) {
AuthenticationBuilder authBuilder = new AuthenticationBuilder();
authBuilder.addUsername(proxy.getUsername()).addPassword(proxy.getPassword());
proxySelector.add(
new org.eclipse.aether.repository.Proxy(
proxy.getProtocol(), proxy.getHost(), proxy.getPort(), authBuilder.build()),
proxy.getNonProxyHosts());
}
sessionBuilder.setProxySelector(proxySelector);
// Note: we do NOT use WagonTransportConfigurationKeys here as Maven Core does NOT depend on Wagon Transport
// and this is okay and "good thing".
DefaultAuthenticationSelector authSelector = new DefaultAuthenticationSelector();
for (Server server : request.getServers()) {
AuthenticationBuilder authBuilder = new AuthenticationBuilder();
authBuilder.addUsername(server.getUsername()).addPassword(server.getPassword());
authBuilder.addPrivateKey(server.getPrivateKey(), server.getPassphrase());
authSelector.add(server.getId(), authBuilder.build());
if (server.getConfiguration() != null) {
XmlNode dom = server.getDelegate().getConfiguration();
List<XmlNode> children = dom.children().stream()
.filter(c -> !"wagonProvider".equals(c.name()))
.collect(Collectors.toList());
dom = XmlNode.newInstance(dom.name(), children);
PlexusConfiguration config = XmlPlexusConfiguration.toPlexusConfiguration(dom);
configProps.put("aether.transport.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 {} uses legacy format", server.getId());
}
}
}
}
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 {} uses legacy format", server.getId());
}
}
}
}
// 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.transport.wagon.perms.fileMode." + server.getId(), server.getFilePermissions());
configProps.put("aether.transport.wagon.perms.dirMode." + server.getId(), server.getDirectoryPermissions());
}
sessionBuilder.setAuthenticationSelector(authSelector);
Object transport =
mergedProps.getOrDefault(Constants.MAVEN_RESOLVER_TRANSPORT, MAVEN_RESOLVER_TRANSPORT_DEFAULT);
if (MAVEN_RESOLVER_TRANSPORT_DEFAULT.equals(transport)) {
// The "default" mode (user did not set anything) from now on defaults to AUTO
} else if (MAVEN_RESOLVER_TRANSPORT_JDK.equals(transport)) {
// Make sure (whatever extra priority is set) that resolver file/jdk is selected
configProps.put(FILE_TRANSPORTER_PRIORITY_KEY, RESOLVER_MAX_PRIORITY);
configProps.put(JDK_HTTP_TRANSPORTER_PRIORITY_KEY, RESOLVER_MAX_PRIORITY);
} else if (MAVEN_RESOLVER_TRANSPORT_APACHE.equals(transport)
|| MAVEN_RESOLVER_TRANSPORT_NATIVE.equals(transport)) {
if (MAVEN_RESOLVER_TRANSPORT_NATIVE.equals(transport)) {
logger.warn(
"Transport name '{}' is DEPRECATED/RENAMED, use '{}' instead",
MAVEN_RESOLVER_TRANSPORT_NATIVE,
MAVEN_RESOLVER_TRANSPORT_APACHE);
}
// Make sure (whatever extra priority is set) that resolver file/apache is selected
configProps.put(FILE_TRANSPORTER_PRIORITY_KEY, RESOLVER_MAX_PRIORITY);
configProps.put(APACHE_HTTP_TRANSPORTER_PRIORITY_KEY, RESOLVER_MAX_PRIORITY);
} else if (MAVEN_RESOLVER_TRANSPORT_WAGON.equals(transport)) {
// Make sure (whatever extra priority is set) that wagon is selected
configProps.put(WAGON_TRANSPORTER_PRIORITY_KEY, RESOLVER_MAX_PRIORITY);
} else if (!MAVEN_RESOLVER_TRANSPORT_AUTO.equals(transport)) {
throw new IllegalArgumentException("Unknown resolver transport '" + transport
+ "'. Supported transports are: " + MAVEN_RESOLVER_TRANSPORT_WAGON + ", "
+ MAVEN_RESOLVER_TRANSPORT_APACHE + ", " + MAVEN_RESOLVER_TRANSPORT_JDK + ", "
+ MAVEN_RESOLVER_TRANSPORT_AUTO);
}
sessionBuilder.setIgnoreArtifactDescriptorRepositories(request.isIgnoreTransitiveRepositories());
sessionBuilder.setTransferListener(request.getTransferListener());
RepositoryListener repositoryListener = eventSpyDispatcher.chainListener(new LoggingRepositoryListener(logger));
boolean recordReverseTree = Boolean.parseBoolean(
mergedProps.getOrDefault(Constants.MAVEN_REPO_LOCAL_RECORD_REVERSE_TREE, Boolean.FALSE.toString()));
if (recordReverseTree) {
repositoryListener = new ChainedRepositoryListener(repositoryListener, new ReverseTreeRepositoryListener());
}
sessionBuilder.setRepositoryListener(repositoryListener);
// may be overridden
String resolverDependencyManagerTransitivity = mergedProps.getOrDefault(
Constants.MAVEN_RESOLVER_DEPENDENCY_MANAGER_TRANSITIVITY, Boolean.TRUE.toString());
sessionBuilder.setDependencyManager(
supplier.getDependencyManager(Boolean.parseBoolean(resolverDependencyManagerTransitivity)));
ArrayList<Path> paths = new ArrayList<>();
String localRepoHead = mergedProps.get(Constants.MAVEN_REPO_LOCAL_HEAD);
if (localRepoHead != null) {
Arrays.stream(localRepoHead.split(","))
.filter(p -> p != null && !p.trim().isEmpty())
.map(this::resolve)
.forEach(paths::add);
}
paths.add(Paths.get(request.getLocalRepository().getBasedir()));
String localRepoTail = mergedProps.get(Constants.MAVEN_REPO_LOCAL_TAIL);
if (localRepoTail != null) {
Arrays.stream(localRepoTail.split(","))
.filter(p -> p != null && !p.trim().isEmpty())
.map(this::resolve)
.forEach(paths::add);
}
sessionBuilder.withLocalRepositoryBaseDirectories(paths);
// Pass over property supported by Maven 3.9.x
if (mergedProps.containsKey(Constants.MAVEN_REPO_LOCAL_TAIL_IGNORE_AVAILABILITY)) {
configProps.put(
ChainedLocalRepositoryManager.CONFIG_PROP_IGNORE_TAIL_AVAILABILITY,
mergedProps.get(Constants.MAVEN_REPO_LOCAL_TAIL_IGNORE_AVAILABILITY));
}
for (RepositorySystemSessionExtender extender : sessionExtenders.values()) {
extender.extend(request, configProps, mirrorSelector, proxySelector, authSelector);
}
// at this point we have "config" with pure MANDATORY resolver config, so resolver final config properties are
// mergedProperties + configProperties
HashMap<String, Object> finalConfigProperties = new HashMap<>();
finalConfigProperties.putAll(mergedProps);
finalConfigProperties.putAll(configProps);
sessionBuilder.setUserProperties(request.getUserProperties());
sessionBuilder.setSystemProperties(request.getSystemProperties());
sessionBuilder.setConfigProperties(finalConfigProperties);
return sessionBuilder;
}