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