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