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