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