1
2
3
4
5 package org.apache.maven.api.model;
6
7 import java.io.Serializable;
8 import java.util.ArrayList;
9 import java.util.Collection;
10 import java.util.Collections;
11 import java.util.HashMap;
12 import java.util.List;
13 import java.util.Map;
14 import org.apache.maven.api.annotations.Experimental;
15 import org.apache.maven.api.annotations.Generated;
16 import org.apache.maven.api.annotations.Immutable;
17 import org.apache.maven.api.annotations.Nonnull;
18 import org.apache.maven.api.annotations.NotThreadSafe;
19 import org.apache.maven.api.annotations.ThreadSafe;
20
21
22
23
24 @Experimental
25 @Generated @ThreadSafe @Immutable
26 public class ModelBase
27 implements Serializable, InputLocationTracker
28 {
29
30
31
32
33
34
35 final List<String> modules;
36
37
38
39
40 final DistributionManagement distributionManagement;
41
42
43
44
45
46 final Map<String, String> properties;
47
48
49
50
51
52
53
54 final DependencyManagement dependencyManagement;
55
56
57
58
59
60
61
62
63
64 final List<Dependency> dependencies;
65
66
67
68
69 final List<Repository> repositories;
70
71
72
73
74 final List<Repository> pluginRepositories;
75
76
77
78
79
80
81 final Reporting reporting;
82
83 final InputLocation location;
84
85 final InputLocation modulesLocation;
86
87 final InputLocation distributionManagementLocation;
88
89 final InputLocation propertiesLocation;
90
91 final InputLocation dependencyManagementLocation;
92
93 final InputLocation dependenciesLocation;
94
95 final InputLocation repositoriesLocation;
96
97 final InputLocation pluginRepositoriesLocation;
98
99 final InputLocation reportingLocation;
100
101 final Map<Object, InputLocation> locations;
102
103
104
105
106
107 ModelBase(
108 Collection<String> modules,
109 DistributionManagement distributionManagement,
110 Map<String, String> properties,
111 DependencyManagement dependencyManagement,
112 Collection<Dependency> dependencies,
113 Collection<Repository> repositories,
114 Collection<Repository> pluginRepositories,
115 Reporting reporting,
116 Map<Object, InputLocation> locations,
117 InputLocation location,
118 InputLocation modulesLocation,
119 InputLocation distributionManagementLocation,
120 InputLocation propertiesLocation,
121 InputLocation dependencyManagementLocation,
122 InputLocation dependenciesLocation,
123 InputLocation repositoriesLocation,
124 InputLocation pluginRepositoriesLocation,
125 InputLocation reportingLocation
126 )
127 {
128 this.modules = ImmutableCollections.copy( modules );
129 this.distributionManagement = distributionManagement;
130 this.properties = ImmutableCollections.copy( properties );
131 this.dependencyManagement = dependencyManagement;
132 this.dependencies = ImmutableCollections.copy( dependencies );
133 this.repositories = ImmutableCollections.copy( repositories );
134 this.pluginRepositories = ImmutableCollections.copy( pluginRepositories );
135 this.reporting = reporting;
136 this.locations = ImmutableCollections.copy( locations );
137 this.location = location;
138 this.modulesLocation = modulesLocation;
139 this.distributionManagementLocation = distributionManagementLocation;
140 this.propertiesLocation = propertiesLocation;
141 this.dependencyManagementLocation = dependencyManagementLocation;
142 this.dependenciesLocation = dependenciesLocation;
143 this.repositoriesLocation = repositoriesLocation;
144 this.pluginRepositoriesLocation = pluginRepositoriesLocation;
145 this.reportingLocation = reportingLocation;
146 }
147
148
149
150
151
152
153
154
155
156 @Nonnull
157 public List<String> getModules()
158 {
159 return this.modules;
160 }
161
162
163
164
165
166
167
168 public DistributionManagement getDistributionManagement()
169 {
170 return this.distributionManagement;
171 }
172
173
174
175
176
177
178
179
180 @Nonnull
181 public Map<String, String> getProperties()
182 {
183 return this.properties;
184 }
185
186
187
188
189
190
191
192
193
194
195 public DependencyManagement getDependencyManagement()
196 {
197 return this.dependencyManagement;
198 }
199
200
201
202
203
204
205
206
207
208
209
210
211 @Nonnull
212 public List<Dependency> getDependencies()
213 {
214 return this.dependencies;
215 }
216
217
218
219
220
221
222
223 @Nonnull
224 public List<Repository> getRepositories()
225 {
226 return this.repositories;
227 }
228
229
230
231
232
233
234
235 @Nonnull
236 public List<Repository> getPluginRepositories()
237 {
238 return this.pluginRepositories;
239 }
240
241
242
243
244
245
246
247
248
249 public Reporting getReporting()
250 {
251 return this.reporting;
252 }
253
254
255
256
257 public InputLocation getLocation( Object key )
258 {
259 if ( key instanceof String )
260 {
261 switch ( ( String ) key )
262 {
263 case "":
264 return location;
265 case "modules":
266 return modulesLocation;
267 case "distributionManagement":
268 return distributionManagementLocation;
269 case "properties":
270 return propertiesLocation;
271 case "dependencyManagement":
272 return dependencyManagementLocation;
273 case "dependencies":
274 return dependenciesLocation;
275 case "repositories":
276 return repositoriesLocation;
277 case "pluginRepositories":
278 return pluginRepositoriesLocation;
279 case "reporting":
280 return reportingLocation;
281 }
282 }
283 return locations != null ? locations.get( key ) : null;
284 }
285
286
287
288
289
290
291 @Nonnull
292 public Builder with()
293 {
294 return newBuilder( this );
295 }
296
297
298
299
300
301
302 @Nonnull
303 public ModelBase withModules( Collection<String> modules )
304 {
305 return with().modules( modules ).build();
306 }
307
308
309
310
311
312
313 @Nonnull
314 public ModelBase withDistributionManagement( DistributionManagement distributionManagement )
315 {
316 return with().distributionManagement( distributionManagement ).build();
317 }
318
319
320
321
322
323
324 @Nonnull
325 public ModelBase withProperties( Map<String, String> properties )
326 {
327 return with().properties( properties ).build();
328 }
329
330
331
332
333
334
335 @Nonnull
336 public ModelBase withDependencyManagement( DependencyManagement dependencyManagement )
337 {
338 return with().dependencyManagement( dependencyManagement ).build();
339 }
340
341
342
343
344
345
346 @Nonnull
347 public ModelBase withDependencies( Collection<Dependency> dependencies )
348 {
349 return with().dependencies( dependencies ).build();
350 }
351
352
353
354
355
356
357 @Nonnull
358 public ModelBase withRepositories( Collection<Repository> repositories )
359 {
360 return with().repositories( repositories ).build();
361 }
362
363
364
365
366
367
368 @Nonnull
369 public ModelBase withPluginRepositories( Collection<Repository> pluginRepositories )
370 {
371 return with().pluginRepositories( pluginRepositories ).build();
372 }
373
374
375
376
377
378
379 @Nonnull
380 public ModelBase withReporting( Reporting reporting )
381 {
382 return with().reporting( reporting ).build();
383 }
384
385
386
387
388
389
390
391
392 @Nonnull
393 public static ModelBase newInstance()
394 {
395 return newInstance( true );
396 }
397
398
399
400
401
402
403
404
405 @Nonnull
406 public static ModelBase newInstance( boolean withDefaults )
407 {
408 return newBuilder( withDefaults ).build();
409 }
410
411
412
413
414
415
416
417
418 @Nonnull
419 public static Builder newBuilder()
420 {
421 return newBuilder( true );
422 }
423
424
425
426
427
428
429
430 @Nonnull
431 public static Builder newBuilder( boolean withDefaults )
432 {
433 return new Builder( withDefaults );
434 }
435
436
437
438
439
440
441
442
443 @Nonnull
444 public static Builder newBuilder( ModelBase from )
445 {
446 return newBuilder( from, false );
447 }
448
449
450
451
452
453
454
455
456 @Nonnull
457 public static Builder newBuilder( ModelBase from, boolean forceCopy )
458 {
459 return new Builder( from, forceCopy );
460 }
461
462
463
464
465
466
467 @NotThreadSafe
468 public static class Builder
469 {
470 ModelBase base;
471 Collection<String> modules;
472 DistributionManagement distributionManagement;
473 Map<String, String> properties;
474 DependencyManagement dependencyManagement;
475 Collection<Dependency> dependencies;
476 Collection<Repository> repositories;
477 Collection<Repository> pluginRepositories;
478 Reporting reporting;
479 Map<Object, InputLocation> locations;
480
481 Builder( boolean withDefaults )
482 {
483 if ( withDefaults )
484 {
485 }
486 }
487
488 Builder( ModelBase base, boolean forceCopy )
489 {
490 if ( forceCopy )
491 {
492 this.modules = base.modules;
493 this.distributionManagement = base.distributionManagement;
494 this.properties = base.properties;
495 this.dependencyManagement = base.dependencyManagement;
496 this.dependencies = base.dependencies;
497 this.repositories = base.repositories;
498 this.pluginRepositories = base.pluginRepositories;
499 this.reporting = base.reporting;
500 }
501 else
502 {
503 this.base = base;
504 }
505 }
506
507 @Nonnull
508 public Builder modules( Collection<String> modules )
509 {
510 this.modules = modules;
511 return this;
512 }
513
514 @Nonnull
515 public Builder distributionManagement( DistributionManagement distributionManagement )
516 {
517 this.distributionManagement = distributionManagement;
518 return this;
519 }
520
521 @Nonnull
522 public Builder properties( Map<String, String> properties )
523 {
524 this.properties = properties;
525 return this;
526 }
527
528 @Nonnull
529 public Builder dependencyManagement( DependencyManagement dependencyManagement )
530 {
531 this.dependencyManagement = dependencyManagement;
532 return this;
533 }
534
535 @Nonnull
536 public Builder dependencies( Collection<Dependency> dependencies )
537 {
538 this.dependencies = dependencies;
539 return this;
540 }
541
542 @Nonnull
543 public Builder repositories( Collection<Repository> repositories )
544 {
545 this.repositories = repositories;
546 return this;
547 }
548
549 @Nonnull
550 public Builder pluginRepositories( Collection<Repository> pluginRepositories )
551 {
552 this.pluginRepositories = pluginRepositories;
553 return this;
554 }
555
556 @Nonnull
557 public Builder reporting( Reporting reporting )
558 {
559 this.reporting = reporting;
560 return this;
561 }
562
563
564 @Nonnull
565 public Builder location( Object key, InputLocation location )
566 {
567 if ( location != null )
568 {
569 if ( this.locations == null )
570 {
571 this.locations = new HashMap<>();
572 }
573 this.locations.put( key, location );
574 }
575 return this;
576 }
577
578 @Nonnull
579 public ModelBase build()
580 {
581 if ( base != null
582 && ( modules == null || modules == base.modules )
583 && ( distributionManagement == null || distributionManagement == base.distributionManagement )
584 && ( properties == null || properties == base.properties )
585 && ( dependencyManagement == null || dependencyManagement == base.dependencyManagement )
586 && ( dependencies == null || dependencies == base.dependencies )
587 && ( repositories == null || repositories == base.repositories )
588 && ( pluginRepositories == null || pluginRepositories == base.pluginRepositories )
589 && ( reporting == null || reporting == base.reporting )
590 )
591 {
592 return base;
593 }
594 Map<Object, InputLocation> locations = null;
595 InputLocation location = null;
596 InputLocation modulesLocation = null;
597 InputLocation distributionManagementLocation = null;
598 InputLocation propertiesLocation = null;
599 InputLocation dependencyManagementLocation = null;
600 InputLocation dependenciesLocation = null;
601 InputLocation repositoriesLocation = null;
602 InputLocation pluginRepositoriesLocation = null;
603 InputLocation reportingLocation = null;
604 if ( this.locations != null )
605 {
606 locations = this.locations;
607 location = locations.remove( "" );
608 modulesLocation = locations.remove( "modules" );
609 distributionManagementLocation = locations.remove( "distributionManagement" );
610 propertiesLocation = locations.remove( "properties" );
611 dependencyManagementLocation = locations.remove( "dependencyManagement" );
612 dependenciesLocation = locations.remove( "dependencies" );
613 repositoriesLocation = locations.remove( "repositories" );
614 pluginRepositoriesLocation = locations.remove( "pluginRepositories" );
615 reportingLocation = locations.remove( "reporting" );
616 }
617 return new ModelBase(
618 modules != null ? modules : ( base != null ? base.modules : null ),
619 distributionManagement != null ? distributionManagement : ( base != null ? base.distributionManagement : null ),
620 properties != null ? properties : ( base != null ? base.properties : null ),
621 dependencyManagement != null ? dependencyManagement : ( base != null ? base.dependencyManagement : null ),
622 dependencies != null ? dependencies : ( base != null ? base.dependencies : null ),
623 repositories != null ? repositories : ( base != null ? base.repositories : null ),
624 pluginRepositories != null ? pluginRepositories : ( base != null ? base.pluginRepositories : null ),
625 reporting != null ? reporting : ( base != null ? base.reporting : null ),
626 locations != null ? locations : ( base != null ? base.locations : null ),
627 location != null ? location : ( base != null ? base.location : null ),
628 modulesLocation != null ? modulesLocation : ( base != null ? base.modulesLocation : null ),
629 distributionManagementLocation != null ? distributionManagementLocation : ( base != null ? base.distributionManagementLocation : null ),
630 propertiesLocation != null ? propertiesLocation : ( base != null ? base.propertiesLocation : null ),
631 dependencyManagementLocation != null ? dependencyManagementLocation : ( base != null ? base.dependencyManagementLocation : null ),
632 dependenciesLocation != null ? dependenciesLocation : ( base != null ? base.dependenciesLocation : null ),
633 repositoriesLocation != null ? repositoriesLocation : ( base != null ? base.repositoriesLocation : null ),
634 pluginRepositoriesLocation != null ? pluginRepositoriesLocation : ( base != null ? base.pluginRepositoriesLocation : null ),
635 reportingLocation != null ? reportingLocation : ( base != null ? base.reportingLocation : null )
636 );
637 }
638 }
639
640 }