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