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