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