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.Keys;
29 import org.eclipse.aether.RepositorySystemSession;
30 import org.eclipse.aether.repository.RemoteRepository;
31 import org.eclipse.aether.repository.RepositoryKeyFunction;
32 import org.eclipse.aether.spi.remoterepo.RepositoryKeyFunctionFactory;
33 import org.eclipse.aether.util.ConfigUtils;
34 import org.eclipse.aether.util.repository.RepositoryIdHelper;
35
36 import static java.util.Objects.requireNonNull;
37
38 @Singleton
39 @Named
40 public class DefaultRepositoryKeyFunctionFactory implements RepositoryKeyFunctionFactory {
41
42
43
44
45
46
47 @Override
48 public RepositoryKeyFunction systemRepositoryKeyFunction(RepositorySystemSession session) {
49 return repositoryKeyFunction(
50 DefaultRepositoryKeyFunctionFactory.class,
51 session,
52 ConfigurationProperties.DEFAULT_REPOSITORY_SYSTEM_REPOSITORY_KEY_FUNCTION,
53 ConfigurationProperties.REPOSITORY_SYSTEM_REPOSITORY_KEY_FUNCTION);
54 }
55
56
57
58
59
60
61
62
63
64 @SuppressWarnings("unchecked")
65 @Override
66 public RepositoryKeyFunction repositoryKeyFunction(
67 Class<?> owner, RepositorySystemSession session, String defaultValue, String configurationKey) {
68 requireNonNull(session);
69 requireNonNull(defaultValue);
70 final RepositoryKeyFunction repositoryKeyFunction = RepositoryIdHelper.getRepositoryKeyFunction(
71 configurationKey != null
72 ? ConfigUtils.getString(session, defaultValue, configurationKey)
73 : defaultValue);
74 if (session.getCache() != null) {
75
76 return (repository, context) -> ((ConcurrentMap<RemoteRepository, ConcurrentMap<String, String>>)
77 session.getCache()
78 .computeIfAbsent(
79 session, Keys.of(owner, "repositoryKeyFunction"), ConcurrentHashMap::new))
80 .computeIfAbsent(repository, k1 -> new ConcurrentHashMap<>())
81 .computeIfAbsent(
82 context == null ? "" : context, k2 -> repositoryKeyFunction.apply(repository, context));
83 } else {
84 return repositoryKeyFunction;
85 }
86 }
87 }