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   * Contains the plugins management informations for the project.
22   */
23  @Experimental
24  @Generated @ThreadSafe @Immutable
25  public class PluginConfiguration
26      extends PluginContainer
27      implements Serializable, InputLocationTracker
28  {
29      /**
30       * Default plugin information to be made available for reference by projects
31       * derived from this one. This plugin configuration will not be resolved or bound to the
32       * lifecycle unless referenced. Any local configuration for a given plugin will override
33       * the plugin's entire definition here.
34       */
35      final PluginManagement pluginManagement;
36      /** Location of the xml element for the field pluginManagement. */
37      final InputLocation pluginManagementLocation;
38  
39      /**
40        * Constructor for this class, package protected.
41        * @see Builder#build()
42        */
43      PluginConfiguration(
44          Collection<Plugin> plugins,
45          PluginManagement pluginManagement,
46          Map<Object, InputLocation> locations,
47          InputLocation location,
48          InputLocation pluginsLocation,
49          InputLocation pluginManagementLocation
50      )
51      {
52          super(
53              plugins,
54              locations,
55              location,
56              pluginsLocation
57          );
58          this.pluginManagement = pluginManagement;
59          this.pluginManagementLocation = pluginManagementLocation;
60      }
61  
62      /**
63       * Default plugin information to be made available for reference by projects
64       * derived from this one. This plugin configuration will not be resolved or bound to the
65       * lifecycle unless referenced. Any local configuration for a given plugin will override
66       * the plugin's entire definition here.
67       *
68       * @return a {@code PluginManagement}
69       */
70      public PluginManagement getPluginManagement()
71      {
72          return this.pluginManagement;
73      }
74  
75      /**
76       * Gets the location of the specified field in the input source.
77       */
78      public InputLocation getLocation( Object key )
79      {
80          if ( key instanceof String )
81          {
82              switch ( ( String ) key )
83              {
84                  case "pluginManagement":
85                      return pluginManagementLocation;
86              }
87          }
88          return super.getLocation( key );
89      }
90  
91      /**
92       * Creates a new builder with this object as the basis.
93       *
94       * @return a {@code Builder}
95       */
96      @Nonnull
97      public Builder with()
98      {
99          return newBuilder( this );
100     }
101     /**
102      * Creates a new {@code PluginConfiguration} instance using the specified plugins.
103      *
104      * @param plugins the new {@code Collection<Plugin>} to use
105      * @return a {@code PluginConfiguration} with the specified plugins
106      */
107     @Nonnull
108     public PluginConfiguration withPlugins( Collection<Plugin> plugins )
109     {
110         return with().plugins( plugins ).build();
111     }
112     /**
113      * Creates a new {@code PluginConfiguration} instance using the specified pluginManagement.
114      *
115      * @param pluginManagement the new {@code PluginManagement} to use
116      * @return a {@code PluginConfiguration} with the specified pluginManagement
117      */
118     @Nonnull
119     public PluginConfiguration withPluginManagement( PluginManagement pluginManagement )
120     {
121         return with().pluginManagement( pluginManagement ).build();
122     }
123 
124     /**
125      * Creates a new {@code PluginConfiguration} instance.
126      * Equivalent to {@code newInstance( true )}.
127      * @see #newInstance(boolean)
128      *
129      * @return a new {@code PluginConfiguration}
130      */
131     @Nonnull
132     public static PluginConfiguration newInstance()
133     {
134         return newInstance( true );
135     }
136 
137     /**
138      * Creates a new {@code PluginConfiguration} instance using default values or not.
139      * Equivalent to {@code newBuilder( withDefaults ).build()}.
140      *
141      * @param withDefaults the boolean indicating whether default values should be used
142      * @return a new {@code PluginConfiguration}
143      */
144     @Nonnull
145     public static PluginConfiguration newInstance( boolean withDefaults )
146     {
147         return newBuilder( withDefaults ).build();
148     }
149 
150     /**
151      * Creates a new {@code PluginConfiguration} builder instance.
152      * Equivalent to {@code newBuilder( true )}.
153      * @see #newBuilder(boolean)
154      *
155      * @return a new {@code Builder}
156      */
157     @Nonnull
158     public static Builder newBuilder()
159     {
160         return newBuilder( true );
161     }
162 
163     /**
164      * Creates a new {@code PluginConfiguration} builder instance using default values or not.
165      *
166      * @param withDefaults the boolean indicating whether default values should be used
167      * @return a new {@code Builder}
168      */
169     @Nonnull
170     public static Builder newBuilder( boolean withDefaults )
171     {
172         return new Builder( withDefaults );
173     }
174 
175     /**
176      * Creates a new {@code PluginConfiguration} builder instance using the specified object as a basis.
177      * Equivalent to {@code newBuilder( from, false )}.
178      *
179      * @param from the {@code PluginConfiguration} instance to use as a basis
180      * @return a new {@code Builder}
181      */
182     @Nonnull
183     public static Builder newBuilder( PluginConfiguration from )
184     {
185         return newBuilder( from, false );
186     }
187 
188     /**
189      * Creates a new {@code PluginConfiguration} builder instance using the specified object as a basis.
190      *
191      * @param from the {@code PluginConfiguration} instance to use as a basis
192      * @param forceCopy the boolean indicating if a copy should be forced
193      * @return a new {@code Builder}
194      */
195     @Nonnull
196     public static Builder newBuilder( PluginConfiguration from, boolean forceCopy )
197     {
198         return new Builder( from, forceCopy );
199     }
200 
201     /**
202      * Builder class used to create PluginConfiguration instances.
203      * @see #with()
204      * @see #newBuilder()
205      */
206     @NotThreadSafe
207     public static class Builder
208         extends PluginContainer.Builder
209     {
210         PluginConfiguration base;
211         PluginManagement pluginManagement;
212 
213         Builder( boolean withDefaults )
214         {
215             super( withDefaults );
216             if ( withDefaults )
217             {
218             }
219         }
220 
221         Builder( PluginConfiguration base, boolean forceCopy )
222         {
223             super( base, forceCopy );
224             if ( forceCopy )
225             {
226                 this.pluginManagement = base.pluginManagement;
227             }
228             else
229             {
230                 this.base = base;
231             }
232         }
233 
234         @Nonnull
235         public Builder plugins( Collection<Plugin> plugins )
236         {
237             this.plugins = plugins;
238             return this;
239         }
240 
241         @Nonnull
242         public Builder pluginManagement( PluginManagement pluginManagement )
243         {
244             this.pluginManagement = pluginManagement;
245             return this;
246         }
247 
248 
249         @Nonnull
250         public Builder location( Object key, InputLocation location )
251         {
252             if ( location != null )
253             {
254                 if ( this.locations == null )
255                 {
256                     this.locations = new HashMap<>();
257                 }
258                 this.locations.put( key, location );
259             }
260             return this;
261         }
262 
263         @Nonnull
264         public PluginConfiguration build()
265         {
266             if ( base != null
267                     && ( plugins == null || plugins == base.plugins )
268                     && ( pluginManagement == null || pluginManagement == base.pluginManagement )
269             )
270             {
271                 return base;
272             }
273             Map<Object, InputLocation> locations = null;
274             InputLocation location = null;
275             InputLocation pluginsLocation = null;
276             InputLocation pluginManagementLocation = null;
277             if ( this.locations != null )
278             {
279                 locations = this.locations;
280                 location = locations.remove( "" );
281                 pluginsLocation = locations.remove( "plugins" );
282                 pluginManagementLocation = locations.remove( "pluginManagement" );
283             }
284             return new PluginConfiguration(
285                 plugins != null ? plugins : ( base != null ? base.plugins : null ),
286                 pluginManagement != null ? pluginManagement : ( base != null ? base.pluginManagement : null ),
287                 locations != null ? locations : ( base != null ? base.locations : null ),
288                 location != null ? location : ( base != null ? base.location : null ),
289                 pluginsLocation != null ? pluginsLocation : ( base != null ? base.pluginsLocation : null ),
290                 pluginManagementLocation != null ? pluginManagementLocation : ( base != null ? base.pluginManagementLocation : null )
291             );
292         }
293     }
294 
295 }