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   * Build configuration in a profile.
24   */
25  @Experimental
26  @Generated @ThreadSafe @Immutable
27  public class BuildBase
28      extends PluginConfiguration
29      implements Serializable, InputLocationTracker
30  {
31      /**
32       * The default goal (or phase in Maven 2) to execute when none is specified for
33       * the project. Note that in case of a build with subprojects, only the default goal of the top-level
34       * project is relevant, i.e. the default goals of subprojects are ignored. Since Maven 3,
35       * multiple goals/phases can be separated by whitespace.
36       */
37      final String defaultGoal;
38      /**
39       * This element describes all the classpath resources such as properties
40       * files associated with a project. These resources are often included in the final
41       * package.
42       * The default value is {@code src/main/resources}.
43       */
44      final List<Resource> resources;
45      /**
46       * This element describes all the classpath resources such as properties
47       * files associated with a project's unit tests.
48       * The default value is {@code src/test/resources}.
49       */
50      final List<Resource> testResources;
51      /**
52       * The directory where all files generated by the build are placed.
53       * The default value is {@code target}.
54       */
55      final String directory;
56      /**
57       * The filename (excluding the extension, and with no path information) that
58       * the produced artifact will be called.
59       * The default value is {@code ${artifactId}-${version}}.
60       */
61      final String finalName;
62      /**
63       * The list of filter properties files that are used when filtering is enabled.
64       */
65      final List<String> filters;
66      /** Locations (this potentially hides the same name field from the super class) */
67      final Map<Object, InputLocation> locations;
68  
69      /**
70        * Constructor for this class, to be called from its subclasses and {@link Builder}.
71        * @see Builder#build()
72        */
73      protected BuildBase(Builder builder) {
74          super(builder);
75          this.defaultGoal = builder.defaultGoal != null ? builder.defaultGoal : (builder.base != null ? builder.base.defaultGoal : null);
76          this.resources = ImmutableCollections.copy(builder.resources != null ? builder.resources : (builder.base != null ? builder.base.resources : null));
77          this.testResources = ImmutableCollections.copy(builder.testResources != null ? builder.testResources : (builder.base != null ? builder.base.testResources : null));
78          this.directory = builder.directory != null ? builder.directory : (builder.base != null ? builder.base.directory : null);
79          this.finalName = builder.finalName != null ? builder.finalName : (builder.base != null ? builder.base.finalName : null);
80          this.filters = ImmutableCollections.copy(builder.filters != null ? builder.filters : (builder.base != null ? builder.base.filters : null));
81          Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
82          Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
83          Map<Object, InputLocation> mutableLocations = new HashMap<>(super.locations);
84          mutableLocations.put("defaultGoal", newlocs.containsKey("defaultGoal") ? newlocs.get("defaultGoal") : oldlocs.get("defaultGoal"));
85          mutableLocations.put("resources", newlocs.containsKey("resources") ? newlocs.get("resources") : oldlocs.get("resources"));
86          mutableLocations.put("testResources", newlocs.containsKey("testResources") ? newlocs.get("testResources") : oldlocs.get("testResources"));
87          mutableLocations.put("directory", newlocs.containsKey("directory") ? newlocs.get("directory") : oldlocs.get("directory"));
88          mutableLocations.put("finalName", newlocs.containsKey("finalName") ? newlocs.get("finalName") : oldlocs.get("finalName"));
89          mutableLocations.put("filters", newlocs.containsKey("filters") ? newlocs.get("filters") : oldlocs.get("filters"));
90          this.locations = Collections.unmodifiableMap(mutableLocations);
91      }
92  
93      /**
94       * The default goal (or phase in Maven 2) to execute when none is specified for
95       * the project. Note that in case of a build with subprojects, only the default goal of the top-level
96       * project is relevant, i.e. the default goals of subprojects are ignored. Since Maven 3,
97       * multiple goals/phases can be separated by whitespace.
98       *
99       * @return a {@code String}
100      */
101     public String getDefaultGoal() {
102         return this.defaultGoal;
103     }
104 
105     /**
106      * This element describes all the classpath resources such as properties
107      * files associated with a project. These resources are often included in the final
108      * package.
109      * The default value is {@code src/main/resources}.
110      *
111      * @return a {@code List<Resource>}
112      */
113     @Nonnull
114     public List<Resource> getResources() {
115         return this.resources;
116     }
117 
118     /**
119      * This element describes all the classpath resources such as properties
120      * files associated with a project's unit tests.
121      * The default value is {@code src/test/resources}.
122      *
123      * @return a {@code List<Resource>}
124      */
125     @Nonnull
126     public List<Resource> getTestResources() {
127         return this.testResources;
128     }
129 
130     /**
131      * The directory where all files generated by the build are placed.
132      * The default value is {@code target}.
133      *
134      * @return a {@code String}
135      */
136     public String getDirectory() {
137         return this.directory;
138     }
139 
140     /**
141      * The filename (excluding the extension, and with no path information) that
142      * the produced artifact will be called.
143      * The default value is {@code ${artifactId}-${version}}.
144      *
145      * @return a {@code String}
146      */
147     public String getFinalName() {
148         return this.finalName;
149     }
150 
151     /**
152      * The list of filter properties files that are used when filtering is enabled.
153      *
154      * @return a {@code List<String>}
155      */
156     @Nonnull
157     public List<String> getFilters() {
158         return this.filters;
159     }
160 
161     /**
162      * Gets the location of the specified field in the input source.
163      */
164     public InputLocation getLocation(Object key) {
165         return locations != null ? locations.get(key) : null;
166     }
167 
168     /**
169     * Gets the keys of the locations of the input source.
170     */
171     public Set<Object> getLocationKeys() {
172         return locations != null ? locations.keySet() : null;
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 BuildBase} instance using the specified plugins.
186      *
187      * @param plugins the new {@code Collection<Plugin>} to use
188      * @return a {@code BuildBase} with the specified plugins
189      */
190     @Nonnull
191     public BuildBase withPlugins(Collection<Plugin> plugins) {
192         return newBuilder(this, true).plugins(plugins).build();
193     }
194     /**
195      * Creates a new {@code BuildBase} instance using the specified pluginManagement.
196      *
197      * @param pluginManagement the new {@code PluginManagement} to use
198      * @return a {@code BuildBase} with the specified pluginManagement
199      */
200     @Nonnull
201     public BuildBase withPluginManagement(PluginManagement pluginManagement) {
202         return newBuilder(this, true).pluginManagement(pluginManagement).build();
203     }
204     /**
205      * Creates a new {@code BuildBase} instance using the specified defaultGoal.
206      *
207      * @param defaultGoal the new {@code String} to use
208      * @return a {@code BuildBase} with the specified defaultGoal
209      */
210     @Nonnull
211     public BuildBase withDefaultGoal(String defaultGoal) {
212         return newBuilder(this, true).defaultGoal(defaultGoal).build();
213     }
214     /**
215      * Creates a new {@code BuildBase} instance using the specified resources.
216      *
217      * @param resources the new {@code Collection<Resource>} to use
218      * @return a {@code BuildBase} with the specified resources
219      */
220     @Nonnull
221     public BuildBase withResources(Collection<Resource> resources) {
222         return newBuilder(this, true).resources(resources).build();
223     }
224     /**
225      * Creates a new {@code BuildBase} instance using the specified testResources.
226      *
227      * @param testResources the new {@code Collection<Resource>} to use
228      * @return a {@code BuildBase} with the specified testResources
229      */
230     @Nonnull
231     public BuildBase withTestResources(Collection<Resource> testResources) {
232         return newBuilder(this, true).testResources(testResources).build();
233     }
234     /**
235      * Creates a new {@code BuildBase} instance using the specified directory.
236      *
237      * @param directory the new {@code String} to use
238      * @return a {@code BuildBase} with the specified directory
239      */
240     @Nonnull
241     public BuildBase withDirectory(String directory) {
242         return newBuilder(this, true).directory(directory).build();
243     }
244     /**
245      * Creates a new {@code BuildBase} instance using the specified finalName.
246      *
247      * @param finalName the new {@code String} to use
248      * @return a {@code BuildBase} with the specified finalName
249      */
250     @Nonnull
251     public BuildBase withFinalName(String finalName) {
252         return newBuilder(this, true).finalName(finalName).build();
253     }
254     /**
255      * Creates a new {@code BuildBase} instance using the specified filters.
256      *
257      * @param filters the new {@code Collection<String>} to use
258      * @return a {@code BuildBase} with the specified filters
259      */
260     @Nonnull
261     public BuildBase withFilters(Collection<String> filters) {
262         return newBuilder(this, true).filters(filters).build();
263     }
264 
265     /**
266      * Creates a new {@code BuildBase} instance.
267      * Equivalent to {@code newInstance(true)}.
268      * @see #newInstance(boolean)
269      *
270      * @return a new {@code BuildBase}
271      */
272     @Nonnull
273     public static BuildBase newInstance() {
274         return newInstance(true);
275     }
276 
277     /**
278      * Creates a new {@code BuildBase} instance using default values or not.
279      * Equivalent to {@code newBuilder(withDefaults).build()}.
280      *
281      * @param withDefaults the boolean indicating whether default values should be used
282      * @return a new {@code BuildBase}
283      */
284     @Nonnull
285     public static BuildBase newInstance(boolean withDefaults) {
286         return newBuilder(withDefaults).build();
287     }
288 
289     /**
290      * Creates a new {@code BuildBase} builder instance.
291      * Equivalent to {@code newBuilder(true)}.
292      * @see #newBuilder(boolean)
293      *
294      * @return a new {@code Builder}
295      */
296     @Nonnull
297     public static Builder newBuilder() {
298         return newBuilder(true);
299     }
300 
301     /**
302      * Creates a new {@code BuildBase} builder instance using default values or not.
303      *
304      * @param withDefaults the boolean indicating whether default values should be used
305      * @return a new {@code Builder}
306      */
307     @Nonnull
308     public static Builder newBuilder(boolean withDefaults) {
309         return new Builder(withDefaults);
310     }
311 
312     /**
313      * Creates a new {@code BuildBase} builder instance using the specified object as a basis.
314      * Equivalent to {@code newBuilder(from, false)}.
315      *
316      * @param from the {@code BuildBase} instance to use as a basis
317      * @return a new {@code Builder}
318      */
319     @Nonnull
320     public static Builder newBuilder(BuildBase from) {
321         return newBuilder(from, false);
322     }
323 
324     /**
325      * Creates a new {@code BuildBase} builder instance using the specified object as a basis.
326      *
327      * @param from the {@code BuildBase} instance to use as a basis
328      * @param forceCopy the boolean indicating if a copy should be forced
329      * @return a new {@code Builder}
330      */
331     @Nonnull
332     public static Builder newBuilder(BuildBase from, boolean forceCopy) {
333         return new Builder(from, forceCopy);
334     }
335 
336     /**
337      * Builder class used to create BuildBase instances.
338      * @see #with()
339      * @see #newBuilder()
340      */
341     @NotThreadSafe
342     public static class Builder
343         extends PluginConfiguration.Builder
344     {
345         BuildBase base;
346         String defaultGoal;
347         Collection<Resource> resources;
348         Collection<Resource> testResources;
349         String directory;
350         String finalName;
351         Collection<String> filters;
352 
353         protected Builder(boolean withDefaults) {
354             super(withDefaults);
355             if (withDefaults) {
356             }
357         }
358 
359         protected Builder(BuildBase base, boolean forceCopy) {
360             super(base, forceCopy);
361             if (forceCopy) {
362                 this.defaultGoal = base.defaultGoal;
363                 this.resources = base.resources;
364                 this.testResources = base.testResources;
365                 this.directory = base.directory;
366                 this.finalName = base.finalName;
367                 this.filters = base.filters;
368                 this.locations = base.locations;
369                 this.importedFrom = base.importedFrom;
370             } else {
371                 this.base = base;
372             }
373         }
374 
375         @Nonnull
376         public Builder plugins(Collection<Plugin> plugins) {
377             this.plugins = plugins;
378             return this;
379         }
380 
381         @Nonnull
382         public Builder pluginManagement(PluginManagement pluginManagement) {
383             this.pluginManagement = pluginManagement;
384             return this;
385         }
386 
387         @Nonnull
388         public Builder defaultGoal(String defaultGoal) {
389             this.defaultGoal = defaultGoal;
390             return this;
391         }
392 
393         @Nonnull
394         public Builder resources(Collection<Resource> resources) {
395             this.resources = resources;
396             return this;
397         }
398 
399         @Nonnull
400         public Builder testResources(Collection<Resource> testResources) {
401             this.testResources = testResources;
402             return this;
403         }
404 
405         @Nonnull
406         public Builder directory(String directory) {
407             this.directory = directory;
408             return this;
409         }
410 
411         @Nonnull
412         public Builder finalName(String finalName) {
413             this.finalName = finalName;
414             return this;
415         }
416 
417         @Nonnull
418         public Builder filters(Collection<String> filters) {
419             this.filters = filters;
420             return this;
421         }
422 
423 
424         @Nonnull
425         public Builder location(Object key, InputLocation location) {
426             if (location != null) {
427                 if (!(this.locations instanceof HashMap)) {
428                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
429                 }
430                 this.locations.put(key, location);
431             }
432             return this;
433         }
434 
435         @Nonnull
436         public Builder importedFrom(InputLocation importedFrom) {
437             this.importedFrom = importedFrom;
438             return this;
439         }
440 
441         @Nonnull
442         public BuildBase build() {
443             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
444             if (base != null
445                     && (plugins == null || plugins == base.plugins)
446                     && (pluginManagement == null || pluginManagement == base.pluginManagement)
447                     && (defaultGoal == null || defaultGoal == base.defaultGoal)
448                     && (resources == null || resources == base.resources)
449                     && (testResources == null || testResources == base.testResources)
450                     && (directory == null || directory == base.directory)
451                     && (finalName == null || finalName == base.finalName)
452                     && (filters == null || filters == base.filters)
453             ) {
454                 return base;
455             }
456             return new BuildBase(this);
457         }
458     }
459 
460 
461             
462     /**
463      * @see java.lang.Object#toString()
464      */
465     public String toString()
466     {
467         return "BuildBase {" + super.toString() + "}";
468     }
469             
470           
471 }