View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   //   Generated by Maven, any modifications will be overwritten.
3   // ==============================================================
4   package org.apache.maven.api.model;
5   
6   import java.io.Serializable;
7   import java.util.ArrayList;
8   import java.util.Collection;
9   import java.util.Collections;
10  import java.util.HashMap;
11  import java.util.List;
12  import java.util.Map;
13  import org.apache.maven.api.annotations.Experimental;
14  import org.apache.maven.api.annotations.Generated;
15  import org.apache.maven.api.annotations.Immutable;
16  import org.apache.maven.api.annotations.Nonnull;
17  import org.apache.maven.api.annotations.NotThreadSafe;
18  import org.apache.maven.api.annotations.ThreadSafe;
19  
20  /**
21   * Build configuration in a profile.
22   */
23  @Experimental
24  @Generated @ThreadSafe @Immutable
25  public class BuildBase
26      extends PluginConfiguration
27      implements Serializable, InputLocationTracker
28  {
29      /**
30       * The default goal (or phase in Maven 2) to execute when none is specified for
31       * the project. Note that in case of a multi-module build, only the default goal of the top-level
32       * project is relevant, i.e. the default goals of child modules are ignored. Since Maven 3,
33       * multiple goals/phases can be separated by whitespace.
34       */
35      final String defaultGoal;
36      /**
37       * This element describes all of the classpath resources such as properties
38       * files associated with a project. These resources are often included in the final
39       * package.
40       * The default value is {@code src/main/resources}.
41       */
42      final List<Resource> resources;
43      /**
44       * This element describes all of the classpath resources such as properties
45       * files associated with a project's unit tests.
46       * The default value is {@code src/test/resources}.
47       */
48      final List<Resource> testResources;
49      /**
50       * The directory where all files generated by the build are placed.
51       * The default value is {@code target}.
52       */
53      final String directory;
54      /**
55       * The filename (excluding the extension, and with no path information) that
56       * the produced artifact will be called.
57       * The default value is {@code ${artifactId}-${version}}.
58       */
59      final String finalName;
60      /**
61       * The list of filter properties files that are used when filtering is enabled.
62       */
63      final List<String> filters;
64      /** Location of the xml element for the field defaultGoal. */
65      final InputLocation defaultGoalLocation;
66      /** Location of the xml element for the field resources. */
67      final InputLocation resourcesLocation;
68      /** Location of the xml element for the field testResources. */
69      final InputLocation testResourcesLocation;
70      /** Location of the xml element for the field directory. */
71      final InputLocation directoryLocation;
72      /** Location of the xml element for the field finalName. */
73      final InputLocation finalNameLocation;
74      /** Location of the xml element for the field filters. */
75      final InputLocation filtersLocation;
76  
77      /**
78        * Constructor for this class, package protected.
79        * @see Builder#build()
80        */
81      BuildBase(
82          Collection<Plugin> plugins,
83          PluginManagement pluginManagement,
84          String defaultGoal,
85          Collection<Resource> resources,
86          Collection<Resource> testResources,
87          String directory,
88          String finalName,
89          Collection<String> filters,
90          Map<Object, InputLocation> locations,
91          InputLocation location,
92          InputLocation pluginsLocation,
93          InputLocation pluginManagementLocation,
94          InputLocation defaultGoalLocation,
95          InputLocation resourcesLocation,
96          InputLocation testResourcesLocation,
97          InputLocation directoryLocation,
98          InputLocation finalNameLocation,
99          InputLocation filtersLocation
100     )
101     {
102         super(
103             plugins,
104             pluginManagement,
105             locations,
106             location,
107             pluginsLocation,
108             pluginManagementLocation
109         );
110         this.defaultGoal = defaultGoal;
111         this.resources = ImmutableCollections.copy( resources );
112         this.testResources = ImmutableCollections.copy( testResources );
113         this.directory = directory;
114         this.finalName = finalName;
115         this.filters = ImmutableCollections.copy( filters );
116         this.defaultGoalLocation = defaultGoalLocation;
117         this.resourcesLocation = resourcesLocation;
118         this.testResourcesLocation = testResourcesLocation;
119         this.directoryLocation = directoryLocation;
120         this.finalNameLocation = finalNameLocation;
121         this.filtersLocation = filtersLocation;
122     }
123 
124     /**
125      * The default goal (or phase in Maven 2) to execute when none is specified for
126      * the project. Note that in case of a multi-module build, only the default goal of the top-level
127      * project is relevant, i.e. the default goals of child modules are ignored. Since Maven 3,
128      * multiple goals/phases can be separated by whitespace.
129      *
130      * @return a {@code String}
131      */
132     public String getDefaultGoal()
133     {
134         return this.defaultGoal;
135     }
136 
137     /**
138      * This element describes all of the classpath resources such as properties
139      * files associated with a project. These resources are often included in the final
140      * package.
141      * The default value is {@code src/main/resources}.
142      *
143      * @return a {@code List<Resource>}
144      */
145     @Nonnull
146     public List<Resource> getResources()
147     {
148         return this.resources;
149     }
150 
151     /**
152      * This element describes all of the classpath resources such as properties
153      * files associated with a project's unit tests.
154      * The default value is {@code src/test/resources}.
155      *
156      * @return a {@code List<Resource>}
157      */
158     @Nonnull
159     public List<Resource> getTestResources()
160     {
161         return this.testResources;
162     }
163 
164     /**
165      * The directory where all files generated by the build are placed.
166      * The default value is {@code target}.
167      *
168      * @return a {@code String}
169      */
170     public String getDirectory()
171     {
172         return this.directory;
173     }
174 
175     /**
176      * The filename (excluding the extension, and with no path information) that
177      * the produced artifact will be called.
178      * The default value is {@code ${artifactId}-${version}}.
179      *
180      * @return a {@code String}
181      */
182     public String getFinalName()
183     {
184         return this.finalName;
185     }
186 
187     /**
188      * The list of filter properties files that are used when filtering is enabled.
189      *
190      * @return a {@code List<String>}
191      */
192     @Nonnull
193     public List<String> getFilters()
194     {
195         return this.filters;
196     }
197 
198     /**
199      * Gets the location of the specified field in the input source.
200      */
201     public InputLocation getLocation( Object key )
202     {
203         if ( key instanceof String )
204         {
205             switch ( ( String ) key )
206             {
207                 case "defaultGoal":
208                     return defaultGoalLocation;
209                 case "resources":
210                     return resourcesLocation;
211                 case "testResources":
212                     return testResourcesLocation;
213                 case "directory":
214                     return directoryLocation;
215                 case "finalName":
216                     return finalNameLocation;
217                 case "filters":
218                     return filtersLocation;
219             }
220         }
221         return super.getLocation( key );
222     }
223 
224     /**
225      * Creates a new builder with this object as the basis.
226      *
227      * @return a {@code Builder}
228      */
229     @Nonnull
230     public Builder with()
231     {
232         return newBuilder( this );
233     }
234     /**
235      * Creates a new {@code BuildBase} instance using the specified plugins.
236      *
237      * @param plugins the new {@code Collection<Plugin>} to use
238      * @return a {@code BuildBase} with the specified plugins
239      */
240     @Nonnull
241     public BuildBase withPlugins( Collection<Plugin> plugins )
242     {
243         return with().plugins( plugins ).build();
244     }
245     /**
246      * Creates a new {@code BuildBase} instance using the specified pluginManagement.
247      *
248      * @param pluginManagement the new {@code PluginManagement} to use
249      * @return a {@code BuildBase} with the specified pluginManagement
250      */
251     @Nonnull
252     public BuildBase withPluginManagement( PluginManagement pluginManagement )
253     {
254         return with().pluginManagement( pluginManagement ).build();
255     }
256     /**
257      * Creates a new {@code BuildBase} instance using the specified defaultGoal.
258      *
259      * @param defaultGoal the new {@code String} to use
260      * @return a {@code BuildBase} with the specified defaultGoal
261      */
262     @Nonnull
263     public BuildBase withDefaultGoal( String defaultGoal )
264     {
265         return with().defaultGoal( defaultGoal ).build();
266     }
267     /**
268      * Creates a new {@code BuildBase} instance using the specified resources.
269      *
270      * @param resources the new {@code Collection<Resource>} to use
271      * @return a {@code BuildBase} with the specified resources
272      */
273     @Nonnull
274     public BuildBase withResources( Collection<Resource> resources )
275     {
276         return with().resources( resources ).build();
277     }
278     /**
279      * Creates a new {@code BuildBase} instance using the specified testResources.
280      *
281      * @param testResources the new {@code Collection<Resource>} to use
282      * @return a {@code BuildBase} with the specified testResources
283      */
284     @Nonnull
285     public BuildBase withTestResources( Collection<Resource> testResources )
286     {
287         return with().testResources( testResources ).build();
288     }
289     /**
290      * Creates a new {@code BuildBase} instance using the specified directory.
291      *
292      * @param directory the new {@code String} to use
293      * @return a {@code BuildBase} with the specified directory
294      */
295     @Nonnull
296     public BuildBase withDirectory( String directory )
297     {
298         return with().directory( directory ).build();
299     }
300     /**
301      * Creates a new {@code BuildBase} instance using the specified finalName.
302      *
303      * @param finalName the new {@code String} to use
304      * @return a {@code BuildBase} with the specified finalName
305      */
306     @Nonnull
307     public BuildBase withFinalName( String finalName )
308     {
309         return with().finalName( finalName ).build();
310     }
311     /**
312      * Creates a new {@code BuildBase} instance using the specified filters.
313      *
314      * @param filters the new {@code Collection<String>} to use
315      * @return a {@code BuildBase} with the specified filters
316      */
317     @Nonnull
318     public BuildBase withFilters( Collection<String> filters )
319     {
320         return with().filters( filters ).build();
321     }
322 
323     /**
324      * Creates a new {@code BuildBase} instance.
325      * Equivalent to {@code newInstance( true )}.
326      * @see #newInstance(boolean)
327      *
328      * @return a new {@code BuildBase}
329      */
330     @Nonnull
331     public static BuildBase newInstance()
332     {
333         return newInstance( true );
334     }
335 
336     /**
337      * Creates a new {@code BuildBase} instance using default values or not.
338      * Equivalent to {@code newBuilder( withDefaults ).build()}.
339      *
340      * @param withDefaults the boolean indicating whether default values should be used
341      * @return a new {@code BuildBase}
342      */
343     @Nonnull
344     public static BuildBase newInstance( boolean withDefaults )
345     {
346         return newBuilder( withDefaults ).build();
347     }
348 
349     /**
350      * Creates a new {@code BuildBase} 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     {
359         return newBuilder( true );
360     }
361 
362     /**
363      * Creates a new {@code BuildBase} 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     {
371         return new Builder( withDefaults );
372     }
373 
374     /**
375      * Creates a new {@code BuildBase} builder instance using the specified object as a basis.
376      * Equivalent to {@code newBuilder( from, false )}.
377      *
378      * @param from the {@code BuildBase} instance to use as a basis
379      * @return a new {@code Builder}
380      */
381     @Nonnull
382     public static Builder newBuilder( BuildBase from )
383     {
384         return newBuilder( from, false );
385     }
386 
387     /**
388      * Creates a new {@code BuildBase} builder instance using the specified object as a basis.
389      *
390      * @param from the {@code BuildBase} instance to use as a basis
391      * @param forceCopy the boolean indicating if a copy should be forced
392      * @return a new {@code Builder}
393      */
394     @Nonnull
395     public static Builder newBuilder( BuildBase from, boolean forceCopy )
396     {
397         return new Builder( from, forceCopy );
398     }
399 
400     /**
401      * Builder class used to create BuildBase instances.
402      * @see #with()
403      * @see #newBuilder()
404      */
405     @NotThreadSafe
406     public static class Builder
407         extends PluginConfiguration.Builder
408     {
409         BuildBase base;
410         String defaultGoal;
411         Collection<Resource> resources;
412         Collection<Resource> testResources;
413         String directory;
414         String finalName;
415         Collection<String> filters;
416 
417         Builder( boolean withDefaults )
418         {
419             super( withDefaults );
420             if ( withDefaults )
421             {
422             }
423         }
424 
425         Builder( BuildBase base, boolean forceCopy )
426         {
427             super( base, forceCopy );
428             if ( forceCopy )
429             {
430                 this.defaultGoal = base.defaultGoal;
431                 this.resources = base.resources;
432                 this.testResources = base.testResources;
433                 this.directory = base.directory;
434                 this.finalName = base.finalName;
435                 this.filters = base.filters;
436             }
437             else
438             {
439                 this.base = base;
440             }
441         }
442 
443         @Nonnull
444         public Builder plugins( Collection<Plugin> plugins )
445         {
446             this.plugins = plugins;
447             return this;
448         }
449 
450         @Nonnull
451         public Builder pluginManagement( PluginManagement pluginManagement )
452         {
453             this.pluginManagement = pluginManagement;
454             return this;
455         }
456 
457         @Nonnull
458         public Builder defaultGoal( String defaultGoal )
459         {
460             this.defaultGoal = defaultGoal;
461             return this;
462         }
463 
464         @Nonnull
465         public Builder resources( Collection<Resource> resources )
466         {
467             this.resources = resources;
468             return this;
469         }
470 
471         @Nonnull
472         public Builder testResources( Collection<Resource> testResources )
473         {
474             this.testResources = testResources;
475             return this;
476         }
477 
478         @Nonnull
479         public Builder directory( String directory )
480         {
481             this.directory = directory;
482             return this;
483         }
484 
485         @Nonnull
486         public Builder finalName( String finalName )
487         {
488             this.finalName = finalName;
489             return this;
490         }
491 
492         @Nonnull
493         public Builder filters( Collection<String> filters )
494         {
495             this.filters = filters;
496             return this;
497         }
498 
499 
500         @Nonnull
501         public Builder location( Object key, InputLocation location )
502         {
503             if ( location != null )
504             {
505                 if ( this.locations == null )
506                 {
507                     this.locations = new HashMap<>();
508                 }
509                 this.locations.put( key, location );
510             }
511             return this;
512         }
513 
514         @Nonnull
515         public BuildBase build()
516         {
517             if ( base != null
518                     && ( plugins == null || plugins == base.plugins )
519                     && ( pluginManagement == null || pluginManagement == base.pluginManagement )
520                     && ( defaultGoal == null || defaultGoal == base.defaultGoal )
521                     && ( resources == null || resources == base.resources )
522                     && ( testResources == null || testResources == base.testResources )
523                     && ( directory == null || directory == base.directory )
524                     && ( finalName == null || finalName == base.finalName )
525                     && ( filters == null || filters == base.filters )
526             )
527             {
528                 return base;
529             }
530             Map<Object, InputLocation> locations = null;
531             InputLocation location = null;
532             InputLocation pluginsLocation = null;
533             InputLocation pluginManagementLocation = null;
534             InputLocation defaultGoalLocation = null;
535             InputLocation resourcesLocation = null;
536             InputLocation testResourcesLocation = null;
537             InputLocation directoryLocation = null;
538             InputLocation finalNameLocation = null;
539             InputLocation filtersLocation = null;
540             if ( this.locations != null )
541             {
542                 locations = this.locations;
543                 location = locations.remove( "" );
544                 pluginsLocation = locations.remove( "plugins" );
545                 pluginManagementLocation = locations.remove( "pluginManagement" );
546                 defaultGoalLocation = locations.remove( "defaultGoal" );
547                 resourcesLocation = locations.remove( "resources" );
548                 testResourcesLocation = locations.remove( "testResources" );
549                 directoryLocation = locations.remove( "directory" );
550                 finalNameLocation = locations.remove( "finalName" );
551                 filtersLocation = locations.remove( "filters" );
552             }
553             return new BuildBase(
554                 plugins != null ? plugins : ( base != null ? base.plugins : null ),
555                 pluginManagement != null ? pluginManagement : ( base != null ? base.pluginManagement : null ),
556                 defaultGoal != null ? defaultGoal : ( base != null ? base.defaultGoal : null ),
557                 resources != null ? resources : ( base != null ? base.resources : null ),
558                 testResources != null ? testResources : ( base != null ? base.testResources : null ),
559                 directory != null ? directory : ( base != null ? base.directory : null ),
560                 finalName != null ? finalName : ( base != null ? base.finalName : null ),
561                 filters != null ? filters : ( base != null ? base.filters : null ),
562                 locations != null ? locations : ( base != null ? base.locations : null ),
563                 location != null ? location : ( base != null ? base.location : null ),
564                 pluginsLocation != null ? pluginsLocation : ( base != null ? base.pluginsLocation : null ),
565                 pluginManagementLocation != null ? pluginManagementLocation : ( base != null ? base.pluginManagementLocation : null ),
566                 defaultGoalLocation != null ? defaultGoalLocation : ( base != null ? base.defaultGoalLocation : null ),
567                 resourcesLocation != null ? resourcesLocation : ( base != null ? base.resourcesLocation : null ),
568                 testResourcesLocation != null ? testResourcesLocation : ( base != null ? base.testResourcesLocation : null ),
569                 directoryLocation != null ? directoryLocation : ( base != null ? base.directoryLocation : null ),
570                 finalNameLocation != null ? finalNameLocation : ( base != null ? base.finalNameLocation : null ),
571                 filtersLocation != null ? filtersLocation : ( base != null ? base.filtersLocation : null )
572             );
573         }
574     }
575 
576 }