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