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      /** Location of the xml element for this object. */
55      final InputLocation location;
56      /** Location of the xml element for the field type. */
57      final InputLocation typeLocation;
58      /** Location of the xml element for the field sendOnError. */
59      final InputLocation sendOnErrorLocation;
60      /** Location of the xml element for the field sendOnFailure. */
61      final InputLocation sendOnFailureLocation;
62      /** Location of the xml element for the field sendOnSuccess. */
63      final InputLocation sendOnSuccessLocation;
64      /** Location of the xml element for the field sendOnWarning. */
65      final InputLocation sendOnWarningLocation;
66      /** Location of the xml element for the field address. */
67      final InputLocation addressLocation;
68      /** Location of the xml element for the field configuration. */
69      final InputLocation configurationLocation;
70      /** Other locations */
71      final Map<Object, InputLocation> locations;
72  
73      /**
74        * Constructor for this class, package protected.
75        * @see Builder#build()
76        */
77      Notifier(
78          String type,
79          boolean sendOnError,
80          boolean sendOnFailure,
81          boolean sendOnSuccess,
82          boolean sendOnWarning,
83          String address,
84          Map<String, String> configuration,
85          Map<Object, InputLocation> locations,
86          InputLocation location,
87          InputLocation typeLocation,
88          InputLocation sendOnErrorLocation,
89          InputLocation sendOnFailureLocation,
90          InputLocation sendOnSuccessLocation,
91          InputLocation sendOnWarningLocation,
92          InputLocation addressLocation,
93          InputLocation configurationLocation
94      )
95      {
96          this.type = type;
97          this.sendOnError = sendOnError;
98          this.sendOnFailure = sendOnFailure;
99          this.sendOnSuccess = sendOnSuccess;
100         this.sendOnWarning = sendOnWarning;
101         this.address = address;
102         this.configuration = ImmutableCollections.copy( configuration );
103         this.locations = ImmutableCollections.copy( locations );
104         this.location = location;
105         this.typeLocation = typeLocation;
106         this.sendOnErrorLocation = sendOnErrorLocation;
107         this.sendOnFailureLocation = sendOnFailureLocation;
108         this.sendOnSuccessLocation = sendOnSuccessLocation;
109         this.sendOnWarningLocation = sendOnWarningLocation;
110         this.addressLocation = addressLocation;
111         this.configurationLocation = configurationLocation;
112     }
113 
114     /**
115      * The mechanism used to deliver notifications.
116      *
117      * @return a {@code String}
118      */
119     public String getType()
120     {
121         return this.type;
122     }
123 
124     /**
125      * Whether to send notifications on error.
126      *
127      * @return a {@code boolean}
128      */
129     public boolean isSendOnError()
130     {
131         return this.sendOnError;
132     }
133 
134     /**
135      * Whether to send notifications on failure.
136      *
137      * @return a {@code boolean}
138      */
139     public boolean isSendOnFailure()
140     {
141         return this.sendOnFailure;
142     }
143 
144     /**
145      * Whether to send notifications on success.
146      *
147      * @return a {@code boolean}
148      */
149     public boolean isSendOnSuccess()
150     {
151         return this.sendOnSuccess;
152     }
153 
154     /**
155      * Whether to send notifications on warning.
156      *
157      * @return a {@code boolean}
158      */
159     public boolean isSendOnWarning()
160     {
161         return this.sendOnWarning;
162     }
163 
164     /**
165      * <b>Deprecated</b>. Where to send the notification to - eg email address.
166      *
167      * @return a {@code String}
168      */
169     public String getAddress()
170     {
171         return this.address;
172     }
173 
174     /**
175      * Extended configuration specific to this notifier goes here.
176      *
177      * @return a {@code Map<String, String>}
178      */
179     @Nonnull
180     public Map<String, String> getConfiguration()
181     {
182         return this.configuration;
183     }
184 
185     /**
186      * Gets the location of the specified field in the input source.
187      */
188     public InputLocation getLocation( Object key )
189     {
190         if ( key instanceof String )
191         {
192             switch ( ( String ) key )
193             {
194                 case "":
195                     return location;
196                 case "type":
197                     return typeLocation;
198                 case "sendOnError":
199                     return sendOnErrorLocation;
200                 case "sendOnFailure":
201                     return sendOnFailureLocation;
202                 case "sendOnSuccess":
203                     return sendOnSuccessLocation;
204                 case "sendOnWarning":
205                     return sendOnWarningLocation;
206                 case "address":
207                     return addressLocation;
208                 case "configuration":
209                     return configurationLocation;
210             }
211         }
212         return locations != null ? locations.get( key ) : null;
213     }
214 
215     /**
216      * Creates a new builder with this object as the basis.
217      *
218      * @return a {@code Builder}
219      */
220     @Nonnull
221     public Builder with()
222     {
223         return newBuilder( this );
224     }
225     /**
226      * Creates a new {@code Notifier} instance using the specified type.
227      *
228      * @param type the new {@code String} to use
229      * @return a {@code Notifier} with the specified type
230      */
231     @Nonnull
232     public Notifier withType( String type )
233     {
234         return with().type( type ).build();
235     }
236     /**
237      * Creates a new {@code Notifier} instance using the specified sendOnError.
238      *
239      * @param sendOnError the new {@code boolean} to use
240      * @return a {@code Notifier} with the specified sendOnError
241      */
242     @Nonnull
243     public Notifier withSendOnError( boolean sendOnError )
244     {
245         return with().sendOnError( sendOnError ).build();
246     }
247     /**
248      * Creates a new {@code Notifier} instance using the specified sendOnFailure.
249      *
250      * @param sendOnFailure the new {@code boolean} to use
251      * @return a {@code Notifier} with the specified sendOnFailure
252      */
253     @Nonnull
254     public Notifier withSendOnFailure( boolean sendOnFailure )
255     {
256         return with().sendOnFailure( sendOnFailure ).build();
257     }
258     /**
259      * Creates a new {@code Notifier} instance using the specified sendOnSuccess.
260      *
261      * @param sendOnSuccess the new {@code boolean} to use
262      * @return a {@code Notifier} with the specified sendOnSuccess
263      */
264     @Nonnull
265     public Notifier withSendOnSuccess( boolean sendOnSuccess )
266     {
267         return with().sendOnSuccess( sendOnSuccess ).build();
268     }
269     /**
270      * Creates a new {@code Notifier} instance using the specified sendOnWarning.
271      *
272      * @param sendOnWarning the new {@code boolean} to use
273      * @return a {@code Notifier} with the specified sendOnWarning
274      */
275     @Nonnull
276     public Notifier withSendOnWarning( boolean sendOnWarning )
277     {
278         return with().sendOnWarning( sendOnWarning ).build();
279     }
280     /**
281      * Creates a new {@code Notifier} instance using the specified address.
282      *
283      * @param address the new {@code String} to use
284      * @return a {@code Notifier} with the specified address
285      */
286     @Nonnull
287     public Notifier withAddress( String address )
288     {
289         return with().address( address ).build();
290     }
291     /**
292      * Creates a new {@code Notifier} instance using the specified configuration.
293      *
294      * @param configuration the new {@code Map<String, String>} to use
295      * @return a {@code Notifier} with the specified configuration
296      */
297     @Nonnull
298     public Notifier withConfiguration( Map<String, String> configuration )
299     {
300         return with().configuration( configuration ).build();
301     }
302 
303     /**
304      * Creates a new {@code Notifier} instance.
305      * Equivalent to {@code newInstance( true )}.
306      * @see #newInstance(boolean)
307      *
308      * @return a new {@code Notifier}
309      */
310     @Nonnull
311     public static Notifier newInstance()
312     {
313         return newInstance( true );
314     }
315 
316     /**
317      * Creates a new {@code Notifier} instance using default values or not.
318      * Equivalent to {@code newBuilder( withDefaults ).build()}.
319      *
320      * @param withDefaults the boolean indicating whether default values should be used
321      * @return a new {@code Notifier}
322      */
323     @Nonnull
324     public static Notifier newInstance( boolean withDefaults )
325     {
326         return newBuilder( withDefaults ).build();
327     }
328 
329     /**
330      * Creates a new {@code Notifier} builder instance.
331      * Equivalent to {@code newBuilder( true )}.
332      * @see #newBuilder(boolean)
333      *
334      * @return a new {@code Builder}
335      */
336     @Nonnull
337     public static Builder newBuilder()
338     {
339         return newBuilder( true );
340     }
341 
342     /**
343      * Creates a new {@code Notifier} builder instance using default values or not.
344      *
345      * @param withDefaults the boolean indicating whether default values should be used
346      * @return a new {@code Builder}
347      */
348     @Nonnull
349     public static Builder newBuilder( boolean withDefaults )
350     {
351         return new Builder( withDefaults );
352     }
353 
354     /**
355      * Creates a new {@code Notifier} builder instance using the specified object as a basis.
356      * Equivalent to {@code newBuilder( from, false )}.
357      *
358      * @param from the {@code Notifier} instance to use as a basis
359      * @return a new {@code Builder}
360      */
361     @Nonnull
362     public static Builder newBuilder( Notifier from )
363     {
364         return newBuilder( from, false );
365     }
366 
367     /**
368      * Creates a new {@code Notifier} builder instance using the specified object as a basis.
369      *
370      * @param from the {@code Notifier} instance to use as a basis
371      * @param forceCopy the boolean indicating if a copy should be forced
372      * @return a new {@code Builder}
373      */
374     @Nonnull
375     public static Builder newBuilder( Notifier from, boolean forceCopy )
376     {
377         return new Builder( from, forceCopy );
378     }
379 
380     /**
381      * Builder class used to create Notifier instances.
382      * @see #with()
383      * @see #newBuilder()
384      */
385     @NotThreadSafe
386     public static class Builder
387     {
388         Notifier base;
389         String type;
390         Boolean sendOnError;
391         Boolean sendOnFailure;
392         Boolean sendOnSuccess;
393         Boolean sendOnWarning;
394         String address;
395         Map<String, String> configuration;
396         Map<Object, InputLocation> locations;
397 
398         Builder( boolean withDefaults )
399         {
400             if ( withDefaults )
401             {
402                 this.type = "mail";
403                 this.sendOnError = true;
404                 this.sendOnFailure = true;
405                 this.sendOnSuccess = true;
406                 this.sendOnWarning = true;
407             }
408         }
409 
410         Builder( Notifier base, boolean forceCopy )
411         {
412             if ( forceCopy )
413             {
414                 this.type = base.type;
415                 this.sendOnError = base.sendOnError;
416                 this.sendOnFailure = base.sendOnFailure;
417                 this.sendOnSuccess = base.sendOnSuccess;
418                 this.sendOnWarning = base.sendOnWarning;
419                 this.address = base.address;
420                 this.configuration = base.configuration;
421             }
422             else
423             {
424                 this.base = base;
425             }
426         }
427 
428         @Nonnull
429         public Builder type( String type )
430         {
431             this.type = type;
432             return this;
433         }
434 
435         @Nonnull
436         public Builder sendOnError( boolean sendOnError )
437         {
438             this.sendOnError = sendOnError;
439             return this;
440         }
441 
442         @Nonnull
443         public Builder sendOnFailure( boolean sendOnFailure )
444         {
445             this.sendOnFailure = sendOnFailure;
446             return this;
447         }
448 
449         @Nonnull
450         public Builder sendOnSuccess( boolean sendOnSuccess )
451         {
452             this.sendOnSuccess = sendOnSuccess;
453             return this;
454         }
455 
456         @Nonnull
457         public Builder sendOnWarning( boolean sendOnWarning )
458         {
459             this.sendOnWarning = sendOnWarning;
460             return this;
461         }
462 
463         @Nonnull
464         public Builder address( String address )
465         {
466             this.address = address;
467             return this;
468         }
469 
470         @Nonnull
471         public Builder configuration( Map<String, String> configuration )
472         {
473             this.configuration = configuration;
474             return this;
475         }
476 
477 
478         @Nonnull
479         public Builder location( Object key, InputLocation location )
480         {
481             if ( location != null )
482             {
483                 if ( this.locations == null )
484                 {
485                     this.locations = new HashMap<>();
486                 }
487                 this.locations.put( key, location );
488             }
489             return this;
490         }
491 
492         @Nonnull
493         public Notifier build()
494         {
495             if ( base != null
496                     && ( type == null || type == base.type )
497                     && ( sendOnError == null || sendOnError == base.sendOnError )
498                     && ( sendOnFailure == null || sendOnFailure == base.sendOnFailure )
499                     && ( sendOnSuccess == null || sendOnSuccess == base.sendOnSuccess )
500                     && ( sendOnWarning == null || sendOnWarning == base.sendOnWarning )
501                     && ( address == null || address == base.address )
502                     && ( configuration == null || configuration == base.configuration )
503             )
504             {
505                 return base;
506             }
507             Map<Object, InputLocation> locations = null;
508             InputLocation location = null;
509             InputLocation typeLocation = null;
510             InputLocation sendOnErrorLocation = null;
511             InputLocation sendOnFailureLocation = null;
512             InputLocation sendOnSuccessLocation = null;
513             InputLocation sendOnWarningLocation = null;
514             InputLocation addressLocation = null;
515             InputLocation configurationLocation = null;
516             if ( this.locations != null )
517             {
518                 locations = this.locations;
519                 location = locations.remove( "" );
520                 typeLocation = locations.remove( "type" );
521                 sendOnErrorLocation = locations.remove( "sendOnError" );
522                 sendOnFailureLocation = locations.remove( "sendOnFailure" );
523                 sendOnSuccessLocation = locations.remove( "sendOnSuccess" );
524                 sendOnWarningLocation = locations.remove( "sendOnWarning" );
525                 addressLocation = locations.remove( "address" );
526                 configurationLocation = locations.remove( "configuration" );
527             }
528             return new Notifier(
529                 type != null ? type : ( base != null ? base.type : null ),
530                 sendOnError != null ? sendOnError : ( base != null ? base.sendOnError : true ),
531                 sendOnFailure != null ? sendOnFailure : ( base != null ? base.sendOnFailure : true ),
532                 sendOnSuccess != null ? sendOnSuccess : ( base != null ? base.sendOnSuccess : true ),
533                 sendOnWarning != null ? sendOnWarning : ( base != null ? base.sendOnWarning : true ),
534                 address != null ? address : ( base != null ? base.address : null ),
535                 configuration != null ? configuration : ( base != null ? base.configuration : null ),
536                 locations != null ? locations : ( base != null ? base.locations : null ),
537                 location != null ? location : ( base != null ? base.location : null ),
538                 typeLocation != null ? typeLocation : ( base != null ? base.typeLocation : null ),
539                 sendOnErrorLocation != null ? sendOnErrorLocation : ( base != null ? base.sendOnErrorLocation : null ),
540                 sendOnFailureLocation != null ? sendOnFailureLocation : ( base != null ? base.sendOnFailureLocation : null ),
541                 sendOnSuccessLocation != null ? sendOnSuccessLocation : ( base != null ? base.sendOnSuccessLocation : null ),
542                 sendOnWarningLocation != null ? sendOnWarningLocation : ( base != null ? base.sendOnWarningLocation : null ),
543                 addressLocation != null ? addressLocation : ( base != null ? base.addressLocation : null ),
544                 configurationLocation != null ? configurationLocation : ( base != null ? base.configurationLocation : null )
545             );
546         }
547     }
548 
549 }