1
2
3
4
5 package org.apache.maven.api.metadata;
6
7 import java.io.Serializable;
8 import java.util.ArrayList;
9 import java.util.Collection;
10 import java.util.Collections;
11 import java.util.HashMap;
12 import java.util.List;
13 import java.util.Map;
14 import java.util.Objects;
15 import java.util.Optional;
16 import java.util.Set;
17 import java.util.stream.Collectors;
18 import java.util.stream.Stream;
19 import org.apache.maven.api.annotations.Experimental;
20 import org.apache.maven.api.annotations.Generated;
21 import org.apache.maven.api.annotations.Immutable;
22 import org.apache.maven.api.annotations.Nonnull;
23 import org.apache.maven.api.annotations.NotThreadSafe;
24 import org.apache.maven.api.annotations.ThreadSafe;
25
26
27
28
29 @Experimental
30 @Generated @ThreadSafe @Immutable
31 public class Versioning
32 implements Serializable
33 {
34
35
36
37 final String latest;
38
39
40
41 final String release;
42
43
44
45 final List<String> versions;
46
47
48
49 final String lastUpdated;
50
51
52
53 final Snapshot snapshot;
54
55
56
57 final List<SnapshotVersion> snapshotVersions;
58
59
60
61
62
63 protected Versioning(Builder builder) {
64 this.latest = builder.latest != null ? builder.latest : (builder.base != null ? builder.base.latest : null);
65 this.release = builder.release != null ? builder.release : (builder.base != null ? builder.base.release : null);
66 this.versions = ImmutableCollections.copy(builder.versions != null ? builder.versions : (builder.base != null ? builder.base.versions : null));
67 this.lastUpdated = builder.lastUpdated != null ? builder.lastUpdated : (builder.base != null ? builder.base.lastUpdated : null);
68 this.snapshot = builder.snapshot != null ? builder.snapshot : (builder.base != null ? builder.base.snapshot : null);
69 this.snapshotVersions = ImmutableCollections.copy(builder.snapshotVersions != null ? builder.snapshotVersions : (builder.base != null ? builder.base.snapshotVersions : null));
70 }
71
72
73
74
75
76
77 public String getLatest() {
78 return this.latest;
79 }
80
81
82
83
84
85
86 public String getRelease() {
87 return this.release;
88 }
89
90
91
92
93
94
95 @Nonnull
96 public List<String> getVersions() {
97 return this.versions;
98 }
99
100
101
102
103
104
105 public String getLastUpdated() {
106 return this.lastUpdated;
107 }
108
109
110
111
112
113
114 public Snapshot getSnapshot() {
115 return this.snapshot;
116 }
117
118
119
120
121
122
123 @Nonnull
124 public List<SnapshotVersion> getSnapshotVersions() {
125 return this.snapshotVersions;
126 }
127
128
129
130
131
132
133 @Nonnull
134 public Builder with() {
135 return newBuilder(this);
136 }
137
138
139
140
141
142
143 @Nonnull
144 public Versioning withLatest(String latest) {
145 return newBuilder(this, true).latest(latest).build();
146 }
147
148
149
150
151
152
153 @Nonnull
154 public Versioning withRelease(String release) {
155 return newBuilder(this, true).release(release).build();
156 }
157
158
159
160
161
162
163 @Nonnull
164 public Versioning withVersions(Collection<String> versions) {
165 return newBuilder(this, true).versions(versions).build();
166 }
167
168
169
170
171
172
173 @Nonnull
174 public Versioning withLastUpdated(String lastUpdated) {
175 return newBuilder(this, true).lastUpdated(lastUpdated).build();
176 }
177
178
179
180
181
182
183 @Nonnull
184 public Versioning withSnapshot(Snapshot snapshot) {
185 return newBuilder(this, true).snapshot(snapshot).build();
186 }
187
188
189
190
191
192
193 @Nonnull
194 public Versioning withSnapshotVersions(Collection<SnapshotVersion> snapshotVersions) {
195 return newBuilder(this, true).snapshotVersions(snapshotVersions).build();
196 }
197
198
199
200
201
202
203
204
205 @Nonnull
206 public static Versioning newInstance() {
207 return newInstance(true);
208 }
209
210
211
212
213
214
215
216
217 @Nonnull
218 public static Versioning newInstance(boolean withDefaults) {
219 return newBuilder(withDefaults).build();
220 }
221
222
223
224
225
226
227
228
229 @Nonnull
230 public static Builder newBuilder() {
231 return newBuilder(true);
232 }
233
234
235
236
237
238
239
240 @Nonnull
241 public static Builder newBuilder(boolean withDefaults) {
242 return new Builder(withDefaults);
243 }
244
245
246
247
248
249
250
251
252 @Nonnull
253 public static Builder newBuilder(Versioning from) {
254 return newBuilder(from, false);
255 }
256
257
258
259
260
261
262
263
264 @Nonnull
265 public static Builder newBuilder(Versioning from, boolean forceCopy) {
266 return new Builder(from, forceCopy);
267 }
268
269
270
271
272
273
274 @NotThreadSafe
275 public static class Builder
276 {
277 Versioning base;
278 String latest;
279 String release;
280 Collection<String> versions;
281 String lastUpdated;
282 Snapshot snapshot;
283 Collection<SnapshotVersion> snapshotVersions;
284
285 protected Builder(boolean withDefaults) {
286 if (withDefaults) {
287 }
288 }
289
290 protected Builder(Versioning base, boolean forceCopy) {
291 if (forceCopy) {
292 this.latest = base.latest;
293 this.release = base.release;
294 this.versions = base.versions;
295 this.lastUpdated = base.lastUpdated;
296 this.snapshot = base.snapshot;
297 this.snapshotVersions = base.snapshotVersions;
298 } else {
299 this.base = base;
300 }
301 }
302
303 @Nonnull
304 public Builder latest(String latest) {
305 this.latest = latest;
306 return this;
307 }
308
309 @Nonnull
310 public Builder release(String release) {
311 this.release = release;
312 return this;
313 }
314
315 @Nonnull
316 public Builder versions(Collection<String> versions) {
317 this.versions = versions;
318 return this;
319 }
320
321 @Nonnull
322 public Builder lastUpdated(String lastUpdated) {
323 this.lastUpdated = lastUpdated;
324 return this;
325 }
326
327 @Nonnull
328 public Builder snapshot(Snapshot snapshot) {
329 this.snapshot = snapshot;
330 return this;
331 }
332
333 @Nonnull
334 public Builder snapshotVersions(Collection<SnapshotVersion> snapshotVersions) {
335 this.snapshotVersions = snapshotVersions;
336 return this;
337 }
338
339
340 @Nonnull
341 public Versioning build() {
342
343 if (base != null
344 && (latest == null || latest == base.latest)
345 && (release == null || release == base.release)
346 && (versions == null || versions == base.versions)
347 && (lastUpdated == null || lastUpdated == base.lastUpdated)
348 && (snapshot == null || snapshot == base.snapshot)
349 && (snapshotVersions == null || snapshotVersions == base.snapshotVersions)
350 ) {
351 return base;
352 }
353 return new Versioning(this);
354 }
355
356 }
357
358 }