1
2
3
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
20
21 @Experimental
22 @Generated @ThreadSafe @Immutable
23 public class Notifier
24 implements Serializable, InputLocationTracker
25 {
26
27
28
29 final String type;
30
31
32
33 final boolean sendOnError;
34
35
36
37 final boolean sendOnFailure;
38
39
40
41 final boolean sendOnSuccess;
42
43
44
45 final boolean sendOnWarning;
46
47
48
49 final String address;
50
51
52
53 final Map<String, String> configuration;
54
55 final InputLocation location;
56
57 final InputLocation typeLocation;
58
59 final InputLocation sendOnErrorLocation;
60
61 final InputLocation sendOnFailureLocation;
62
63 final InputLocation sendOnSuccessLocation;
64
65 final InputLocation sendOnWarningLocation;
66
67 final InputLocation addressLocation;
68
69 final InputLocation configurationLocation;
70
71 final Map<Object, InputLocation> locations;
72
73
74
75
76
77 Notifier(
78 String type,
79 boolean sendOnError,
80 boolean sendOnFailure,
81 boolean sendOnSuccess,
82 boolean sendOnWarning,
83 String address,
84 Map<String, String> configuration,
85 Map<Object, InputLocation> locations,
86 InputLocation location,
87 InputLocation typeLocation,
88 InputLocation sendOnErrorLocation,
89 InputLocation sendOnFailureLocation,
90 InputLocation sendOnSuccessLocation,
91 InputLocation sendOnWarningLocation,
92 InputLocation addressLocation,
93 InputLocation configurationLocation
94 )
95 {
96 this.type = type;
97 this.sendOnError = sendOnError;
98 this.sendOnFailure = sendOnFailure;
99 this.sendOnSuccess = sendOnSuccess;
100 this.sendOnWarning = sendOnWarning;
101 this.address = address;
102 this.configuration = ImmutableCollections.copy( configuration );
103 this.locations = ImmutableCollections.copy( locations );
104 this.location = location;
105 this.typeLocation = typeLocation;
106 this.sendOnErrorLocation = sendOnErrorLocation;
107 this.sendOnFailureLocation = sendOnFailureLocation;
108 this.sendOnSuccessLocation = sendOnSuccessLocation;
109 this.sendOnWarningLocation = sendOnWarningLocation;
110 this.addressLocation = addressLocation;
111 this.configurationLocation = configurationLocation;
112 }
113
114
115
116
117
118
119 public String getType()
120 {
121 return this.type;
122 }
123
124
125
126
127
128
129 public boolean isSendOnError()
130 {
131 return this.sendOnError;
132 }
133
134
135
136
137
138
139 public boolean isSendOnFailure()
140 {
141 return this.sendOnFailure;
142 }
143
144
145
146
147
148
149 public boolean isSendOnSuccess()
150 {
151 return this.sendOnSuccess;
152 }
153
154
155
156
157
158
159 public boolean isSendOnWarning()
160 {
161 return this.sendOnWarning;
162 }
163
164
165
166
167
168
169 public String getAddress()
170 {
171 return this.address;
172 }
173
174
175
176
177
178
179 @Nonnull
180 public Map<String, String> getConfiguration()
181 {
182 return this.configuration;
183 }
184
185
186
187
188 public InputLocation getLocation( Object key )
189 {
190 if ( key instanceof String )
191 {
192 switch ( ( String ) key )
193 {
194 case "":
195 return location;
196 case "type":
197 return typeLocation;
198 case "sendOnError":
199 return sendOnErrorLocation;
200 case "sendOnFailure":
201 return sendOnFailureLocation;
202 case "sendOnSuccess":
203 return sendOnSuccessLocation;
204 case "sendOnWarning":
205 return sendOnWarningLocation;
206 case "address":
207 return addressLocation;
208 case "configuration":
209 return configurationLocation;
210 }
211 }
212 return locations != null ? locations.get( key ) : null;
213 }
214
215
216
217
218
219
220 @Nonnull
221 public Builder with()
222 {
223 return newBuilder( this );
224 }
225
226
227
228
229
230
231 @Nonnull
232 public Notifier withType( String type )
233 {
234 return with().type( type ).build();
235 }
236
237
238
239
240
241
242 @Nonnull
243 public Notifier withSendOnError( boolean sendOnError )
244 {
245 return with().sendOnError( sendOnError ).build();
246 }
247
248
249
250
251
252
253 @Nonnull
254 public Notifier withSendOnFailure( boolean sendOnFailure )
255 {
256 return with().sendOnFailure( sendOnFailure ).build();
257 }
258
259
260
261
262
263
264 @Nonnull
265 public Notifier withSendOnSuccess( boolean sendOnSuccess )
266 {
267 return with().sendOnSuccess( sendOnSuccess ).build();
268 }
269
270
271
272
273
274
275 @Nonnull
276 public Notifier withSendOnWarning( boolean sendOnWarning )
277 {
278 return with().sendOnWarning( sendOnWarning ).build();
279 }
280
281
282
283
284
285
286 @Nonnull
287 public Notifier withAddress( String address )
288 {
289 return with().address( address ).build();
290 }
291
292
293
294
295
296
297 @Nonnull
298 public Notifier withConfiguration( Map<String, String> configuration )
299 {
300 return with().configuration( configuration ).build();
301 }
302
303
304
305
306
307
308
309
310 @Nonnull
311 public static Notifier newInstance()
312 {
313 return newInstance( true );
314 }
315
316
317
318
319
320
321
322
323 @Nonnull
324 public static Notifier newInstance( boolean withDefaults )
325 {
326 return newBuilder( withDefaults ).build();
327 }
328
329
330
331
332
333
334
335
336 @Nonnull
337 public static Builder newBuilder()
338 {
339 return newBuilder( true );
340 }
341
342
343
344
345
346
347
348 @Nonnull
349 public static Builder newBuilder( boolean withDefaults )
350 {
351 return new Builder( withDefaults );
352 }
353
354
355
356
357
358
359
360
361 @Nonnull
362 public static Builder newBuilder( Notifier from )
363 {
364 return newBuilder( from, false );
365 }
366
367
368
369
370
371
372
373
374 @Nonnull
375 public static Builder newBuilder( Notifier from, boolean forceCopy )
376 {
377 return new Builder( from, forceCopy );
378 }
379
380
381
382
383
384
385 @NotThreadSafe
386 public static class Builder
387 {
388 Notifier base;
389 String type;
390 Boolean sendOnError;
391 Boolean sendOnFailure;
392 Boolean sendOnSuccess;
393 Boolean sendOnWarning;
394 String address;
395 Map<String, String> configuration;
396 Map<Object, InputLocation> locations;
397
398 Builder( boolean withDefaults )
399 {
400 if ( withDefaults )
401 {
402 this.type = "mail";
403 this.sendOnError = true;
404 this.sendOnFailure = true;
405 this.sendOnSuccess = true;
406 this.sendOnWarning = true;
407 }
408 }
409
410 Builder( Notifier base, boolean forceCopy )
411 {
412 if ( forceCopy )
413 {
414 this.type = base.type;
415 this.sendOnError = base.sendOnError;
416 this.sendOnFailure = base.sendOnFailure;
417 this.sendOnSuccess = base.sendOnSuccess;
418 this.sendOnWarning = base.sendOnWarning;
419 this.address = base.address;
420 this.configuration = base.configuration;
421 }
422 else
423 {
424 this.base = base;
425 }
426 }
427
428 @Nonnull
429 public Builder type( String type )
430 {
431 this.type = type;
432 return this;
433 }
434
435 @Nonnull
436 public Builder sendOnError( boolean sendOnError )
437 {
438 this.sendOnError = sendOnError;
439 return this;
440 }
441
442 @Nonnull
443 public Builder sendOnFailure( boolean sendOnFailure )
444 {
445 this.sendOnFailure = sendOnFailure;
446 return this;
447 }
448
449 @Nonnull
450 public Builder sendOnSuccess( boolean sendOnSuccess )
451 {
452 this.sendOnSuccess = sendOnSuccess;
453 return this;
454 }
455
456 @Nonnull
457 public Builder sendOnWarning( boolean sendOnWarning )
458 {
459 this.sendOnWarning = sendOnWarning;
460 return this;
461 }
462
463 @Nonnull
464 public Builder address( String address )
465 {
466 this.address = address;
467 return this;
468 }
469
470 @Nonnull
471 public Builder configuration( Map<String, String> configuration )
472 {
473 this.configuration = configuration;
474 return this;
475 }
476
477
478 @Nonnull
479 public Builder location( Object key, InputLocation location )
480 {
481 if ( location != null )
482 {
483 if ( this.locations == null )
484 {
485 this.locations = new HashMap<>();
486 }
487 this.locations.put( key, location );
488 }
489 return this;
490 }
491
492 @Nonnull
493 public Notifier build()
494 {
495 if ( base != null
496 && ( type == null || type == base.type )
497 && ( sendOnError == null || sendOnError == base.sendOnError )
498 && ( sendOnFailure == null || sendOnFailure == base.sendOnFailure )
499 && ( sendOnSuccess == null || sendOnSuccess == base.sendOnSuccess )
500 && ( sendOnWarning == null || sendOnWarning == base.sendOnWarning )
501 && ( address == null || address == base.address )
502 && ( configuration == null || configuration == base.configuration )
503 )
504 {
505 return base;
506 }
507 Map<Object, InputLocation> locations = null;
508 InputLocation location = null;
509 InputLocation typeLocation = null;
510 InputLocation sendOnErrorLocation = null;
511 InputLocation sendOnFailureLocation = null;
512 InputLocation sendOnSuccessLocation = null;
513 InputLocation sendOnWarningLocation = null;
514 InputLocation addressLocation = null;
515 InputLocation configurationLocation = null;
516 if ( this.locations != null )
517 {
518 locations = this.locations;
519 location = locations.remove( "" );
520 typeLocation = locations.remove( "type" );
521 sendOnErrorLocation = locations.remove( "sendOnError" );
522 sendOnFailureLocation = locations.remove( "sendOnFailure" );
523 sendOnSuccessLocation = locations.remove( "sendOnSuccess" );
524 sendOnWarningLocation = locations.remove( "sendOnWarning" );
525 addressLocation = locations.remove( "address" );
526 configurationLocation = locations.remove( "configuration" );
527 }
528 return new Notifier(
529 type != null ? type : ( base != null ? base.type : null ),
530 sendOnError != null ? sendOnError : ( base != null ? base.sendOnError : true ),
531 sendOnFailure != null ? sendOnFailure : ( base != null ? base.sendOnFailure : true ),
532 sendOnSuccess != null ? sendOnSuccess : ( base != null ? base.sendOnSuccess : true ),
533 sendOnWarning != null ? sendOnWarning : ( base != null ? base.sendOnWarning : true ),
534 address != null ? address : ( base != null ? base.address : null ),
535 configuration != null ? configuration : ( base != null ? base.configuration : null ),
536 locations != null ? locations : ( base != null ? base.locations : null ),
537 location != null ? location : ( base != null ? base.location : null ),
538 typeLocation != null ? typeLocation : ( base != null ? base.typeLocation : null ),
539 sendOnErrorLocation != null ? sendOnErrorLocation : ( base != null ? base.sendOnErrorLocation : null ),
540 sendOnFailureLocation != null ? sendOnFailureLocation : ( base != null ? base.sendOnFailureLocation : null ),
541 sendOnSuccessLocation != null ? sendOnSuccessLocation : ( base != null ? base.sendOnSuccessLocation : null ),
542 sendOnWarningLocation != null ? sendOnWarningLocation : ( base != null ? base.sendOnWarningLocation : null ),
543 addressLocation != null ? addressLocation : ( base != null ? base.addressLocation : null ),
544 configurationLocation != null ? configurationLocation : ( base != null ? base.configurationLocation : null )
545 );
546 }
547 }
548
549 }