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