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