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