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