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 org.eclipse.aether.RepositorySystemSession;
22 import org.eclipse.aether.artifact.Artifact;
23 import org.eclipse.aether.metadata.Metadata;
24 import org.eclipse.aether.repository.RemoteRepository;
25 import org.eclipse.aether.repository.RepositoryKeyFunction;
26 import org.eclipse.aether.util.ConfigUtils;
27
28
29
30
31
32
33
34
35
36
37
38
39 public abstract class LocalPathPrefixComposerFactorySupport implements LocalPathPrefixComposerFactory {
40
41
42
43
44
45
46
47
48 public static final String CONFIG_PROP_SPLIT = EnhancedLocalRepositoryManagerFactory.CONFIG_PROPS_PREFIX + "split";
49
50 public static final boolean DEFAULT_SPLIT = false;
51
52
53
54
55
56
57
58
59 public static final String CONFIG_PROP_LOCAL_PREFIX =
60 EnhancedLocalRepositoryManagerFactory.CONFIG_PROPS_PREFIX + "localPrefix";
61
62 public static final String DEFAULT_LOCAL_PREFIX = "installed";
63
64
65
66
67
68
69
70
71 public static final String CONFIG_PROP_SPLIT_LOCAL =
72 EnhancedLocalRepositoryManagerFactory.CONFIG_PROPS_PREFIX + "splitLocal";
73
74 public static final boolean DEFAULT_SPLIT_LOCAL = false;
75
76
77
78
79
80
81
82
83 public static final String CONFIG_PROP_REMOTE_PREFIX =
84 EnhancedLocalRepositoryManagerFactory.CONFIG_PROPS_PREFIX + "remotePrefix";
85
86 public static final String DEFAULT_REMOTE_PREFIX = "cached";
87
88
89
90
91
92
93
94
95 public static final String CONFIG_PROP_SPLIT_REMOTE =
96 EnhancedLocalRepositoryManagerFactory.CONFIG_PROPS_PREFIX + "splitRemote";
97
98 public static final boolean DEFAULT_SPLIT_REMOTE = false;
99
100
101
102
103
104
105
106
107 public static final String CONFIG_PROP_SPLIT_REMOTE_REPOSITORY =
108 EnhancedLocalRepositoryManagerFactory.CONFIG_PROPS_PREFIX + "splitRemoteRepository";
109
110 public static final boolean DEFAULT_SPLIT_REMOTE_REPOSITORY = false;
111
112
113
114
115
116
117
118
119
120 public static final String CONFIG_PROP_SPLIT_REMOTE_REPOSITORY_LAST =
121 EnhancedLocalRepositoryManagerFactory.CONFIG_PROPS_PREFIX + "splitRemoteRepositoryLast";
122
123 public static final boolean DEFAULT_SPLIT_REMOTE_REPOSITORY_LAST = false;
124
125
126
127
128
129
130
131
132 public static final String CONFIG_PROP_RELEASES_PREFIX =
133 EnhancedLocalRepositoryManagerFactory.CONFIG_PROPS_PREFIX + "releasesPrefix";
134
135 public static final String DEFAULT_RELEASES_PREFIX = "releases";
136
137
138
139
140
141
142
143
144 public static final String CONFIG_PROP_SNAPSHOTS_PREFIX =
145 EnhancedLocalRepositoryManagerFactory.CONFIG_PROPS_PREFIX + "snapshotsPrefix";
146
147 public static final String DEFAULT_SNAPSHOTS_PREFIX = "snapshots";
148
149
150
151
152 private static final String R1_CONF_PROP_SPLIT = "aether.enhancedLocalRepository.split";
153
154 private static final String R1_CONF_PROP_LOCAL_PREFIX = "aether.enhancedLocalRepository.localPrefix";
155
156 private static final String R1_CONF_PROP_SPLIT_LOCAL = "aether.enhancedLocalRepository.splitLocal";
157
158 private static final String R1_CONF_PROP_REMOTE_PREFIX = "aether.enhancedLocalRepository.remotePrefix";
159
160 private static final String R1_CONF_PROP_SPLIT_REMOTE = "aether.enhancedLocalRepository.splitRemote";
161
162 private static final String R1_CONF_PROP_SPLIT_REMOTE_REPOSITORY =
163 "aether.enhancedLocalRepository.splitRemoteRepository";
164
165 private static final String R1_CONF_PROP_SPLIT_REMOTE_REPOSITORY_LAST =
166 "aether.enhancedLocalRepository.splitRemoteRepositoryLast";
167
168 private static final String R1_CONF_PROP_RELEASES_PREFIX = "aether.enhancedLocalRepository.releasesPrefix";
169
170 private static final String R1_CONF_PROP_SNAPSHOTS_PREFIX = "aether.enhancedLocalRepository.snapshotsPrefix";
171
172 protected boolean isSplit(RepositorySystemSession session) {
173 return ConfigUtils.getBoolean(session, DEFAULT_SPLIT, CONFIG_PROP_SPLIT, R1_CONF_PROP_SPLIT);
174 }
175
176 protected String getLocalPrefix(RepositorySystemSession session) {
177 return ConfigUtils.getString(
178 session, DEFAULT_LOCAL_PREFIX, CONFIG_PROP_LOCAL_PREFIX, R1_CONF_PROP_LOCAL_PREFIX);
179 }
180
181 protected boolean isSplitLocal(RepositorySystemSession session) {
182 return ConfigUtils.getBoolean(session, DEFAULT_SPLIT_LOCAL, CONFIG_PROP_SPLIT_LOCAL, R1_CONF_PROP_SPLIT_LOCAL);
183 }
184
185 protected String getRemotePrefix(RepositorySystemSession session) {
186 return ConfigUtils.getString(
187 session, DEFAULT_REMOTE_PREFIX, CONFIG_PROP_REMOTE_PREFIX, R1_CONF_PROP_REMOTE_PREFIX);
188 }
189
190 protected boolean isSplitRemote(RepositorySystemSession session) {
191 return ConfigUtils.getBoolean(
192 session, DEFAULT_SPLIT_REMOTE, CONFIG_PROP_SPLIT_REMOTE, R1_CONF_PROP_SPLIT_REMOTE);
193 }
194
195 protected boolean isSplitRemoteRepository(RepositorySystemSession session) {
196 return ConfigUtils.getBoolean(
197 session,
198 DEFAULT_SPLIT_REMOTE_REPOSITORY,
199 CONFIG_PROP_SPLIT_REMOTE_REPOSITORY,
200 R1_CONF_PROP_SPLIT_REMOTE_REPOSITORY);
201 }
202
203 protected boolean isSplitRemoteRepositoryLast(RepositorySystemSession session) {
204 return ConfigUtils.getBoolean(
205 session,
206 DEFAULT_SPLIT_REMOTE_REPOSITORY_LAST,
207 CONFIG_PROP_SPLIT_REMOTE_REPOSITORY_LAST,
208 R1_CONF_PROP_SPLIT_REMOTE_REPOSITORY_LAST);
209 }
210
211 protected String getReleasesPrefix(RepositorySystemSession session) {
212 return ConfigUtils.getString(
213 session, DEFAULT_RELEASES_PREFIX, CONFIG_PROP_RELEASES_PREFIX, R1_CONF_PROP_RELEASES_PREFIX);
214 }
215
216 protected String getSnapshotsPrefix(RepositorySystemSession session) {
217 return ConfigUtils.getString(
218 session, DEFAULT_SNAPSHOTS_PREFIX, CONFIG_PROP_SNAPSHOTS_PREFIX, R1_CONF_PROP_SNAPSHOTS_PREFIX);
219 }
220
221
222
223
224
225 @SuppressWarnings("checkstyle:parameternumber")
226 protected abstract static class LocalPathPrefixComposerSupport implements LocalPathPrefixComposer {
227 protected final boolean split;
228
229 protected final String localPrefix;
230
231 protected final boolean splitLocal;
232
233 protected final String remotePrefix;
234
235 protected final boolean splitRemote;
236
237 protected final boolean splitRemoteRepository;
238
239 protected final boolean splitRemoteRepositoryLast;
240
241 protected final String releasesPrefix;
242
243 protected final String snapshotsPrefix;
244
245 protected final RepositoryKeyFunction repositoryKeyFunction;
246
247 protected LocalPathPrefixComposerSupport(
248 boolean split,
249 String localPrefix,
250 boolean splitLocal,
251 String remotePrefix,
252 boolean splitRemote,
253 boolean splitRemoteRepository,
254 boolean splitRemoteRepositoryLast,
255 String releasesPrefix,
256 String snapshotsPrefix,
257 RepositoryKeyFunction repositoryKeyFunction) {
258 this.split = split;
259 this.localPrefix = localPrefix;
260 this.splitLocal = splitLocal;
261 this.remotePrefix = remotePrefix;
262 this.splitRemote = splitRemote;
263 this.splitRemoteRepository = splitRemoteRepository;
264 this.splitRemoteRepositoryLast = splitRemoteRepositoryLast;
265 this.releasesPrefix = releasesPrefix;
266 this.snapshotsPrefix = snapshotsPrefix;
267 this.repositoryKeyFunction = repositoryKeyFunction;
268 }
269
270 @Override
271 public String getPathPrefixForLocalArtifact(Artifact artifact) {
272 if (!split) {
273 return null;
274 }
275 String result = localPrefix;
276 if (splitLocal) {
277 result += "/" + (artifact.isSnapshot() ? snapshotsPrefix : releasesPrefix);
278 }
279 return result;
280 }
281
282 @Override
283 public String getPathPrefixForRemoteArtifact(Artifact artifact, RemoteRepository repository) {
284 if (!split) {
285 return null;
286 }
287 String result = remotePrefix;
288 if (!splitRemoteRepositoryLast && splitRemoteRepository) {
289 result += "/" + repositoryKeyFunction.apply(repository, null);
290 }
291 if (splitRemote) {
292 result += "/" + (artifact.isSnapshot() ? snapshotsPrefix : releasesPrefix);
293 }
294 if (splitRemoteRepositoryLast && splitRemoteRepository) {
295 result += "/" + repositoryKeyFunction.apply(repository, null);
296 }
297 return result;
298 }
299
300 @Override
301 public String getPathPrefixForLocalMetadata(Metadata metadata) {
302 if (!split) {
303 return null;
304 }
305 String result = localPrefix;
306 if (splitLocal) {
307 result += "/" + (isSnapshot(metadata) ? snapshotsPrefix : releasesPrefix);
308 }
309 return result;
310 }
311
312 @Override
313 public String getPathPrefixForRemoteMetadata(Metadata metadata, RemoteRepository repository) {
314 if (!split) {
315 return null;
316 }
317 String result = remotePrefix;
318 if (!splitRemoteRepositoryLast && splitRemoteRepository) {
319 result += "/" + repositoryKeyFunction.apply(repository, null);
320 }
321 if (splitRemote) {
322 result += "/" + (isSnapshot(metadata) ? snapshotsPrefix : releasesPrefix);
323 }
324 if (splitRemoteRepositoryLast && splitRemoteRepository) {
325 result += "/" + repositoryKeyFunction.apply(repository, null);
326 }
327 return result;
328 }
329
330 protected boolean isSnapshot(Metadata metadata) {
331 return !metadata.getVersion().isEmpty() && metadata.getVersion().endsWith("-SNAPSHOT");
332 }
333 }
334 }