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