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