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.Collections;
9   import java.util.HashMap;
10  import java.util.Map;
11  import org.apache.maven.api.annotations.Experimental;
12  import org.apache.maven.api.annotations.Generated;
13  import org.apache.maven.api.annotations.Immutable;
14  import org.apache.maven.api.annotations.Nonnull;
15  import org.apache.maven.api.annotations.NotThreadSafe;
16  import org.apache.maven.api.annotations.ThreadSafe;
17  import org.apache.maven.api.xml.XmlNode;
18  
19  /**
20   * Contains the configuration information of the container like Plugin.
21   */
22  @Experimental
23  @Generated @ThreadSafe @Immutable
24  public class ConfigurationContainer
25      implements Serializable, InputLocationTracker
26  {
27      /**
28       * Whether any configuration should be propagated to child POMs. Note: While the type
29       * of this field is {@code String} for technical reasons, the semantic type is actually
30       * {@code Boolean}. Default value is {@code true}.
31       */
32      final String inherited;
33      /**
34       * <p>The configuration as DOM object.</p>
35       * <p>By default, every element content is trimmed, but starting with Maven 3.1.0, you can add
36       * {@code xml:space="preserve"} to elements you want to preserve whitespace.</p>
37       * <p>You can control how child POMs inherit configuration from parent POMs by adding {@code combine.children}
38       * or {@code combine.self} attributes to the children of the configuration element:</p>
39       * <ul>
40       * <li>{@code combine.children}: available values are {@code merge} (default) and {@code append},</li>
41       * <li>{@code combine.self}: available values are {@code merge} (default) and {@code override}.</li>
42       * </ul>
43       * <p>See <a href="https://maven.apache.org/pom.html#Plugins">POM Reference documentation</a> and
44       * <a href="https://codehaus-plexus.github.io/plexus-utils/apidocs/org/codehaus/plexus/util/xml/Xpp3DomUtils.html">Xpp3DomUtils</a>
45       * for more information.</p>
46       */
47      final XmlNode configuration;
48      /** Location of the xml element for this object. */
49      final InputLocation location;
50      /** Location of the xml element for the field inherited. */
51      final InputLocation inheritedLocation;
52      /** Location of the xml element for the field configuration. */
53      final InputLocation configurationLocation;
54      /** Other locations */
55      final Map<Object, InputLocation> locations;
56  
57      /**
58        * Constructor for this class, package protected.
59        * @see Builder#build()
60        */
61      ConfigurationContainer(
62          String inherited,
63          XmlNode configuration,
64          Map<Object, InputLocation> locations,
65          InputLocation location,
66          InputLocation inheritedLocation,
67          InputLocation configurationLocation
68      )
69      {
70          this.inherited = inherited;
71          this.configuration = configuration;
72          this.locations = ImmutableCollections.copy( locations );
73          this.location = location;
74          this.inheritedLocation = inheritedLocation;
75          this.configurationLocation = configurationLocation;
76      }
77  
78      /**
79       * Whether any configuration should be propagated to child POMs. Note: While the type
80       * of this field is {@code String} for technical reasons, the semantic type is actually
81       * {@code Boolean}. Default value is {@code true}.
82       *
83       * @return a {@code String}
84       */
85      public String getInherited()
86      {
87          return this.inherited;
88      }
89  
90      /**
91       * <p>The configuration as DOM object.</p>
92       * <p>By default, every element content is trimmed, but starting with Maven 3.1.0, you can add
93       * {@code xml:space="preserve"} to elements you want to preserve whitespace.</p>
94       * <p>You can control how child POMs inherit configuration from parent POMs by adding {@code combine.children}
95       * or {@code combine.self} attributes to the children of the configuration element:</p>
96       * <ul>
97       * <li>{@code combine.children}: available values are {@code merge} (default) and {@code append},</li>
98       * <li>{@code combine.self}: available values are {@code merge} (default) and {@code override}.</li>
99       * </ul>
100      * <p>See <a href="https://maven.apache.org/pom.html#Plugins">POM Reference documentation</a> and
101      * <a href="https://codehaus-plexus.github.io/plexus-utils/apidocs/org/codehaus/plexus/util/xml/Xpp3DomUtils.html">Xpp3DomUtils</a>
102      * for more information.</p>
103      *
104      * @return a {@code XmlNode}
105      */
106     public XmlNode getConfiguration()
107     {
108         return this.configuration;
109     }
110 
111     /**
112      * Gets the location of the specified field in the input source.
113      */
114     public InputLocation getLocation( Object key )
115     {
116         if ( key instanceof String )
117         {
118             switch ( ( String ) key )
119             {
120                 case "":
121                     return location;
122                 case "inherited":
123                     return inheritedLocation;
124                 case "configuration":
125                     return configurationLocation;
126             }
127         }
128         return locations != null ? locations.get( key ) : null;
129     }
130 
131     /**
132      * Creates a new builder with this object as the basis.
133      *
134      * @return a {@code Builder}
135      */
136     @Nonnull
137     public Builder with()
138     {
139         return newBuilder( this );
140     }
141     /**
142      * Creates a new {@code ConfigurationContainer} instance using the specified inherited.
143      *
144      * @param inherited the new {@code String} to use
145      * @return a {@code ConfigurationContainer} with the specified inherited
146      */
147     @Nonnull
148     public ConfigurationContainer withInherited( String inherited )
149     {
150         return with().inherited( inherited ).build();
151     }
152     /**
153      * Creates a new {@code ConfigurationContainer} instance using the specified configuration.
154      *
155      * @param configuration the new {@code XmlNode} to use
156      * @return a {@code ConfigurationContainer} with the specified configuration
157      */
158     @Nonnull
159     public ConfigurationContainer withConfiguration( XmlNode configuration )
160     {
161         return with().configuration( configuration ).build();
162     }
163 
164     /**
165      * Creates a new {@code ConfigurationContainer} instance.
166      * Equivalent to {@code newInstance( true )}.
167      * @see #newInstance(boolean)
168      *
169      * @return a new {@code ConfigurationContainer}
170      */
171     @Nonnull
172     public static ConfigurationContainer newInstance()
173     {
174         return newInstance( true );
175     }
176 
177     /**
178      * Creates a new {@code ConfigurationContainer} instance using default values or not.
179      * Equivalent to {@code newBuilder( withDefaults ).build()}.
180      *
181      * @param withDefaults the boolean indicating whether default values should be used
182      * @return a new {@code ConfigurationContainer}
183      */
184     @Nonnull
185     public static ConfigurationContainer newInstance( boolean withDefaults )
186     {
187         return newBuilder( withDefaults ).build();
188     }
189 
190     /**
191      * Creates a new {@code ConfigurationContainer} builder instance.
192      * Equivalent to {@code newBuilder( true )}.
193      * @see #newBuilder(boolean)
194      *
195      * @return a new {@code Builder}
196      */
197     @Nonnull
198     public static Builder newBuilder()
199     {
200         return newBuilder( true );
201     }
202 
203     /**
204      * Creates a new {@code ConfigurationContainer} builder instance using default values or not.
205      *
206      * @param withDefaults the boolean indicating whether default values should be used
207      * @return a new {@code Builder}
208      */
209     @Nonnull
210     public static Builder newBuilder( boolean withDefaults )
211     {
212         return new Builder( withDefaults );
213     }
214 
215     /**
216      * Creates a new {@code ConfigurationContainer} builder instance using the specified object as a basis.
217      * Equivalent to {@code newBuilder( from, false )}.
218      *
219      * @param from the {@code ConfigurationContainer} instance to use as a basis
220      * @return a new {@code Builder}
221      */
222     @Nonnull
223     public static Builder newBuilder( ConfigurationContainer from )
224     {
225         return newBuilder( from, false );
226     }
227 
228     /**
229      * Creates a new {@code ConfigurationContainer} builder instance using the specified object as a basis.
230      *
231      * @param from the {@code ConfigurationContainer} instance to use as a basis
232      * @param forceCopy the boolean indicating if a copy should be forced
233      * @return a new {@code Builder}
234      */
235     @Nonnull
236     public static Builder newBuilder( ConfigurationContainer from, boolean forceCopy )
237     {
238         return new Builder( from, forceCopy );
239     }
240 
241     /**
242      * Builder class used to create ConfigurationContainer instances.
243      * @see #with()
244      * @see #newBuilder()
245      */
246     @NotThreadSafe
247     public static class Builder
248     {
249         ConfigurationContainer base;
250         String inherited;
251         XmlNode configuration;
252         Map<Object, InputLocation> locations;
253 
254         Builder( boolean withDefaults )
255         {
256             if ( withDefaults )
257             {
258             }
259         }
260 
261         Builder( ConfigurationContainer base, boolean forceCopy )
262         {
263             if ( forceCopy )
264             {
265                 this.inherited = base.inherited;
266                 this.configuration = base.configuration;
267             }
268             else
269             {
270                 this.base = base;
271             }
272         }
273 
274         @Nonnull
275         public Builder inherited( String inherited )
276         {
277             this.inherited = inherited;
278             return this;
279         }
280 
281         @Nonnull
282         public Builder configuration( XmlNode configuration )
283         {
284             this.configuration = configuration;
285             return this;
286         }
287 
288 
289         @Nonnull
290         public Builder location( Object key, InputLocation location )
291         {
292             if ( location != null )
293             {
294                 if ( this.locations == null )
295                 {
296                     this.locations = new HashMap<>();
297                 }
298                 this.locations.put( key, location );
299             }
300             return this;
301         }
302 
303         @Nonnull
304         public ConfigurationContainer build()
305         {
306             if ( base != null
307                     && ( inherited == null || inherited == base.inherited )
308                     && ( configuration == null || configuration == base.configuration )
309             )
310             {
311                 return base;
312             }
313             Map<Object, InputLocation> locations = null;
314             InputLocation location = null;
315             InputLocation inheritedLocation = null;
316             InputLocation configurationLocation = null;
317             if ( this.locations != null )
318             {
319                 locations = this.locations;
320                 location = locations.remove( "" );
321                 inheritedLocation = locations.remove( "inherited" );
322                 configurationLocation = locations.remove( "configuration" );
323             }
324             return new ConfigurationContainer(
325                 inherited != null ? inherited : ( base != null ? base.inherited : null ),
326                 configuration != null ? configuration : ( base != null ? base.configuration : null ),
327                 locations != null ? locations : ( base != null ? base.locations : null ),
328                 location != null ? location : ( base != null ? base.location : null ),
329                 inheritedLocation != null ? inheritedLocation : ( base != null ? base.inheritedLocation : null ),
330                 configurationLocation != null ? configurationLocation : ( base != null ? base.configurationLocation : null )
331             );
332         }
333     }
334 
335 
336             
337     public boolean isInherited()
338     {
339         return ( getInherited() != null ) ? Boolean.parseBoolean( getInherited() ) : true;
340     }
341 
342             
343           
344 }