View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   //  Generated by Modello Velocity from model.vm
3   //  template, any modifications will be overwritten.
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   * Configures one method for notifying users/developers when a build breaks.
20   */
21  @Experimental
22  @Generated @ThreadSafe @Immutable
23  public class Notifier
24      implements Serializable, InputLocationTracker
25  {
26      /**
27       * The mechanism used to deliver notifications.
28       */
29      final String type;
30      /**
31       * Whether to send notifications on error.
32       */
33      final boolean sendOnError;
34      /**
35       * Whether to send notifications on failure.
36       */
37      final boolean sendOnFailure;
38      /**
39       * Whether to send notifications on success.
40       */
41      final boolean sendOnSuccess;
42      /**
43       * Whether to send notifications on warning.
44       */
45      final boolean sendOnWarning;
46      /**
47       * <b>Deprecated</b>. Where to send the notification to - eg email address.
48       */
49      final String address;
50      /**
51       * Extended configuration specific to this notifier goes here.
52       */
53      final Map<String, String> configuration;
54      /** Locations */
55      final Map<Object, InputLocation> locations;
56  
57      /**
58        * Constructor for this class, package protected.
59        * @see Builder#build()
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       * The mechanism used to deliver notifications.
83       *
84       * @return a {@code String}
85       */
86      public String getType() {
87          return this.type;
88      }
89  
90      /**
91       * Whether to send notifications on error.
92       *
93       * @return a {@code boolean}
94       */
95      public boolean isSendOnError() {
96          return this.sendOnError;
97      }
98  
99      /**
100      * Whether to send notifications on failure.
101      *
102      * @return a {@code boolean}
103      */
104     public boolean isSendOnFailure() {
105         return this.sendOnFailure;
106     }
107 
108     /**
109      * Whether to send notifications on success.
110      *
111      * @return a {@code boolean}
112      */
113     public boolean isSendOnSuccess() {
114         return this.sendOnSuccess;
115     }
116 
117     /**
118      * Whether to send notifications on warning.
119      *
120      * @return a {@code boolean}
121      */
122     public boolean isSendOnWarning() {
123         return this.sendOnWarning;
124     }
125 
126     /**
127      * <b>Deprecated</b>. Where to send the notification to - eg email address.
128      *
129      * @return a {@code String}
130      */
131     public String getAddress() {
132         return this.address;
133     }
134 
135     /**
136      * Extended configuration specific to this notifier goes here.
137      *
138      * @return a {@code Map<String, String>}
139      */
140     @Nonnull
141     public Map<String, String> getConfiguration() {
142         return this.configuration;
143     }
144 
145     /**
146      * Gets the location of the specified field in the input source.
147      */
148     public InputLocation getLocation(Object key) {
149         return locations != null ? locations.get(key) : null;
150     }
151 
152     /**
153      * Creates a new builder with this object as the basis.
154      *
155      * @return a {@code Builder}
156      */
157     @Nonnull
158     public Builder with() {
159         return newBuilder(this);
160     }
161     /**
162      * Creates a new {@code Notifier} instance using the specified type.
163      *
164      * @param type the new {@code String} to use
165      * @return a {@code Notifier} with the specified type
166      */
167     @Nonnull
168     public Notifier withType(String type) {
169         return newBuilder(this, true).type(type).build();
170     }
171     /**
172      * Creates a new {@code Notifier} instance using the specified sendOnError.
173      *
174      * @param sendOnError the new {@code boolean} to use
175      * @return a {@code Notifier} with the specified sendOnError
176      */
177     @Nonnull
178     public Notifier withSendOnError(boolean sendOnError) {
179         return newBuilder(this, true).sendOnError(sendOnError).build();
180     }
181     /**
182      * Creates a new {@code Notifier} instance using the specified sendOnFailure.
183      *
184      * @param sendOnFailure the new {@code boolean} to use
185      * @return a {@code Notifier} with the specified sendOnFailure
186      */
187     @Nonnull
188     public Notifier withSendOnFailure(boolean sendOnFailure) {
189         return newBuilder(this, true).sendOnFailure(sendOnFailure).build();
190     }
191     /**
192      * Creates a new {@code Notifier} instance using the specified sendOnSuccess.
193      *
194      * @param sendOnSuccess the new {@code boolean} to use
195      * @return a {@code Notifier} with the specified sendOnSuccess
196      */
197     @Nonnull
198     public Notifier withSendOnSuccess(boolean sendOnSuccess) {
199         return newBuilder(this, true).sendOnSuccess(sendOnSuccess).build();
200     }
201     /**
202      * Creates a new {@code Notifier} instance using the specified sendOnWarning.
203      *
204      * @param sendOnWarning the new {@code boolean} to use
205      * @return a {@code Notifier} with the specified sendOnWarning
206      */
207     @Nonnull
208     public Notifier withSendOnWarning(boolean sendOnWarning) {
209         return newBuilder(this, true).sendOnWarning(sendOnWarning).build();
210     }
211     /**
212      * Creates a new {@code Notifier} instance using the specified address.
213      *
214      * @param address the new {@code String} to use
215      * @return a {@code Notifier} with the specified address
216      */
217     @Nonnull
218     public Notifier withAddress(String address) {
219         return newBuilder(this, true).address(address).build();
220     }
221     /**
222      * Creates a new {@code Notifier} instance using the specified configuration.
223      *
224      * @param configuration the new {@code Map<String, String>} to use
225      * @return a {@code Notifier} with the specified configuration
226      */
227     @Nonnull
228     public Notifier withConfiguration(Map<String, String> configuration) {
229         return newBuilder(this, true).configuration(configuration).build();
230     }
231 
232     /**
233      * Creates a new {@code Notifier} instance.
234      * Equivalent to {@code newInstance(true)}.
235      * @see #newInstance(boolean)
236      *
237      * @return a new {@code Notifier}
238      */
239     @Nonnull
240     public static Notifier newInstance() {
241         return newInstance(true);
242     }
243 
244     /**
245      * Creates a new {@code Notifier} instance using default values or not.
246      * Equivalent to {@code newBuilder(withDefaults).build()}.
247      *
248      * @param withDefaults the boolean indicating whether default values should be used
249      * @return a new {@code Notifier}
250      */
251     @Nonnull
252     public static Notifier newInstance(boolean withDefaults) {
253         return newBuilder(withDefaults).build();
254     }
255 
256     /**
257      * Creates a new {@code Notifier} builder instance.
258      * Equivalent to {@code newBuilder(true)}.
259      * @see #newBuilder(boolean)
260      *
261      * @return a new {@code Builder}
262      */
263     @Nonnull
264     public static Builder newBuilder() {
265         return newBuilder(true);
266     }
267 
268     /**
269      * Creates a new {@code Notifier} builder instance using default values or not.
270      *
271      * @param withDefaults the boolean indicating whether default values should be used
272      * @return a new {@code Builder}
273      */
274     @Nonnull
275     public static Builder newBuilder(boolean withDefaults) {
276         return new Builder(withDefaults);
277     }
278 
279     /**
280      * Creates a new {@code Notifier} builder instance using the specified object as a basis.
281      * Equivalent to {@code newBuilder(from, false)}.
282      *
283      * @param from the {@code Notifier} instance to use as a basis
284      * @return a new {@code Builder}
285      */
286     @Nonnull
287     public static Builder newBuilder(Notifier from) {
288         return newBuilder(from, false);
289     }
290 
291     /**
292      * Creates a new {@code Notifier} builder instance using the specified object as a basis.
293      *
294      * @param from the {@code Notifier} instance to use as a basis
295      * @param forceCopy the boolean indicating if a copy should be forced
296      * @return a new {@code Builder}
297      */
298     @Nonnull
299     public static Builder newBuilder(Notifier from, boolean forceCopy) {
300         return new Builder(from, forceCopy);
301     }
302 
303     /**
304      * Builder class used to create Notifier instances.
305      * @see #with()
306      * @see #newBuilder()
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 }