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