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