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.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   * The {@code <build>} element contains information required to build the project.
24   * Default values are defined in Super POM.
25   */
26  @Experimental
27  @Generated @ThreadSafe @Immutable
28  public class Build
29      extends BuildBase
30      implements Serializable, InputLocationTracker
31  {
32      /**
33       * This element specifies a directory containing the source of the project. The
34       * generated build system will compile the sources from this directory when the project is
35       * built. The path given is relative to the project descriptor.
36       * The default value is {@code src/main/java}.
37       */
38      final String sourceDirectory;
39      /**
40       * This element specifies a directory containing the script sources of the
41       * project. This directory is meant to be different from the sourceDirectory, in that its
42       * contents will be copied to the output directory in most cases (since scripts are
43       * interpreted rather than compiled).
44       * The default value is {@code src/main/scripts}.
45       */
46      final String scriptSourceDirectory;
47      /**
48       * This element specifies a directory containing the unit test source of the
49       * project. The generated build system will compile these directories when the project is
50       * being tested. The path given is relative to the project descriptor.
51       * The default value is {@code src/test/java}.
52       */
53      final String testSourceDirectory;
54      /**
55       * The directory where compiled application classes are placed.
56       * The default value is {@code target/classes}.
57       */
58      final String outputDirectory;
59      /**
60       * The directory where compiled test classes are placed.
61       * The default value is {@code target/test-classes}.
62       */
63      final String testOutputDirectory;
64      /**
65       * A set of build extensions to use from this project.
66       */
67      final List<Extension> extensions;
68      /** Locations (this potentially hides the same name field from the super class) */
69      final Map<Object, InputLocation> locations;
70  
71      /**
72        * Constructor for this class, to be called from its subclasses and {@link Builder}.
73        * @see Builder#build()
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       * This element specifies a directory containing the source of the project. The
97       * generated build system will compile the sources from this directory when the project is
98       * built. The path given is relative to the project descriptor.
99       * The default value is {@code src/main/java}.
100      *
101      * @return a {@code String}
102      */
103     public String getSourceDirectory() {
104         return this.sourceDirectory;
105     }
106 
107     /**
108      * This element specifies a directory containing the script sources of the
109      * project. This directory is meant to be different from the sourceDirectory, in that its
110      * contents will be copied to the output directory in most cases (since scripts are
111      * interpreted rather than compiled).
112      * The default value is {@code src/main/scripts}.
113      *
114      * @return a {@code String}
115      */
116     public String getScriptSourceDirectory() {
117         return this.scriptSourceDirectory;
118     }
119 
120     /**
121      * This element specifies a directory containing the unit test source of the
122      * project. The generated build system will compile these directories when the project is
123      * being tested. The path given is relative to the project descriptor.
124      * The default value is {@code src/test/java}.
125      *
126      * @return a {@code String}
127      */
128     public String getTestSourceDirectory() {
129         return this.testSourceDirectory;
130     }
131 
132     /**
133      * The directory where compiled application classes are placed.
134      * The default value is {@code target/classes}.
135      *
136      * @return a {@code String}
137      */
138     public String getOutputDirectory() {
139         return this.outputDirectory;
140     }
141 
142     /**
143      * The directory where compiled test classes are placed.
144      * The default value is {@code target/test-classes}.
145      *
146      * @return a {@code String}
147      */
148     public String getTestOutputDirectory() {
149         return this.testOutputDirectory;
150     }
151 
152     /**
153      * A set of build extensions to use from this project.
154      *
155      * @return a {@code List<Extension>}
156      */
157     @Nonnull
158     public List<Extension> getExtensions() {
159         return this.extensions;
160     }
161 
162     /**
163      * Gets the location of the specified field in the input source.
164      */
165     public InputLocation getLocation(Object key) {
166         return locations != null ? locations.get(key) : null;
167     }
168 
169     /**
170     * Gets the keys of the locations of the input source.
171     */
172     public Set<Object> getLocationKeys() {
173         return locations != null ? locations.keySet() : null;
174     }
175 
176     /**
177      * Creates a new builder with this object as the basis.
178      *
179      * @return a {@code Builder}
180      */
181     @Nonnull
182     public Builder with() {
183         return newBuilder(this);
184     }
185     /**
186      * Creates a new {@code Build} instance using the specified plugins.
187      *
188      * @param plugins the new {@code Collection<Plugin>} to use
189      * @return a {@code Build} with the specified plugins
190      */
191     @Nonnull
192     public Build withPlugins(Collection<Plugin> plugins) {
193         return newBuilder(this, true).plugins(plugins).build();
194     }
195     /**
196      * Creates a new {@code Build} instance using the specified pluginManagement.
197      *
198      * @param pluginManagement the new {@code PluginManagement} to use
199      * @return a {@code Build} with the specified pluginManagement
200      */
201     @Nonnull
202     public Build withPluginManagement(PluginManagement pluginManagement) {
203         return newBuilder(this, true).pluginManagement(pluginManagement).build();
204     }
205     /**
206      * Creates a new {@code Build} instance using the specified defaultGoal.
207      *
208      * @param defaultGoal the new {@code String} to use
209      * @return a {@code Build} with the specified defaultGoal
210      */
211     @Nonnull
212     public Build withDefaultGoal(String defaultGoal) {
213         return newBuilder(this, true).defaultGoal(defaultGoal).build();
214     }
215     /**
216      * Creates a new {@code Build} instance using the specified resources.
217      *
218      * @param resources the new {@code Collection<Resource>} to use
219      * @return a {@code Build} with the specified resources
220      */
221     @Nonnull
222     public Build withResources(Collection<Resource> resources) {
223         return newBuilder(this, true).resources(resources).build();
224     }
225     /**
226      * Creates a new {@code Build} instance using the specified testResources.
227      *
228      * @param testResources the new {@code Collection<Resource>} to use
229      * @return a {@code Build} with the specified testResources
230      */
231     @Nonnull
232     public Build withTestResources(Collection<Resource> testResources) {
233         return newBuilder(this, true).testResources(testResources).build();
234     }
235     /**
236      * Creates a new {@code Build} instance using the specified directory.
237      *
238      * @param directory the new {@code String} to use
239      * @return a {@code Build} with the specified directory
240      */
241     @Nonnull
242     public Build withDirectory(String directory) {
243         return newBuilder(this, true).directory(directory).build();
244     }
245     /**
246      * Creates a new {@code Build} instance using the specified finalName.
247      *
248      * @param finalName the new {@code String} to use
249      * @return a {@code Build} with the specified finalName
250      */
251     @Nonnull
252     public Build withFinalName(String finalName) {
253         return newBuilder(this, true).finalName(finalName).build();
254     }
255     /**
256      * Creates a new {@code Build} instance using the specified filters.
257      *
258      * @param filters the new {@code Collection<String>} to use
259      * @return a {@code Build} with the specified filters
260      */
261     @Nonnull
262     public Build withFilters(Collection<String> filters) {
263         return newBuilder(this, true).filters(filters).build();
264     }
265     /**
266      * Creates a new {@code Build} instance using the specified sourceDirectory.
267      *
268      * @param sourceDirectory the new {@code String} to use
269      * @return a {@code Build} with the specified sourceDirectory
270      */
271     @Nonnull
272     public Build withSourceDirectory(String sourceDirectory) {
273         return newBuilder(this, true).sourceDirectory(sourceDirectory).build();
274     }
275     /**
276      * Creates a new {@code Build} instance using the specified scriptSourceDirectory.
277      *
278      * @param scriptSourceDirectory the new {@code String} to use
279      * @return a {@code Build} with the specified scriptSourceDirectory
280      */
281     @Nonnull
282     public Build withScriptSourceDirectory(String scriptSourceDirectory) {
283         return newBuilder(this, true).scriptSourceDirectory(scriptSourceDirectory).build();
284     }
285     /**
286      * Creates a new {@code Build} instance using the specified testSourceDirectory.
287      *
288      * @param testSourceDirectory the new {@code String} to use
289      * @return a {@code Build} with the specified testSourceDirectory
290      */
291     @Nonnull
292     public Build withTestSourceDirectory(String testSourceDirectory) {
293         return newBuilder(this, true).testSourceDirectory(testSourceDirectory).build();
294     }
295     /**
296      * Creates a new {@code Build} instance using the specified outputDirectory.
297      *
298      * @param outputDirectory the new {@code String} to use
299      * @return a {@code Build} with the specified outputDirectory
300      */
301     @Nonnull
302     public Build withOutputDirectory(String outputDirectory) {
303         return newBuilder(this, true).outputDirectory(outputDirectory).build();
304     }
305     /**
306      * Creates a new {@code Build} instance using the specified testOutputDirectory.
307      *
308      * @param testOutputDirectory the new {@code String} to use
309      * @return a {@code Build} with the specified testOutputDirectory
310      */
311     @Nonnull
312     public Build withTestOutputDirectory(String testOutputDirectory) {
313         return newBuilder(this, true).testOutputDirectory(testOutputDirectory).build();
314     }
315     /**
316      * Creates a new {@code Build} instance using the specified extensions.
317      *
318      * @param extensions the new {@code Collection<Extension>} to use
319      * @return a {@code Build} with the specified extensions
320      */
321     @Nonnull
322     public Build withExtensions(Collection<Extension> extensions) {
323         return newBuilder(this, true).extensions(extensions).build();
324     }
325 
326     /**
327      * Creates a new {@code Build} instance.
328      * Equivalent to {@code newInstance(true)}.
329      * @see #newInstance(boolean)
330      *
331      * @return a new {@code Build}
332      */
333     @Nonnull
334     public static Build newInstance() {
335         return newInstance(true);
336     }
337 
338     /**
339      * Creates a new {@code Build} instance using default values or not.
340      * Equivalent to {@code newBuilder(withDefaults).build()}.
341      *
342      * @param withDefaults the boolean indicating whether default values should be used
343      * @return a new {@code Build}
344      */
345     @Nonnull
346     public static Build newInstance(boolean withDefaults) {
347         return newBuilder(withDefaults).build();
348     }
349 
350     /**
351      * Creates a new {@code Build} builder instance.
352      * Equivalent to {@code newBuilder(true)}.
353      * @see #newBuilder(boolean)
354      *
355      * @return a new {@code Builder}
356      */
357     @Nonnull
358     public static Builder newBuilder() {
359         return newBuilder(true);
360     }
361 
362     /**
363      * Creates a new {@code Build} builder instance using default values or not.
364      *
365      * @param withDefaults the boolean indicating whether default values should be used
366      * @return a new {@code Builder}
367      */
368     @Nonnull
369     public static Builder newBuilder(boolean withDefaults) {
370         return new Builder(withDefaults);
371     }
372 
373     /**
374      * Creates a new {@code Build} builder instance using the specified object as a basis.
375      * Equivalent to {@code newBuilder(from, false)}.
376      *
377      * @param from the {@code Build} instance to use as a basis
378      * @return a new {@code Builder}
379      */
380     @Nonnull
381     public static Builder newBuilder(Build from) {
382         return newBuilder(from, false);
383     }
384 
385     /**
386      * Creates a new {@code Build} builder instance using the specified object as a basis.
387      *
388      * @param from the {@code Build} instance to use as a basis
389      * @param forceCopy the boolean indicating if a copy should be forced
390      * @return a new {@code Builder}
391      */
392     @Nonnull
393     public static Builder newBuilder(Build from, boolean forceCopy) {
394         return new Builder(from, forceCopy);
395     }
396 
397     /**
398      * Builder class used to create Build instances.
399      * @see #with()
400      * @see #newBuilder()
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             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
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      * @see java.lang.Object#toString()
567      */
568     public String toString()
569     {
570         return "Build {" + super.toString() + "}";
571     }
572             
573           
574 }