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
18 /**
19 * The conditions within the build runtime environment which will trigger the
20 * automatic inclusion of the build profile. Multiple conditions can be defined, which must
21 * be all satisfied to activate the profile.
22 */
23 @Experimental
24 @Generated @ThreadSafe @Immutable
25 public class Activation
26 implements Serializable, InputLocationTracker
27 {
28 /**
29 * If set to true, this profile will be active unless another profile in this
30 * pom is activated using the command line -P option or by one of that profile's
31 * activators.
32 */
33 final boolean activeByDefault;
34 /**
35 * Specifies that this profile will be activated when a matching JDK is detected.
36 * For example, {@code 1.4} only activates on JDKs versioned 1.4,
37 * while {@code !1.4} matches any JDK that is not version 1.4. Ranges are supported too:
38 * {@code [1.5,)} activates when the JDK is 1.5 minimum.
39 */
40 final String jdk;
41 /**
42 * Specifies that this profile will be activated when matching operating system
43 * attributes are detected.
44 */
45 final ActivationOS os;
46 /**
47 * Specifies that this profile will be activated when this property is
48 * specified.
49 */
50 final ActivationProperty property;
51 /**
52 * Specifies that this profile will be activated based on existence of a file.
53 */
54 final ActivationFile file;
55 /**
56 * Specifies that this profile will be activated based on the project's packaging.
57 */
58 final String packaging;
59 /** Locations */
60 final Map<Object, InputLocation> locations;
61
62 /**
63 * Constructor for this class, package protected.
64 * @see Builder#build()
65 */
66 Activation(
67 boolean activeByDefault,
68 String jdk,
69 ActivationOS os,
70 ActivationProperty property,
71 ActivationFile file,
72 String packaging,
73 Map<Object, InputLocation> locations
74 ) {
75 this.activeByDefault = activeByDefault;
76 this.jdk = jdk;
77 this.os = os;
78 this.property = property;
79 this.file = file;
80 this.packaging = packaging;
81 this.locations = ImmutableCollections.copy(locations);
82 }
83
84 /**
85 * If set to true, this profile will be active unless another profile in this
86 * pom is activated using the command line -P option or by one of that profile's
87 * activators.
88 *
89 * @return a {@code boolean}
90 */
91 public boolean isActiveByDefault() {
92 return this.activeByDefault;
93 }
94
95 /**
96 * Specifies that this profile will be activated when a matching JDK is detected.
97 * For example, {@code 1.4} only activates on JDKs versioned 1.4,
98 * while {@code !1.4} matches any JDK that is not version 1.4. Ranges are supported too:
99 * {@code [1.5,)} activates when the JDK is 1.5 minimum.
100 *
101 * @return a {@code String}
102 */
103 public String getJdk() {
104 return this.jdk;
105 }
106
107 /**
108 * Specifies that this profile will be activated when matching operating system
109 * attributes are detected.
110 *
111 * @return a {@code ActivationOS}
112 */
113 public ActivationOS getOs() {
114 return this.os;
115 }
116
117 /**
118 * Specifies that this profile will be activated when this property is
119 * specified.
120 *
121 * @return a {@code ActivationProperty}
122 */
123 public ActivationProperty getProperty() {
124 return this.property;
125 }
126
127 /**
128 * Specifies that this profile will be activated based on existence of a file.
129 *
130 * @return a {@code ActivationFile}
131 */
132 public ActivationFile getFile() {
133 return this.file;
134 }
135
136 /**
137 * Specifies that this profile will be activated based on the project's packaging.
138 *
139 * @return a {@code String}
140 */
141 public String getPackaging() {
142 return this.packaging;
143 }
144
145 /**
146 * Gets the location of the specified field in the input source.
147 */
148 public InputLocation getLocation(Object key) {
149 return locations != null ? locations.get(key) : null;
150 }
151
152 /**
153 * Creates a new builder with this object as the basis.
154 *
155 * @return a {@code Builder}
156 */
157 @Nonnull
158 public Builder with() {
159 return newBuilder(this);
160 }
161 /**
162 * Creates a new {@code Activation} instance using the specified activeByDefault.
163 *
164 * @param activeByDefault the new {@code boolean} to use
165 * @return a {@code Activation} with the specified activeByDefault
166 */
167 @Nonnull
168 public Activation withActiveByDefault(boolean activeByDefault) {
169 return newBuilder(this, true).activeByDefault(activeByDefault).build();
170 }
171 /**
172 * Creates a new {@code Activation} instance using the specified jdk.
173 *
174 * @param jdk the new {@code String} to use
175 * @return a {@code Activation} with the specified jdk
176 */
177 @Nonnull
178 public Activation withJdk(String jdk) {
179 return newBuilder(this, true).jdk(jdk).build();
180 }
181 /**
182 * Creates a new {@code Activation} instance using the specified os.
183 *
184 * @param os the new {@code ActivationOS} to use
185 * @return a {@code Activation} with the specified os
186 */
187 @Nonnull
188 public Activation withOs(ActivationOS os) {
189 return newBuilder(this, true).os(os).build();
190 }
191 /**
192 * Creates a new {@code Activation} instance using the specified property.
193 *
194 * @param property the new {@code ActivationProperty} to use
195 * @return a {@code Activation} with the specified property
196 */
197 @Nonnull
198 public Activation withProperty(ActivationProperty property) {
199 return newBuilder(this, true).property(property).build();
200 }
201 /**
202 * Creates a new {@code Activation} instance using the specified file.
203 *
204 * @param file the new {@code ActivationFile} to use
205 * @return a {@code Activation} with the specified file
206 */
207 @Nonnull
208 public Activation withFile(ActivationFile file) {
209 return newBuilder(this, true).file(file).build();
210 }
211 /**
212 * Creates a new {@code Activation} instance using the specified packaging.
213 *
214 * @param packaging the new {@code String} to use
215 * @return a {@code Activation} with the specified packaging
216 */
217 @Nonnull
218 public Activation withPackaging(String packaging) {
219 return newBuilder(this, true).packaging(packaging).build();
220 }
221
222 /**
223 * Creates a new {@code Activation} instance.
224 * Equivalent to {@code newInstance(true)}.
225 * @see #newInstance(boolean)
226 *
227 * @return a new {@code Activation}
228 */
229 @Nonnull
230 public static Activation newInstance() {
231 return newInstance(true);
232 }
233
234 /**
235 * Creates a new {@code Activation} instance using default values or not.
236 * Equivalent to {@code newBuilder(withDefaults).build()}.
237 *
238 * @param withDefaults the boolean indicating whether default values should be used
239 * @return a new {@code Activation}
240 */
241 @Nonnull
242 public static Activation newInstance(boolean withDefaults) {
243 return newBuilder(withDefaults).build();
244 }
245
246 /**
247 * Creates a new {@code Activation} builder instance.
248 * Equivalent to {@code newBuilder(true)}.
249 * @see #newBuilder(boolean)
250 *
251 * @return a new {@code Builder}
252 */
253 @Nonnull
254 public static Builder newBuilder() {
255 return newBuilder(true);
256 }
257
258 /**
259 * Creates a new {@code Activation} builder instance using default values or not.
260 *
261 * @param withDefaults the boolean indicating whether default values should be used
262 * @return a new {@code Builder}
263 */
264 @Nonnull
265 public static Builder newBuilder(boolean withDefaults) {
266 return new Builder(withDefaults);
267 }
268
269 /**
270 * Creates a new {@code Activation} builder instance using the specified object as a basis.
271 * Equivalent to {@code newBuilder(from, false)}.
272 *
273 * @param from the {@code Activation} instance to use as a basis
274 * @return a new {@code Builder}
275 */
276 @Nonnull
277 public static Builder newBuilder(Activation from) {
278 return newBuilder(from, false);
279 }
280
281 /**
282 * Creates a new {@code Activation} builder instance using the specified object as a basis.
283 *
284 * @param from the {@code Activation} instance to use as a basis
285 * @param forceCopy the boolean indicating if a copy should be forced
286 * @return a new {@code Builder}
287 */
288 @Nonnull
289 public static Builder newBuilder(Activation from, boolean forceCopy) {
290 return new Builder(from, forceCopy);
291 }
292
293 /**
294 * Builder class used to create Activation instances.
295 * @see #with()
296 * @see #newBuilder()
297 */
298 @NotThreadSafe
299 public static class Builder
300 {
301 Activation base;
302 Boolean activeByDefault;
303 String jdk;
304 ActivationOS os;
305 ActivationProperty property;
306 ActivationFile file;
307 String packaging;
308 Map<Object, InputLocation> locations;
309
310 Builder(boolean withDefaults) {
311 if (withDefaults) {
312 this.activeByDefault = false;
313 }
314 }
315
316 Builder(Activation base, boolean forceCopy) {
317 if (forceCopy) {
318 this.activeByDefault = base.activeByDefault;
319 this.jdk = base.jdk;
320 this.os = base.os;
321 this.property = base.property;
322 this.file = base.file;
323 this.packaging = base.packaging;
324 this.locations = base.locations;
325 } else {
326 this.base = base;
327 }
328 }
329
330 @Nonnull
331 public Builder activeByDefault(boolean activeByDefault) {
332 this.activeByDefault = activeByDefault;
333 return this;
334 }
335
336 @Nonnull
337 public Builder jdk(String jdk) {
338 this.jdk = jdk;
339 return this;
340 }
341
342 @Nonnull
343 public Builder os(ActivationOS os) {
344 this.os = os;
345 return this;
346 }
347
348 @Nonnull
349 public Builder property(ActivationProperty property) {
350 this.property = property;
351 return this;
352 }
353
354 @Nonnull
355 public Builder file(ActivationFile file) {
356 this.file = file;
357 return this;
358 }
359
360 @Nonnull
361 public Builder packaging(String packaging) {
362 this.packaging = packaging;
363 return this;
364 }
365
366
367 @Nonnull
368 public Builder location(Object key, InputLocation location) {
369 if (location != null) {
370 if (!(this.locations instanceof HashMap)) {
371 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
372 }
373 this.locations.put(key, location);
374 }
375 return this;
376 }
377
378 @Nonnull
379 public Activation build() {
380 if (base != null
381 && (activeByDefault == null || activeByDefault == base.activeByDefault)
382 && (jdk == null || jdk == base.jdk)
383 && (os == null || os == base.os)
384 && (property == null || property == base.property)
385 && (file == null || file == base.file)
386 && (packaging == null || packaging == base.packaging)
387 ) {
388 return base;
389 }
390 Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
391 Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
392 Map<Object, InputLocation> locations = new HashMap<>();
393 locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
394 locations.put("activeByDefault", newlocs.containsKey("activeByDefault") ? newlocs.get("activeByDefault") : oldlocs.get("activeByDefault"));
395 locations.put("jdk", newlocs.containsKey("jdk") ? newlocs.get("jdk") : oldlocs.get("jdk"));
396 locations.put("os", newlocs.containsKey("os") ? newlocs.get("os") : oldlocs.get("os"));
397 locations.put("property", newlocs.containsKey("property") ? newlocs.get("property") : oldlocs.get("property"));
398 locations.put("file", newlocs.containsKey("file") ? newlocs.get("file") : oldlocs.get("file"));
399 locations.put("packaging", newlocs.containsKey("packaging") ? newlocs.get("packaging") : oldlocs.get("packaging"));
400 return new Activation(
401 activeByDefault != null ? activeByDefault : (base != null ? base.activeByDefault : false),
402 jdk != null ? jdk : (base != null ? base.jdk : null),
403 os != null ? os : (base != null ? base.os : null),
404 property != null ? property : (base != null ? base.property : null),
405 file != null ? file : (base != null ? base.file : null),
406 packaging != null ? packaging : (base != null ? base.packaging : null),
407 locations
408 );
409 }
410 }
411
412 }