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 final InputLocation releasesLocation;
39
40 final InputLocation snapshotsLocation;
41
42
43
44
45
46 Repository(
47 String id,
48 String name,
49 String url,
50 String layout,
51 RepositoryPolicy releases,
52 RepositoryPolicy snapshots,
53 Map<Object, InputLocation> locations,
54 InputLocation location,
55 InputLocation idLocation,
56 InputLocation nameLocation,
57 InputLocation urlLocation,
58 InputLocation layoutLocation,
59 InputLocation releasesLocation,
60 InputLocation snapshotsLocation
61 )
62 {
63 super(
64 id,
65 name,
66 url,
67 layout,
68 locations,
69 location,
70 idLocation,
71 nameLocation,
72 urlLocation,
73 layoutLocation
74 );
75 this.releases = releases;
76 this.snapshots = snapshots;
77 this.releasesLocation = releasesLocation;
78 this.snapshotsLocation = snapshotsLocation;
79 }
80
81 @Override
82 public boolean equals( Object o )
83 {
84 if ( this == o )
85 {
86 return true;
87 }
88 if ( o == null || !( o instanceof Repository ) )
89 {
90 return false;
91 }
92 Repository that = ( Repository ) o;
93 return Objects.equals( this.id, that.id );
94 }
95
96 @Override
97 public int hashCode()
98 {
99 return Objects.hash( id );
100 }
101
102
103
104
105
106
107 public RepositoryPolicy getReleases()
108 {
109 return this.releases;
110 }
111
112
113
114
115
116
117 public RepositoryPolicy getSnapshots()
118 {
119 return this.snapshots;
120 }
121
122
123
124
125 public InputLocation getLocation( Object key )
126 {
127 if ( key instanceof String )
128 {
129 switch ( ( String ) key )
130 {
131 case "releases":
132 return releasesLocation;
133 case "snapshots":
134 return snapshotsLocation;
135 }
136 }
137 return super.getLocation( key );
138 }
139
140
141
142
143
144
145 @Nonnull
146 public Builder with()
147 {
148 return newBuilder( this );
149 }
150
151
152
153
154
155
156 @Nonnull
157 public Repository withId( String id )
158 {
159 return with().id( id ).build();
160 }
161
162
163
164
165
166
167 @Nonnull
168 public Repository withName( String name )
169 {
170 return with().name( name ).build();
171 }
172
173
174
175
176
177
178 @Nonnull
179 public Repository withUrl( String url )
180 {
181 return with().url( url ).build();
182 }
183
184
185
186
187
188
189 @Nonnull
190 public Repository withLayout( String layout )
191 {
192 return with().layout( layout ).build();
193 }
194
195
196
197
198
199
200 @Nonnull
201 public Repository withReleases( RepositoryPolicy releases )
202 {
203 return with().releases( releases ).build();
204 }
205
206
207
208
209
210
211 @Nonnull
212 public Repository withSnapshots( RepositoryPolicy snapshots )
213 {
214 return with().snapshots( snapshots ).build();
215 }
216
217
218
219
220
221
222
223
224 @Nonnull
225 public static Repository newInstance()
226 {
227 return newInstance( true );
228 }
229
230
231
232
233
234
235
236
237 @Nonnull
238 public static Repository newInstance( boolean withDefaults )
239 {
240 return newBuilder( withDefaults ).build();
241 }
242
243
244
245
246
247
248
249
250 @Nonnull
251 public static Builder newBuilder()
252 {
253 return newBuilder( true );
254 }
255
256
257
258
259
260
261
262 @Nonnull
263 public static Builder newBuilder( boolean withDefaults )
264 {
265 return new Builder( withDefaults );
266 }
267
268
269
270
271
272
273
274
275 @Nonnull
276 public static Builder newBuilder( Repository from )
277 {
278 return newBuilder( from, false );
279 }
280
281
282
283
284
285
286
287
288 @Nonnull
289 public static Builder newBuilder( Repository from, boolean forceCopy )
290 {
291 return new Builder( from, forceCopy );
292 }
293
294
295
296
297
298
299 @NotThreadSafe
300 public static class Builder
301 extends RepositoryBase.Builder
302 {
303 Repository base;
304 RepositoryPolicy releases;
305 RepositoryPolicy snapshots;
306
307 Builder( boolean withDefaults )
308 {
309 super( withDefaults );
310 if ( withDefaults )
311 {
312 }
313 }
314
315 Builder( Repository base, boolean forceCopy )
316 {
317 super( base, forceCopy );
318 if ( forceCopy )
319 {
320 this.releases = base.releases;
321 this.snapshots = base.snapshots;
322 }
323 else
324 {
325 this.base = base;
326 }
327 }
328
329 @Nonnull
330 public Builder id( String id )
331 {
332 this.id = id;
333 return this;
334 }
335
336 @Nonnull
337 public Builder name( String name )
338 {
339 this.name = name;
340 return this;
341 }
342
343 @Nonnull
344 public Builder url( String url )
345 {
346 this.url = url;
347 return this;
348 }
349
350 @Nonnull
351 public Builder layout( String layout )
352 {
353 this.layout = layout;
354 return this;
355 }
356
357 @Nonnull
358 public Builder releases( RepositoryPolicy releases )
359 {
360 this.releases = releases;
361 return this;
362 }
363
364 @Nonnull
365 public Builder snapshots( RepositoryPolicy snapshots )
366 {
367 this.snapshots = snapshots;
368 return this;
369 }
370
371
372 @Nonnull
373 public Builder location( Object key, InputLocation location )
374 {
375 if ( location != null )
376 {
377 if ( this.locations == null )
378 {
379 this.locations = new HashMap<>();
380 }
381 this.locations.put( key, location );
382 }
383 return this;
384 }
385
386 @Nonnull
387 public Repository build()
388 {
389 if ( base != null
390 && ( id == null || id == base.id )
391 && ( name == null || name == base.name )
392 && ( url == null || url == base.url )
393 && ( layout == null || layout == base.layout )
394 && ( releases == null || releases == base.releases )
395 && ( snapshots == null || snapshots == base.snapshots )
396 )
397 {
398 return base;
399 }
400 Map<Object, InputLocation> locations = null;
401 InputLocation location = null;
402 InputLocation idLocation = null;
403 InputLocation nameLocation = null;
404 InputLocation urlLocation = null;
405 InputLocation layoutLocation = null;
406 InputLocation releasesLocation = null;
407 InputLocation snapshotsLocation = null;
408 if ( this.locations != null )
409 {
410 locations = this.locations;
411 location = locations.remove( "" );
412 idLocation = locations.remove( "id" );
413 nameLocation = locations.remove( "name" );
414 urlLocation = locations.remove( "url" );
415 layoutLocation = locations.remove( "layout" );
416 releasesLocation = locations.remove( "releases" );
417 snapshotsLocation = locations.remove( "snapshots" );
418 }
419 return new Repository(
420 id != null ? id : ( base != null ? base.id : null ),
421 name != null ? name : ( base != null ? base.name : null ),
422 url != null ? url : ( base != null ? base.url : null ),
423 layout != null ? layout : ( base != null ? base.layout : null ),
424 releases != null ? releases : ( base != null ? base.releases : null ),
425 snapshots != null ? snapshots : ( base != null ? base.snapshots : null ),
426 locations != null ? locations : ( base != null ? base.locations : null ),
427 location != null ? location : ( base != null ? base.location : null ),
428 idLocation != null ? idLocation : ( base != null ? base.idLocation : null ),
429 nameLocation != null ? nameLocation : ( base != null ? base.nameLocation : null ),
430 urlLocation != null ? urlLocation : ( base != null ? base.urlLocation : null ),
431 layoutLocation != null ? layoutLocation : ( base != null ? base.layoutLocation : null ),
432 releasesLocation != null ? releasesLocation : ( base != null ? base.releasesLocation : null ),
433 snapshotsLocation != null ? snapshotsLocation : ( base != null ? base.snapshotsLocation : null )
434 );
435 }
436 }
437
438 }