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