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 BuildBase
28 extends PluginConfiguration
29 implements Serializable, InputLocationTracker
30 {
31
32
33
34
35
36
37 final String defaultGoal;
38
39
40
41
42
43
44 final List<Resource> resources;
45
46
47
48
49
50 final List<Resource> testResources;
51
52
53
54
55 final String directory;
56
57
58
59
60
61 final String finalName;
62
63
64
65 final List<String> filters;
66
67 final Map<Object, InputLocation> locations;
68
69
70
71
72
73 protected BuildBase(Builder builder) {
74 super(builder);
75 this.defaultGoal = builder.defaultGoal != null ? builder.defaultGoal : (builder.base != null ? builder.base.defaultGoal : null);
76 this.resources = ImmutableCollections.copy(builder.resources != null ? builder.resources : (builder.base != null ? builder.base.resources : null));
77 this.testResources = ImmutableCollections.copy(builder.testResources != null ? builder.testResources : (builder.base != null ? builder.base.testResources : null));
78 this.directory = builder.directory != null ? builder.directory : (builder.base != null ? builder.base.directory : null);
79 this.finalName = builder.finalName != null ? builder.finalName : (builder.base != null ? builder.base.finalName : null);
80 this.filters = ImmutableCollections.copy(builder.filters != null ? builder.filters : (builder.base != null ? builder.base.filters : null));
81 Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
82 Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
83 Map<Object, InputLocation> mutableLocations = new HashMap<>(super.locations);
84 mutableLocations.put("defaultGoal", newlocs.containsKey("defaultGoal") ? newlocs.get("defaultGoal") : oldlocs.get("defaultGoal"));
85 mutableLocations.put("resources", newlocs.containsKey("resources") ? newlocs.get("resources") : oldlocs.get("resources"));
86 mutableLocations.put("testResources", newlocs.containsKey("testResources") ? newlocs.get("testResources") : oldlocs.get("testResources"));
87 mutableLocations.put("directory", newlocs.containsKey("directory") ? newlocs.get("directory") : oldlocs.get("directory"));
88 mutableLocations.put("finalName", newlocs.containsKey("finalName") ? newlocs.get("finalName") : oldlocs.get("finalName"));
89 mutableLocations.put("filters", newlocs.containsKey("filters") ? newlocs.get("filters") : oldlocs.get("filters"));
90 this.locations = Collections.unmodifiableMap(mutableLocations);
91 }
92
93
94
95
96
97
98
99
100
101 public String getDefaultGoal() {
102 return this.defaultGoal;
103 }
104
105
106
107
108
109
110
111
112
113 @Nonnull
114 public List<Resource> getResources() {
115 return this.resources;
116 }
117
118
119
120
121
122
123
124
125 @Nonnull
126 public List<Resource> getTestResources() {
127 return this.testResources;
128 }
129
130
131
132
133
134
135
136 public String getDirectory() {
137 return this.directory;
138 }
139
140
141
142
143
144
145
146
147 public String getFinalName() {
148 return this.finalName;
149 }
150
151
152
153
154
155
156 @Nonnull
157 public List<String> getFilters() {
158 return this.filters;
159 }
160
161
162
163
164 public InputLocation getLocation(Object key) {
165 return locations != null ? locations.get(key) : null;
166 }
167
168
169
170
171 public Set<Object> getLocationKeys() {
172 return locations != null ? locations.keySet() : null;
173 }
174
175
176
177
178
179
180 @Nonnull
181 public Builder with() {
182 return newBuilder(this);
183 }
184
185
186
187
188
189
190 @Nonnull
191 public BuildBase withPlugins(Collection<Plugin> plugins) {
192 return newBuilder(this, true).plugins(plugins).build();
193 }
194
195
196
197
198
199
200 @Nonnull
201 public BuildBase withPluginManagement(PluginManagement pluginManagement) {
202 return newBuilder(this, true).pluginManagement(pluginManagement).build();
203 }
204
205
206
207
208
209
210 @Nonnull
211 public BuildBase withDefaultGoal(String defaultGoal) {
212 return newBuilder(this, true).defaultGoal(defaultGoal).build();
213 }
214
215
216
217
218
219
220 @Nonnull
221 public BuildBase withResources(Collection<Resource> resources) {
222 return newBuilder(this, true).resources(resources).build();
223 }
224
225
226
227
228
229
230 @Nonnull
231 public BuildBase withTestResources(Collection<Resource> testResources) {
232 return newBuilder(this, true).testResources(testResources).build();
233 }
234
235
236
237
238
239
240 @Nonnull
241 public BuildBase withDirectory(String directory) {
242 return newBuilder(this, true).directory(directory).build();
243 }
244
245
246
247
248
249
250 @Nonnull
251 public BuildBase withFinalName(String finalName) {
252 return newBuilder(this, true).finalName(finalName).build();
253 }
254
255
256
257
258
259
260 @Nonnull
261 public BuildBase withFilters(Collection<String> filters) {
262 return newBuilder(this, true).filters(filters).build();
263 }
264
265
266
267
268
269
270
271
272 @Nonnull
273 public static BuildBase newInstance() {
274 return newInstance(true);
275 }
276
277
278
279
280
281
282
283
284 @Nonnull
285 public static BuildBase newInstance(boolean withDefaults) {
286 return newBuilder(withDefaults).build();
287 }
288
289
290
291
292
293
294
295
296 @Nonnull
297 public static Builder newBuilder() {
298 return newBuilder(true);
299 }
300
301
302
303
304
305
306
307 @Nonnull
308 public static Builder newBuilder(boolean withDefaults) {
309 return new Builder(withDefaults);
310 }
311
312
313
314
315
316
317
318
319 @Nonnull
320 public static Builder newBuilder(BuildBase from) {
321 return newBuilder(from, false);
322 }
323
324
325
326
327
328
329
330
331 @Nonnull
332 public static Builder newBuilder(BuildBase from, boolean forceCopy) {
333 return new Builder(from, forceCopy);
334 }
335
336
337
338
339
340
341 @NotThreadSafe
342 public static class Builder
343 extends PluginConfiguration.Builder
344 {
345 BuildBase base;
346 String defaultGoal;
347 Collection<Resource> resources;
348 Collection<Resource> testResources;
349 String directory;
350 String finalName;
351 Collection<String> filters;
352
353 protected Builder(boolean withDefaults) {
354 super(withDefaults);
355 if (withDefaults) {
356 }
357 }
358
359 protected Builder(BuildBase base, boolean forceCopy) {
360 super(base, forceCopy);
361 if (forceCopy) {
362 this.defaultGoal = base.defaultGoal;
363 this.resources = base.resources;
364 this.testResources = base.testResources;
365 this.directory = base.directory;
366 this.finalName = base.finalName;
367 this.filters = base.filters;
368 this.locations = base.locations;
369 this.importedFrom = base.importedFrom;
370 } else {
371 this.base = base;
372 }
373 }
374
375 @Nonnull
376 public Builder plugins(Collection<Plugin> plugins) {
377 this.plugins = plugins;
378 return this;
379 }
380
381 @Nonnull
382 public Builder pluginManagement(PluginManagement pluginManagement) {
383 this.pluginManagement = pluginManagement;
384 return this;
385 }
386
387 @Nonnull
388 public Builder defaultGoal(String defaultGoal) {
389 this.defaultGoal = defaultGoal;
390 return this;
391 }
392
393 @Nonnull
394 public Builder resources(Collection<Resource> resources) {
395 this.resources = resources;
396 return this;
397 }
398
399 @Nonnull
400 public Builder testResources(Collection<Resource> testResources) {
401 this.testResources = testResources;
402 return this;
403 }
404
405 @Nonnull
406 public Builder directory(String directory) {
407 this.directory = directory;
408 return this;
409 }
410
411 @Nonnull
412 public Builder finalName(String finalName) {
413 this.finalName = finalName;
414 return this;
415 }
416
417 @Nonnull
418 public Builder filters(Collection<String> filters) {
419 this.filters = filters;
420 return this;
421 }
422
423
424 @Nonnull
425 public Builder location(Object key, InputLocation location) {
426 if (location != null) {
427 if (!(this.locations instanceof HashMap)) {
428 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
429 }
430 this.locations.put(key, location);
431 }
432 return this;
433 }
434
435 @Nonnull
436 public Builder importedFrom(InputLocation importedFrom) {
437 this.importedFrom = importedFrom;
438 return this;
439 }
440
441 @Nonnull
442 public BuildBase build() {
443
444 if (base != null
445 && (plugins == null || plugins == base.plugins)
446 && (pluginManagement == null || pluginManagement == base.pluginManagement)
447 && (defaultGoal == null || defaultGoal == base.defaultGoal)
448 && (resources == null || resources == base.resources)
449 && (testResources == null || testResources == base.testResources)
450 && (directory == null || directory == base.directory)
451 && (finalName == null || finalName == base.finalName)
452 && (filters == null || filters == base.filters)
453 ) {
454 return base;
455 }
456 return new BuildBase(this);
457 }
458 }
459
460
461
462
463
464
465 public String toString()
466 {
467 return "BuildBase {" + super.toString() + "}";
468 }
469
470
471 }