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