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