1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.internal.impl;
20
21 import javax.inject.Named;
22 import javax.inject.Singleton;
23
24 import java.util.concurrent.ConcurrentHashMap;
25 import java.util.concurrent.ConcurrentMap;
26
27 import org.eclipse.aether.ConfigurationProperties;
28 import org.eclipse.aether.RepositorySystemSession;
29 import org.eclipse.aether.repository.RemoteRepository;
30 import org.eclipse.aether.repository.RepositoryKeyFunction;
31 import org.eclipse.aether.spi.remoterepo.RepositoryKeyFunctionFactory;
32 import org.eclipse.aether.util.ConfigUtils;
33 import org.eclipse.aether.util.repository.RepositoryIdHelper;
34
35 import static java.util.Objects.requireNonNull;
36
37 @Singleton
38 @Named
39 public class DefaultRepositoryKeyFunctionFactory implements RepositoryKeyFunctionFactory {
40
41
42
43
44
45
46 @Override
47 public RepositoryKeyFunction systemRepositoryKeyFunction(RepositorySystemSession session) {
48 return repositoryKeyFunction(
49 DefaultRepositoryKeyFunctionFactory.class,
50 session,
51 ConfigurationProperties.DEFAULT_REPOSITORY_SYSTEM_REPOSITORY_KEY_FUNCTION,
52 ConfigurationProperties.REPOSITORY_SYSTEM_REPOSITORY_KEY_FUNCTION);
53 }
54
55
56
57
58
59
60
61
62
63 @SuppressWarnings("unchecked")
64 @Override
65 public RepositoryKeyFunction repositoryKeyFunction(
66 Class<?> owner, RepositorySystemSession session, String defaultValue, String configurationKey) {
67 requireNonNull(session);
68 requireNonNull(defaultValue);
69 final RepositoryKeyFunction repositoryKeyFunction = RepositoryIdHelper.getRepositoryKeyFunction(
70 configurationKey != null
71 ? ConfigUtils.getString(session, defaultValue, configurationKey)
72 : defaultValue);
73 if (session.getCache() != null) {
74
75 return (repository, context) -> ((ConcurrentMap<RemoteRepository, ConcurrentMap<String, String>>)
76 session.getCache()
77 .computeIfAbsent(
78 session,
79 owner.getName() + ".repositoryKeyFunction",
80 ConcurrentHashMap::new))
81 .computeIfAbsent(repository, k1 -> new ConcurrentHashMap<>())
82 .computeIfAbsent(
83 context == null ? "" : context, k2 -> repositoryKeyFunction.apply(repository, context));
84 } else {
85 return repositoryKeyFunction;
86 }
87 }
88 }