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 * This is the file specification used to activate the profile. The {@code missing} value
20 * is the location of a file that needs to exist, and if it doesn't, the profile will be
21 * activated. On the other hand, {@code exists} will test for the existence of the file and if it is
22 * there, the profile will be activated.
23 * <p>Variable interpolation for these file specifications is limited to {@code ${project.basedir}},
24 * system properties and user properties.</p>
25 */
26 @Experimental
27 @Generated @ThreadSafe @Immutable
28 public class ActivationFile
29 implements Serializable, InputLocationTracker
30 {
31 /**
32 * The name of the file that must be missing to activate the
33 * profile.
34 */
35 final String missing;
36 /**
37 * The name of the file that must exist to activate the profile.
38 */
39 final String exists;
40 /** Locations */
41 final Map<Object, InputLocation> locations;
42
43 /**
44 * Constructor for this class, package protected.
45 * @see Builder#build()
46 */
47 ActivationFile(
48 String missing,
49 String exists,
50 Map<Object, InputLocation> locations
51 ) {
52 this.missing = missing;
53 this.exists = exists;
54 this.locations = ImmutableCollections.copy(locations);
55 }
56
57 /**
58 * The name of the file that must be missing to activate the
59 * profile.
60 *
61 * @return a {@code String}
62 */
63 public String getMissing() {
64 return this.missing;
65 }
66
67 /**
68 * The name of the file that must exist to activate the profile.
69 *
70 * @return a {@code String}
71 */
72 public String getExists() {
73 return this.exists;
74 }
75
76 /**
77 * Gets the location of the specified field in the input source.
78 */
79 public InputLocation getLocation(Object key) {
80 return locations != null ? locations.get(key) : null;
81 }
82
83 /**
84 * Creates a new builder with this object as the basis.
85 *
86 * @return a {@code Builder}
87 */
88 @Nonnull
89 public Builder with() {
90 return newBuilder(this);
91 }
92 /**
93 * Creates a new {@code ActivationFile} instance using the specified missing.
94 *
95 * @param missing the new {@code String} to use
96 * @return a {@code ActivationFile} with the specified missing
97 */
98 @Nonnull
99 public ActivationFile withMissing(String missing) {
100 return newBuilder(this, true).missing(missing).build();
101 }
102 /**
103 * Creates a new {@code ActivationFile} instance using the specified exists.
104 *
105 * @param exists the new {@code String} to use
106 * @return a {@code ActivationFile} with the specified exists
107 */
108 @Nonnull
109 public ActivationFile withExists(String exists) {
110 return newBuilder(this, true).exists(exists).build();
111 }
112
113 /**
114 * Creates a new {@code ActivationFile} instance.
115 * Equivalent to {@code newInstance(true)}.
116 * @see #newInstance(boolean)
117 *
118 * @return a new {@code ActivationFile}
119 */
120 @Nonnull
121 public static ActivationFile newInstance() {
122 return newInstance(true);
123 }
124
125 /**
126 * Creates a new {@code ActivationFile} instance using default values or not.
127 * Equivalent to {@code newBuilder(withDefaults).build()}.
128 *
129 * @param withDefaults the boolean indicating whether default values should be used
130 * @return a new {@code ActivationFile}
131 */
132 @Nonnull
133 public static ActivationFile newInstance(boolean withDefaults) {
134 return newBuilder(withDefaults).build();
135 }
136
137 /**
138 * Creates a new {@code ActivationFile} builder instance.
139 * Equivalent to {@code newBuilder(true)}.
140 * @see #newBuilder(boolean)
141 *
142 * @return a new {@code Builder}
143 */
144 @Nonnull
145 public static Builder newBuilder() {
146 return newBuilder(true);
147 }
148
149 /**
150 * Creates a new {@code ActivationFile} builder instance using default values or not.
151 *
152 * @param withDefaults the boolean indicating whether default values should be used
153 * @return a new {@code Builder}
154 */
155 @Nonnull
156 public static Builder newBuilder(boolean withDefaults) {
157 return new Builder(withDefaults);
158 }
159
160 /**
161 * Creates a new {@code ActivationFile} builder instance using the specified object as a basis.
162 * Equivalent to {@code newBuilder(from, false)}.
163 *
164 * @param from the {@code ActivationFile} instance to use as a basis
165 * @return a new {@code Builder}
166 */
167 @Nonnull
168 public static Builder newBuilder(ActivationFile from) {
169 return newBuilder(from, false);
170 }
171
172 /**
173 * Creates a new {@code ActivationFile} builder instance using the specified object as a basis.
174 *
175 * @param from the {@code ActivationFile} instance to use as a basis
176 * @param forceCopy the boolean indicating if a copy should be forced
177 * @return a new {@code Builder}
178 */
179 @Nonnull
180 public static Builder newBuilder(ActivationFile from, boolean forceCopy) {
181 return new Builder(from, forceCopy);
182 }
183
184 /**
185 * Builder class used to create ActivationFile instances.
186 * @see #with()
187 * @see #newBuilder()
188 */
189 @NotThreadSafe
190 public static class Builder
191 {
192 ActivationFile base;
193 String missing;
194 String exists;
195 Map<Object, InputLocation> locations;
196
197 Builder(boolean withDefaults) {
198 if (withDefaults) {
199 }
200 }
201
202 Builder(ActivationFile base, boolean forceCopy) {
203 if (forceCopy) {
204 this.missing = base.missing;
205 this.exists = base.exists;
206 this.locations = base.locations;
207 } else {
208 this.base = base;
209 }
210 }
211
212 @Nonnull
213 public Builder missing(String missing) {
214 this.missing = missing;
215 return this;
216 }
217
218 @Nonnull
219 public Builder exists(String exists) {
220 this.exists = exists;
221 return this;
222 }
223
224
225 @Nonnull
226 public Builder location(Object key, InputLocation location) {
227 if (location != null) {
228 if (!(this.locations instanceof HashMap)) {
229 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
230 }
231 this.locations.put(key, location);
232 }
233 return this;
234 }
235
236 @Nonnull
237 public ActivationFile build() {
238 if (base != null
239 && (missing == null || missing == base.missing)
240 && (exists == null || exists == base.exists)
241 ) {
242 return base;
243 }
244 Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
245 Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
246 Map<Object, InputLocation> locations = new HashMap<>();
247 locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
248 locations.put("missing", newlocs.containsKey("missing") ? newlocs.get("missing") : oldlocs.get("missing"));
249 locations.put("exists", newlocs.containsKey("exists") ? newlocs.get("exists") : oldlocs.get("exists"));
250 return new ActivationFile(
251 missing != null ? missing : (base != null ? base.missing : null),
252 exists != null ? exists : (base != null ? base.exists : null),
253 locations
254 );
255 }
256 }
257
258 }