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