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 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 Map<Object, InputLocation> locations;
83
84
85
86
87
88 ModelBase(
89 Collection<String> modules,
90 DistributionManagement distributionManagement,
91 Map<String, String> properties,
92 DependencyManagement dependencyManagement,
93 Collection<Dependency> dependencies,
94 Collection<Repository> repositories,
95 Collection<Repository> pluginRepositories,
96 Reporting reporting,
97 Map<Object, InputLocation> locations
98 ) {
99 this.modules = ImmutableCollections.copy(modules);
100 this.distributionManagement = distributionManagement;
101 this.properties = ImmutableCollections.copy(properties);
102 this.dependencyManagement = dependencyManagement;
103 this.dependencies = ImmutableCollections.copy(dependencies);
104 this.repositories = ImmutableCollections.copy(repositories);
105 this.pluginRepositories = ImmutableCollections.copy(pluginRepositories);
106 this.reporting = reporting;
107 this.locations = ImmutableCollections.copy(locations);
108 }
109
110
111
112
113
114
115
116
117
118 @Nonnull
119 public List<String> getModules() {
120 return this.modules;
121 }
122
123
124
125
126
127
128
129 public DistributionManagement getDistributionManagement() {
130 return this.distributionManagement;
131 }
132
133
134
135
136
137
138
139
140 @Nonnull
141 public Map<String, String> getProperties() {
142 return this.properties;
143 }
144
145
146
147
148
149
150
151
152
153
154 public DependencyManagement getDependencyManagement() {
155 return this.dependencyManagement;
156 }
157
158
159
160
161
162
163
164
165
166
167
168 @Nonnull
169 public List<Dependency> getDependencies() {
170 return this.dependencies;
171 }
172
173
174
175
176
177
178
179 @Nonnull
180 public List<Repository> getRepositories() {
181 return this.repositories;
182 }
183
184
185
186
187
188
189
190 @Nonnull
191 public List<Repository> getPluginRepositories() {
192 return this.pluginRepositories;
193 }
194
195
196
197
198
199
200
201
202
203 public Reporting getReporting() {
204 return this.reporting;
205 }
206
207
208
209
210 public InputLocation getLocation(Object key) {
211 return locations != null ? locations.get(key) : null;
212 }
213
214
215
216
217
218
219 @Nonnull
220 public Builder with() {
221 return newBuilder(this);
222 }
223
224
225
226
227
228
229 @Nonnull
230 public ModelBase withModules(Collection<String> modules) {
231 return newBuilder(this, true).modules(modules).build();
232 }
233
234
235
236
237
238
239 @Nonnull
240 public ModelBase withDistributionManagement(DistributionManagement distributionManagement) {
241 return newBuilder(this, true).distributionManagement(distributionManagement).build();
242 }
243
244
245
246
247
248
249 @Nonnull
250 public ModelBase withProperties(Map<String, String> properties) {
251 return newBuilder(this, true).properties(properties).build();
252 }
253
254
255
256
257
258
259 @Nonnull
260 public ModelBase withDependencyManagement(DependencyManagement dependencyManagement) {
261 return newBuilder(this, true).dependencyManagement(dependencyManagement).build();
262 }
263
264
265
266
267
268
269 @Nonnull
270 public ModelBase withDependencies(Collection<Dependency> dependencies) {
271 return newBuilder(this, true).dependencies(dependencies).build();
272 }
273
274
275
276
277
278
279 @Nonnull
280 public ModelBase withRepositories(Collection<Repository> repositories) {
281 return newBuilder(this, true).repositories(repositories).build();
282 }
283
284
285
286
287
288
289 @Nonnull
290 public ModelBase withPluginRepositories(Collection<Repository> pluginRepositories) {
291 return newBuilder(this, true).pluginRepositories(pluginRepositories).build();
292 }
293
294
295
296
297
298
299 @Nonnull
300 public ModelBase withReporting(Reporting reporting) {
301 return newBuilder(this, true).reporting(reporting).build();
302 }
303
304
305
306
307
308
309
310
311 @Nonnull
312 public static ModelBase newInstance() {
313 return newInstance(true);
314 }
315
316
317
318
319
320
321
322
323 @Nonnull
324 public static ModelBase newInstance(boolean withDefaults) {
325 return newBuilder(withDefaults).build();
326 }
327
328
329
330
331
332
333
334
335 @Nonnull
336 public static Builder newBuilder() {
337 return newBuilder(true);
338 }
339
340
341
342
343
344
345
346 @Nonnull
347 public static Builder newBuilder(boolean withDefaults) {
348 return new Builder(withDefaults);
349 }
350
351
352
353
354
355
356
357
358 @Nonnull
359 public static Builder newBuilder(ModelBase from) {
360 return newBuilder(from, false);
361 }
362
363
364
365
366
367
368
369
370 @Nonnull
371 public static Builder newBuilder(ModelBase from, boolean forceCopy) {
372 return new Builder(from, forceCopy);
373 }
374
375
376
377
378
379
380 @NotThreadSafe
381 public static class Builder
382 {
383 ModelBase base;
384 Collection<String> modules;
385 DistributionManagement distributionManagement;
386 Map<String, String> properties;
387 DependencyManagement dependencyManagement;
388 Collection<Dependency> dependencies;
389 Collection<Repository> repositories;
390 Collection<Repository> pluginRepositories;
391 Reporting reporting;
392 Map<Object, InputLocation> locations;
393
394 Builder(boolean withDefaults) {
395 if (withDefaults) {
396 }
397 }
398
399 Builder(ModelBase base, boolean forceCopy) {
400 if (forceCopy) {
401 this.modules = base.modules;
402 this.distributionManagement = base.distributionManagement;
403 this.properties = base.properties;
404 this.dependencyManagement = base.dependencyManagement;
405 this.dependencies = base.dependencies;
406 this.repositories = base.repositories;
407 this.pluginRepositories = base.pluginRepositories;
408 this.reporting = base.reporting;
409 this.locations = base.locations;
410 } else {
411 this.base = base;
412 }
413 }
414
415 @Nonnull
416 public Builder modules(Collection<String> modules) {
417 this.modules = modules;
418 return this;
419 }
420
421 @Nonnull
422 public Builder distributionManagement(DistributionManagement distributionManagement) {
423 this.distributionManagement = distributionManagement;
424 return this;
425 }
426
427 @Nonnull
428 public Builder properties(Map<String, String> properties) {
429 this.properties = properties;
430 return this;
431 }
432
433 @Nonnull
434 public Builder dependencyManagement(DependencyManagement dependencyManagement) {
435 this.dependencyManagement = dependencyManagement;
436 return this;
437 }
438
439 @Nonnull
440 public Builder dependencies(Collection<Dependency> dependencies) {
441 this.dependencies = dependencies;
442 return this;
443 }
444
445 @Nonnull
446 public Builder repositories(Collection<Repository> repositories) {
447 this.repositories = repositories;
448 return this;
449 }
450
451 @Nonnull
452 public Builder pluginRepositories(Collection<Repository> pluginRepositories) {
453 this.pluginRepositories = pluginRepositories;
454 return this;
455 }
456
457 @Nonnull
458 public Builder reporting(Reporting reporting) {
459 this.reporting = reporting;
460 return this;
461 }
462
463
464 @Nonnull
465 public Builder location(Object key, InputLocation location) {
466 if (location != null) {
467 if (!(this.locations instanceof HashMap)) {
468 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
469 }
470 this.locations.put(key, location);
471 }
472 return this;
473 }
474
475 @Nonnull
476 public ModelBase build() {
477 if (base != null
478 && (modules == null || modules == base.modules)
479 && (distributionManagement == null || distributionManagement == base.distributionManagement)
480 && (properties == null || properties == base.properties)
481 && (dependencyManagement == null || dependencyManagement == base.dependencyManagement)
482 && (dependencies == null || dependencies == base.dependencies)
483 && (repositories == null || repositories == base.repositories)
484 && (pluginRepositories == null || pluginRepositories == base.pluginRepositories)
485 && (reporting == null || reporting == base.reporting)
486 ) {
487 return base;
488 }
489 Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
490 Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
491 Map<Object, InputLocation> locations = new HashMap<>();
492 locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
493 locations.put("modules", newlocs.containsKey("modules") ? newlocs.get("modules") : oldlocs.get("modules"));
494 locations.put("distributionManagement", newlocs.containsKey("distributionManagement") ? newlocs.get("distributionManagement") : oldlocs.get("distributionManagement"));
495 locations.put("properties", newlocs.containsKey("properties") ? newlocs.get("properties") : oldlocs.get("properties"));
496 locations.put("dependencyManagement", newlocs.containsKey("dependencyManagement") ? newlocs.get("dependencyManagement") : oldlocs.get("dependencyManagement"));
497 locations.put("dependencies", newlocs.containsKey("dependencies") ? newlocs.get("dependencies") : oldlocs.get("dependencies"));
498 locations.put("repositories", newlocs.containsKey("repositories") ? newlocs.get("repositories") : oldlocs.get("repositories"));
499 locations.put("pluginRepositories", newlocs.containsKey("pluginRepositories") ? newlocs.get("pluginRepositories") : oldlocs.get("pluginRepositories"));
500 locations.put("reporting", newlocs.containsKey("reporting") ? newlocs.get("reporting") : oldlocs.get("reporting"));
501 return new ModelBase(
502 modules != null ? modules : (base != null ? base.modules : null),
503 distributionManagement != null ? distributionManagement : (base != null ? base.distributionManagement : null),
504 properties != null ? properties : (base != null ? base.properties : null),
505 dependencyManagement != null ? dependencyManagement : (base != null ? base.dependencyManagement : null),
506 dependencies != null ? dependencies : (base != null ? base.dependencies : null),
507 repositories != null ? repositories : (base != null ? base.repositories : null),
508 pluginRepositories != null ? pluginRepositories : (base != null ? base.pluginRepositories : null),
509 reporting != null ? reporting : (base != null ? base.reporting : null),
510 locations
511 );
512 }
513 }
514
515 }