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.version;
20
21 import javax.inject.Inject;
22 import javax.inject.Named;
23 import javax.inject.Singleton;
24
25 import java.util.Collections;
26 import java.util.Map;
27
28 import org.eclipse.aether.ConfigurationProperties;
29 import org.eclipse.aether.RepositorySystemSession;
30 import org.eclipse.aether.spi.version.VersionSchemeSelector;
31 import org.eclipse.aether.util.ConfigUtils;
32 import org.eclipse.aether.version.VersionScheme;
33
34 import static java.util.Objects.requireNonNull;
35
36
37
38
39
40
41 @Singleton
42 @Named
43 public class DefaultVersionSchemeSelector implements VersionSchemeSelector {
44 static final String CONFIG_PROPS_PREFIX = ConfigurationProperties.PREFIX_AETHER + "versionScheme.";
45
46
47
48
49
50
51
52
53 public static final String CONFIG_PROP_VERSION_SCHEME_NAME = CONFIG_PROPS_PREFIX + "name";
54
55 public static final String DEFAULT_VERSION_SCHEME_NAME = GenericVersionSchemeProvider.NAME;
56
57 private final Map<String, VersionScheme> versionSchemes;
58
59 @Inject
60 public DefaultVersionSchemeSelector(Map<String, VersionScheme> versionSchemes) {
61 this.versionSchemes = requireNonNull(versionSchemes);
62 }
63
64 @Override
65 public VersionScheme selectVersionScheme(String schemeName) {
66 requireNonNull(schemeName, "null schemeName");
67 VersionScheme versionScheme = versionSchemes.get(schemeName);
68 if (versionScheme == null) {
69 throw new IllegalArgumentException("scheme not supported");
70 }
71 return versionScheme;
72 }
73
74 @Override
75 public VersionScheme selectVersionScheme(RepositorySystemSession session) {
76 return selectVersionScheme(
77 ConfigUtils.getString(session, DEFAULT_VERSION_SCHEME_NAME, CONFIG_PROP_VERSION_SCHEME_NAME));
78 }
79
80 @Override
81 public Map<String, VersionScheme> getVersionSchemes() {
82 return Collections.unmodifiableMap(versionSchemes);
83 }
84 }