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