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