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