1 // =================== DO NOT EDIT THIS FILE ====================
2 // Generated by Modello Velocity from model.vm
3 // template, any modifications will be overwritten.
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 * Versioning information for "groupId/artifactId" or "groupId/artifactId/version" SNAPSHOT
28 */
29 @Experimental
30 @Generated @ThreadSafe @Immutable
31 public class Versioning
32 implements Serializable
33 {
34 /**
35 * What the last version added to the directory is, including both releases and snapshots ("groupId/artifactId" directory only)
36 */
37 final String latest;
38 /**
39 * What the last version added to the directory is, for the releases only ("groupId/artifactId" directory only)
40 */
41 final String release;
42 /**
43 * Versions available of the artifact (both releases and snapshots) ("groupId/artifactId" directory only)
44 */
45 final List<String> versions;
46 /**
47 * When the metadata was last updated (both "groupId/artifactId" and "groupId/artifactId/version" directories). The timestamp is expressed using UTC in the format yyyyMMddHHmmss.
48 */
49 final String lastUpdated;
50 /**
51 * The current snapshot data in use for this version ("groupId/artifactId/version" only)
52 */
53 final Snapshot snapshot;
54 /**
55 * Information for each sub-artifact available in this artifact snapshot. This is only the most recent SNAPSHOT for each unique extension/classifier combination.
56 */
57 final List<SnapshotVersion> snapshotVersions;
58
59 /**
60 * Constructor for this class, to be called from its subclasses and {@link Builder}.
61 * @see Builder#build()
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 * What the last version added to the directory is, including both releases and snapshots ("groupId/artifactId" directory only)
74 *
75 * @return a {@code String}
76 */
77 public String getLatest() {
78 return this.latest;
79 }
80
81 /**
82 * What the last version added to the directory is, for the releases only ("groupId/artifactId" directory only)
83 *
84 * @return a {@code String}
85 */
86 public String getRelease() {
87 return this.release;
88 }
89
90 /**
91 * Versions available of the artifact (both releases and snapshots) ("groupId/artifactId" directory only)
92 *
93 * @return a {@code List<String>}
94 */
95 @Nonnull
96 public List<String> getVersions() {
97 return this.versions;
98 }
99
100 /**
101 * When the metadata was last updated (both "groupId/artifactId" and "groupId/artifactId/version" directories). The timestamp is expressed using UTC in the format yyyyMMddHHmmss.
102 *
103 * @return a {@code String}
104 */
105 public String getLastUpdated() {
106 return this.lastUpdated;
107 }
108
109 /**
110 * The current snapshot data in use for this version ("groupId/artifactId/version" only)
111 *
112 * @return a {@code Snapshot}
113 */
114 public Snapshot getSnapshot() {
115 return this.snapshot;
116 }
117
118 /**
119 * Information for each sub-artifact available in this artifact snapshot. This is only the most recent SNAPSHOT for each unique extension/classifier combination.
120 *
121 * @return a {@code List<SnapshotVersion>}
122 */
123 @Nonnull
124 public List<SnapshotVersion> getSnapshotVersions() {
125 return this.snapshotVersions;
126 }
127
128 /**
129 * Creates a new builder with this object as the basis.
130 *
131 * @return a {@code Builder}
132 */
133 @Nonnull
134 public Builder with() {
135 return newBuilder(this);
136 }
137 /**
138 * Creates a new {@code Versioning} instance using the specified latest.
139 *
140 * @param latest the new {@code String} to use
141 * @return a {@code Versioning} with the specified latest
142 */
143 @Nonnull
144 public Versioning withLatest(String latest) {
145 return newBuilder(this, true).latest(latest).build();
146 }
147 /**
148 * Creates a new {@code Versioning} instance using the specified release.
149 *
150 * @param release the new {@code String} to use
151 * @return a {@code Versioning} with the specified release
152 */
153 @Nonnull
154 public Versioning withRelease(String release) {
155 return newBuilder(this, true).release(release).build();
156 }
157 /**
158 * Creates a new {@code Versioning} instance using the specified versions.
159 *
160 * @param versions the new {@code Collection<String>} to use
161 * @return a {@code Versioning} with the specified versions
162 */
163 @Nonnull
164 public Versioning withVersions(Collection<String> versions) {
165 return newBuilder(this, true).versions(versions).build();
166 }
167 /**
168 * Creates a new {@code Versioning} instance using the specified lastUpdated.
169 *
170 * @param lastUpdated the new {@code String} to use
171 * @return a {@code Versioning} with the specified lastUpdated
172 */
173 @Nonnull
174 public Versioning withLastUpdated(String lastUpdated) {
175 return newBuilder(this, true).lastUpdated(lastUpdated).build();
176 }
177 /**
178 * Creates a new {@code Versioning} instance using the specified snapshot.
179 *
180 * @param snapshot the new {@code Snapshot} to use
181 * @return a {@code Versioning} with the specified snapshot
182 */
183 @Nonnull
184 public Versioning withSnapshot(Snapshot snapshot) {
185 return newBuilder(this, true).snapshot(snapshot).build();
186 }
187 /**
188 * Creates a new {@code Versioning} instance using the specified snapshotVersions.
189 *
190 * @param snapshotVersions the new {@code Collection<SnapshotVersion>} to use
191 * @return a {@code Versioning} with the specified snapshotVersions
192 */
193 @Nonnull
194 public Versioning withSnapshotVersions(Collection<SnapshotVersion> snapshotVersions) {
195 return newBuilder(this, true).snapshotVersions(snapshotVersions).build();
196 }
197
198 /**
199 * Creates a new {@code Versioning} instance.
200 * Equivalent to {@code newInstance(true)}.
201 * @see #newInstance(boolean)
202 *
203 * @return a new {@code Versioning}
204 */
205 @Nonnull
206 public static Versioning newInstance() {
207 return newInstance(true);
208 }
209
210 /**
211 * Creates a new {@code Versioning} instance using default values or not.
212 * Equivalent to {@code newBuilder(withDefaults).build()}.
213 *
214 * @param withDefaults the boolean indicating whether default values should be used
215 * @return a new {@code Versioning}
216 */
217 @Nonnull
218 public static Versioning newInstance(boolean withDefaults) {
219 return newBuilder(withDefaults).build();
220 }
221
222 /**
223 * Creates a new {@code Versioning} builder instance.
224 * Equivalent to {@code newBuilder(true)}.
225 * @see #newBuilder(boolean)
226 *
227 * @return a new {@code Builder}
228 */
229 @Nonnull
230 public static Builder newBuilder() {
231 return newBuilder(true);
232 }
233
234 /**
235 * Creates a new {@code Versioning} builder instance using default values or not.
236 *
237 * @param withDefaults the boolean indicating whether default values should be used
238 * @return a new {@code Builder}
239 */
240 @Nonnull
241 public static Builder newBuilder(boolean withDefaults) {
242 return new Builder(withDefaults);
243 }
244
245 /**
246 * Creates a new {@code Versioning} builder instance using the specified object as a basis.
247 * Equivalent to {@code newBuilder(from, false)}.
248 *
249 * @param from the {@code Versioning} instance to use as a basis
250 * @return a new {@code Builder}
251 */
252 @Nonnull
253 public static Builder newBuilder(Versioning from) {
254 return newBuilder(from, false);
255 }
256
257 /**
258 * Creates a new {@code Versioning} builder instance using the specified object as a basis.
259 *
260 * @param from the {@code Versioning} instance to use as a basis
261 * @param forceCopy the boolean indicating if a copy should be forced
262 * @return a new {@code Builder}
263 */
264 @Nonnull
265 public static Builder newBuilder(Versioning from, boolean forceCopy) {
266 return new Builder(from, forceCopy);
267 }
268
269 /**
270 * Builder class used to create Versioning instances.
271 * @see #with()
272 * @see #newBuilder()
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 // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
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 }