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