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