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      /** Locations */
49      final Map<Object, InputLocation> locations;
50  
51      /**
52        * Constructor for this class, package protected.
53        * @see Builder#build()
54        */
55      ConfigurationContainer(
56          String inherited,
57          XmlNode configuration,
58          Map<Object, InputLocation> locations
59      ) {
60          this.inherited = inherited;
61          this.configuration = configuration;
62          this.locations = ImmutableCollections.copy(locations);
63      }
64  
65      /**
66       * Whether any configuration should be propagated to child POMs. Note: While the type
67       * of this field is {@code String} for technical reasons, the semantic type is actually
68       * {@code Boolean}. Default value is {@code true}.
69       *
70       * @return a {@code String}
71       */
72      public String getInherited() {
73          return this.inherited;
74      }
75  
76      /**
77       * <p>The configuration as DOM object.</p>
78       * <p>By default, every element content is trimmed, but starting with Maven 3.1.0, you can add
79       * {@code xml:space="preserve"} to elements you want to preserve whitespace.</p>
80       * <p>You can control how child POMs inherit configuration from parent POMs by adding {@code combine.children}
81       * or {@code combine.self} attributes to the children of the configuration element:</p>
82       * <ul>
83       * <li>{@code combine.children}: available values are {@code merge} (default) and {@code append},</li>
84       * <li>{@code combine.self}: available values are {@code merge} (default) and {@code override}.</li>
85       * </ul>
86       * <p>See <a href="https://maven.apache.org/pom.html#Plugins">POM Reference documentation</a> and
87       * <a href="https://codehaus-plexus.github.io/plexus-utils/apidocs/org/codehaus/plexus/util/xml/Xpp3DomUtils.html">Xpp3DomUtils</a>
88       * for more information.</p>
89       *
90       * @return a {@code XmlNode}
91       */
92      public XmlNode getConfiguration() {
93          return this.configuration;
94      }
95  
96      /**
97       * Gets the location of the specified field in the input source.
98       */
99      public InputLocation getLocation(Object key) {
100         return locations != null ? locations.get(key) : null;
101     }
102 
103     /**
104      * Creates a new builder with this object as the basis.
105      *
106      * @return a {@code Builder}
107      */
108     @Nonnull
109     public Builder with() {
110         return newBuilder(this);
111     }
112     /**
113      * Creates a new {@code ConfigurationContainer} instance using the specified inherited.
114      *
115      * @param inherited the new {@code String} to use
116      * @return a {@code ConfigurationContainer} with the specified inherited
117      */
118     @Nonnull
119     public ConfigurationContainer withInherited(String inherited) {
120         return newBuilder(this, true).inherited(inherited).build();
121     }
122     /**
123      * Creates a new {@code ConfigurationContainer} instance using the specified configuration.
124      *
125      * @param configuration the new {@code XmlNode} to use
126      * @return a {@code ConfigurationContainer} with the specified configuration
127      */
128     @Nonnull
129     public ConfigurationContainer withConfiguration(XmlNode configuration) {
130         return newBuilder(this, true).configuration(configuration).build();
131     }
132 
133     /**
134      * Creates a new {@code ConfigurationContainer} instance.
135      * Equivalent to {@code newInstance(true)}.
136      * @see #newInstance(boolean)
137      *
138      * @return a new {@code ConfigurationContainer}
139      */
140     @Nonnull
141     public static ConfigurationContainer newInstance() {
142         return newInstance(true);
143     }
144 
145     /**
146      * Creates a new {@code ConfigurationContainer} instance using default values or not.
147      * Equivalent to {@code newBuilder(withDefaults).build()}.
148      *
149      * @param withDefaults the boolean indicating whether default values should be used
150      * @return a new {@code ConfigurationContainer}
151      */
152     @Nonnull
153     public static ConfigurationContainer newInstance(boolean withDefaults) {
154         return newBuilder(withDefaults).build();
155     }
156 
157     /**
158      * Creates a new {@code ConfigurationContainer} builder instance.
159      * Equivalent to {@code newBuilder(true)}.
160      * @see #newBuilder(boolean)
161      *
162      * @return a new {@code Builder}
163      */
164     @Nonnull
165     public static Builder newBuilder() {
166         return newBuilder(true);
167     }
168 
169     /**
170      * Creates a new {@code ConfigurationContainer} builder instance using default values or not.
171      *
172      * @param withDefaults the boolean indicating whether default values should be used
173      * @return a new {@code Builder}
174      */
175     @Nonnull
176     public static Builder newBuilder(boolean withDefaults) {
177         return new Builder(withDefaults);
178     }
179 
180     /**
181      * Creates a new {@code ConfigurationContainer} builder instance using the specified object as a basis.
182      * Equivalent to {@code newBuilder(from, false)}.
183      *
184      * @param from the {@code ConfigurationContainer} instance to use as a basis
185      * @return a new {@code Builder}
186      */
187     @Nonnull
188     public static Builder newBuilder(ConfigurationContainer from) {
189         return newBuilder(from, false);
190     }
191 
192     /**
193      * Creates a new {@code ConfigurationContainer} builder instance using the specified object as a basis.
194      *
195      * @param from the {@code ConfigurationContainer} instance to use as a basis
196      * @param forceCopy the boolean indicating if a copy should be forced
197      * @return a new {@code Builder}
198      */
199     @Nonnull
200     public static Builder newBuilder(ConfigurationContainer from, boolean forceCopy) {
201         return new Builder(from, forceCopy);
202     }
203 
204     /**
205      * Builder class used to create ConfigurationContainer instances.
206      * @see #with()
207      * @see #newBuilder()
208      */
209     @NotThreadSafe
210     public static class Builder
211     {
212         ConfigurationContainer base;
213         String inherited;
214         XmlNode configuration;
215         Map<Object, InputLocation> locations;
216 
217         Builder(boolean withDefaults) {
218             if (withDefaults) {
219             }
220         }
221 
222         Builder(ConfigurationContainer base, boolean forceCopy) {
223             if (forceCopy) {
224                 this.inherited = base.inherited;
225                 this.configuration = base.configuration;
226                 this.locations = base.locations;
227             } else {
228                 this.base = base;
229             }
230         }
231 
232         @Nonnull
233         public Builder inherited(String inherited) {
234             this.inherited = inherited;
235             return this;
236         }
237 
238         @Nonnull
239         public Builder configuration(XmlNode configuration) {
240             this.configuration = configuration;
241             return this;
242         }
243 
244 
245         @Nonnull
246         public Builder location(Object key, InputLocation location) {
247             if (location != null) {
248                 if (!(this.locations instanceof HashMap)) {
249                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
250                 }
251                 this.locations.put(key, location);
252             }
253             return this;
254         }
255 
256         @Nonnull
257         public ConfigurationContainer build() {
258             if (base != null
259                     && (inherited == null || inherited == base.inherited)
260                     && (configuration == null || configuration == base.configuration)
261             ) {
262                 return base;
263             }
264             Map<Object, InputLocation> locations = null;
265             InputLocation location = null;
266             InputLocation inheritedLocation = null;
267             InputLocation configurationLocation = null;
268             if (this.locations != null) {
269                 locations = this.locations;
270             }
271             return new ConfigurationContainer(
272                 inherited != null ? inherited : (base != null ? base.inherited : null),
273                 configuration != null ? configuration : (base != null ? base.configuration : null),
274                 locations != null ? locations : (base != null ? base.locations : null)
275             );
276         }
277     }
278 
279 
280             
281     public boolean isInherited()
282     {
283         return ( getInherited() != null ) ? Boolean.parseBoolean( getInherited() ) : true;
284     }
285 
286             
287           
288 }