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