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