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