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