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      {
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       * The mechanism used to deliver notifications.
84       *
85       * @return a {@code String}
86       */
87      public String getType()
88      {
89          return this.type;
90      }
91  
92      /**
93       * Whether to send notifications on error.
94       *
95       * @return a {@code boolean}
96       */
97      public boolean isSendOnError()
98      {
99          return this.sendOnError;
100     }
101 
102     /**
103      * Whether to send notifications on failure.
104      *
105      * @return a {@code boolean}
106      */
107     public boolean isSendOnFailure()
108     {
109         return this.sendOnFailure;
110     }
111 
112     /**
113      * Whether to send notifications on success.
114      *
115      * @return a {@code boolean}
116      */
117     public boolean isSendOnSuccess()
118     {
119         return this.sendOnSuccess;
120     }
121 
122     /**
123      * Whether to send notifications on warning.
124      *
125      * @return a {@code boolean}
126      */
127     public boolean isSendOnWarning()
128     {
129         return this.sendOnWarning;
130     }
131 
132     /**
133      * <b>Deprecated</b>. Where to send the notification to - eg email address.
134      *
135      * @return a {@code String}
136      */
137     public String getAddress()
138     {
139         return this.address;
140     }
141 
142     /**
143      * Extended configuration specific to this notifier goes here.
144      *
145      * @return a {@code Map<String, String>}
146      */
147     @Nonnull
148     public Map<String, String> getConfiguration()
149     {
150         return this.configuration;
151     }
152 
153     /**
154      * Gets the location of the specified field in the input source.
155      */
156     public InputLocation getLocation( Object key )
157     {
158         return locations != null ? locations.get( key ) : null;
159     }
160 
161     /**
162      * Creates a new builder with this object as the basis.
163      *
164      * @return a {@code Builder}
165      */
166     @Nonnull
167     public Builder with()
168     {
169         return newBuilder( this );
170     }
171     /**
172      * Creates a new {@code Notifier} instance using the specified type.
173      *
174      * @param type the new {@code String} to use
175      * @return a {@code Notifier} with the specified type
176      */
177     @Nonnull
178     public Notifier withType( String type )
179     {
180         return newBuilder(this, true).type( type ).build();
181     }
182     /**
183      * Creates a new {@code Notifier} instance using the specified sendOnError.
184      *
185      * @param sendOnError the new {@code boolean} to use
186      * @return a {@code Notifier} with the specified sendOnError
187      */
188     @Nonnull
189     public Notifier withSendOnError( boolean sendOnError )
190     {
191         return newBuilder(this, true).sendOnError( sendOnError ).build();
192     }
193     /**
194      * Creates a new {@code Notifier} instance using the specified sendOnFailure.
195      *
196      * @param sendOnFailure the new {@code boolean} to use
197      * @return a {@code Notifier} with the specified sendOnFailure
198      */
199     @Nonnull
200     public Notifier withSendOnFailure( boolean sendOnFailure )
201     {
202         return newBuilder(this, true).sendOnFailure( sendOnFailure ).build();
203     }
204     /**
205      * Creates a new {@code Notifier} instance using the specified sendOnSuccess.
206      *
207      * @param sendOnSuccess the new {@code boolean} to use
208      * @return a {@code Notifier} with the specified sendOnSuccess
209      */
210     @Nonnull
211     public Notifier withSendOnSuccess( boolean sendOnSuccess )
212     {
213         return newBuilder(this, true).sendOnSuccess( sendOnSuccess ).build();
214     }
215     /**
216      * Creates a new {@code Notifier} instance using the specified sendOnWarning.
217      *
218      * @param sendOnWarning the new {@code boolean} to use
219      * @return a {@code Notifier} with the specified sendOnWarning
220      */
221     @Nonnull
222     public Notifier withSendOnWarning( boolean sendOnWarning )
223     {
224         return newBuilder(this, true).sendOnWarning( sendOnWarning ).build();
225     }
226     /**
227      * Creates a new {@code Notifier} instance using the specified address.
228      *
229      * @param address the new {@code String} to use
230      * @return a {@code Notifier} with the specified address
231      */
232     @Nonnull
233     public Notifier withAddress( String address )
234     {
235         return newBuilder(this, true).address( address ).build();
236     }
237     /**
238      * Creates a new {@code Notifier} instance using the specified configuration.
239      *
240      * @param configuration the new {@code Map<String, String>} to use
241      * @return a {@code Notifier} with the specified configuration
242      */
243     @Nonnull
244     public Notifier withConfiguration( Map<String, String> configuration )
245     {
246         return newBuilder(this, true).configuration( configuration ).build();
247     }
248 
249     /**
250      * Creates a new {@code Notifier} instance.
251      * Equivalent to {@code newInstance( true )}.
252      * @see #newInstance(boolean)
253      *
254      * @return a new {@code Notifier}
255      */
256     @Nonnull
257     public static Notifier newInstance()
258     {
259         return newInstance( true );
260     }
261 
262     /**
263      * Creates a new {@code Notifier} instance using default values or not.
264      * Equivalent to {@code newBuilder( withDefaults ).build()}.
265      *
266      * @param withDefaults the boolean indicating whether default values should be used
267      * @return a new {@code Notifier}
268      */
269     @Nonnull
270     public static Notifier newInstance( boolean withDefaults )
271     {
272         return newBuilder( withDefaults ).build();
273     }
274 
275     /**
276      * Creates a new {@code Notifier} builder instance.
277      * Equivalent to {@code newBuilder( true )}.
278      * @see #newBuilder(boolean)
279      *
280      * @return a new {@code Builder}
281      */
282     @Nonnull
283     public static Builder newBuilder()
284     {
285         return newBuilder( true );
286     }
287 
288     /**
289      * Creates a new {@code Notifier} builder instance using default values or not.
290      *
291      * @param withDefaults the boolean indicating whether default values should be used
292      * @return a new {@code Builder}
293      */
294     @Nonnull
295     public static Builder newBuilder( boolean withDefaults )
296     {
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     {
310         return newBuilder( from, false );
311     }
312 
313     /**
314      * Creates a new {@code Notifier} builder instance using the specified object as a basis.
315      *
316      * @param from the {@code Notifier} instance to use as a basis
317      * @param forceCopy the boolean indicating if a copy should be forced
318      * @return a new {@code Builder}
319      */
320     @Nonnull
321     public static Builder newBuilder( Notifier from, boolean forceCopy )
322     {
323         return new Builder( from, forceCopy );
324     }
325 
326     /**
327      * Builder class used to create Notifier instances.
328      * @see #with()
329      * @see #newBuilder()
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 }