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