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