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.ArrayList;
9   import java.util.Collection;
10  import java.util.Collections;
11  import java.util.HashMap;
12  import java.util.List;
13  import java.util.Map;
14  import org.apache.maven.api.annotations.Experimental;
15  import org.apache.maven.api.annotations.Generated;
16  import org.apache.maven.api.annotations.Immutable;
17  import org.apache.maven.api.annotations.Nonnull;
18  import org.apache.maven.api.annotations.NotThreadSafe;
19  import org.apache.maven.api.annotations.ThreadSafe;
20  
21  /**
22   * The {@code <ciManagement>} element contains informations required to the
23   * continuous integration system of the project.
24   */
25  @Experimental
26  @Generated @ThreadSafe @Immutable
27  public class CiManagement
28      implements Serializable, InputLocationTracker
29  {
30      /**
31       * The name of the continuous integration system, e.g. {@code continuum}.
32       */
33      final String system;
34      /**
35       * URL for the continuous integration system used by the project if it has a web
36       * interface.
37       */
38      final String url;
39      /**
40       * Configuration for notifying developers/users when a build is unsuccessful,
41       * including user information and notification mode.
42       */
43      final List<Notifier> notifiers;
44      /** Location of the xml element for this object. */
45      final InputLocation location;
46      /** Location of the xml element for the field system. */
47      final InputLocation systemLocation;
48      /** Location of the xml element for the field url. */
49      final InputLocation urlLocation;
50      /** Location of the xml element for the field notifiers. */
51      final InputLocation notifiersLocation;
52      /** Other locations */
53      final Map<Object, InputLocation> locations;
54  
55      /**
56        * Constructor for this class, package protected.
57        * @see Builder#build()
58        */
59      CiManagement(
60          String system,
61          String url,
62          Collection<Notifier> notifiers,
63          Map<Object, InputLocation> locations,
64          InputLocation location,
65          InputLocation systemLocation,
66          InputLocation urlLocation,
67          InputLocation notifiersLocation
68      )
69      {
70          this.system = system;
71          this.url = url;
72          this.notifiers = ImmutableCollections.copy( notifiers );
73          this.locations = ImmutableCollections.copy( locations );
74          this.location = location;
75          this.systemLocation = systemLocation;
76          this.urlLocation = urlLocation;
77          this.notifiersLocation = notifiersLocation;
78      }
79  
80      /**
81       * The name of the continuous integration system, e.g. {@code continuum}.
82       *
83       * @return a {@code String}
84       */
85      public String getSystem()
86      {
87          return this.system;
88      }
89  
90      /**
91       * URL for the continuous integration system used by the project if it has a web
92       * interface.
93       *
94       * @return a {@code String}
95       */
96      public String getUrl()
97      {
98          return this.url;
99      }
100 
101     /**
102      * Configuration for notifying developers/users when a build is unsuccessful,
103      * including user information and notification mode.
104      *
105      * @return a {@code List<Notifier>}
106      */
107     @Nonnull
108     public List<Notifier> getNotifiers()
109     {
110         return this.notifiers;
111     }
112 
113     /**
114      * Gets the location of the specified field in the input source.
115      */
116     public InputLocation getLocation( Object key )
117     {
118         if ( key instanceof String )
119         {
120             switch ( ( String ) key )
121             {
122                 case "":
123                     return location;
124                 case "system":
125                     return systemLocation;
126                 case "url":
127                     return urlLocation;
128                 case "notifiers":
129                     return notifiersLocation;
130             }
131         }
132         return locations != null ? locations.get( key ) : null;
133     }
134 
135     /**
136      * Creates a new builder with this object as the basis.
137      *
138      * @return a {@code Builder}
139      */
140     @Nonnull
141     public Builder with()
142     {
143         return newBuilder( this );
144     }
145     /**
146      * Creates a new {@code CiManagement} instance using the specified system.
147      *
148      * @param system the new {@code String} to use
149      * @return a {@code CiManagement} with the specified system
150      */
151     @Nonnull
152     public CiManagement withSystem( String system )
153     {
154         return with().system( system ).build();
155     }
156     /**
157      * Creates a new {@code CiManagement} instance using the specified url.
158      *
159      * @param url the new {@code String} to use
160      * @return a {@code CiManagement} with the specified url
161      */
162     @Nonnull
163     public CiManagement withUrl( String url )
164     {
165         return with().url( url ).build();
166     }
167     /**
168      * Creates a new {@code CiManagement} instance using the specified notifiers.
169      *
170      * @param notifiers the new {@code Collection<Notifier>} to use
171      * @return a {@code CiManagement} with the specified notifiers
172      */
173     @Nonnull
174     public CiManagement withNotifiers( Collection<Notifier> notifiers )
175     {
176         return with().notifiers( notifiers ).build();
177     }
178 
179     /**
180      * Creates a new {@code CiManagement} instance.
181      * Equivalent to {@code newInstance( true )}.
182      * @see #newInstance(boolean)
183      *
184      * @return a new {@code CiManagement}
185      */
186     @Nonnull
187     public static CiManagement newInstance()
188     {
189         return newInstance( true );
190     }
191 
192     /**
193      * Creates a new {@code CiManagement} instance using default values or not.
194      * Equivalent to {@code newBuilder( withDefaults ).build()}.
195      *
196      * @param withDefaults the boolean indicating whether default values should be used
197      * @return a new {@code CiManagement}
198      */
199     @Nonnull
200     public static CiManagement newInstance( boolean withDefaults )
201     {
202         return newBuilder( withDefaults ).build();
203     }
204 
205     /**
206      * Creates a new {@code CiManagement} builder instance.
207      * Equivalent to {@code newBuilder( true )}.
208      * @see #newBuilder(boolean)
209      *
210      * @return a new {@code Builder}
211      */
212     @Nonnull
213     public static Builder newBuilder()
214     {
215         return newBuilder( true );
216     }
217 
218     /**
219      * Creates a new {@code CiManagement} builder instance using default values or not.
220      *
221      * @param withDefaults the boolean indicating whether default values should be used
222      * @return a new {@code Builder}
223      */
224     @Nonnull
225     public static Builder newBuilder( boolean withDefaults )
226     {
227         return new Builder( withDefaults );
228     }
229 
230     /**
231      * Creates a new {@code CiManagement} builder instance using the specified object as a basis.
232      * Equivalent to {@code newBuilder( from, false )}.
233      *
234      * @param from the {@code CiManagement} instance to use as a basis
235      * @return a new {@code Builder}
236      */
237     @Nonnull
238     public static Builder newBuilder( CiManagement from )
239     {
240         return newBuilder( from, false );
241     }
242 
243     /**
244      * Creates a new {@code CiManagement} builder instance using the specified object as a basis.
245      *
246      * @param from the {@code CiManagement} instance to use as a basis
247      * @param forceCopy the boolean indicating if a copy should be forced
248      * @return a new {@code Builder}
249      */
250     @Nonnull
251     public static Builder newBuilder( CiManagement from, boolean forceCopy )
252     {
253         return new Builder( from, forceCopy );
254     }
255 
256     /**
257      * Builder class used to create CiManagement instances.
258      * @see #with()
259      * @see #newBuilder()
260      */
261     @NotThreadSafe
262     public static class Builder
263     {
264         CiManagement base;
265         String system;
266         String url;
267         Collection<Notifier> notifiers;
268         Map<Object, InputLocation> locations;
269 
270         Builder( boolean withDefaults )
271         {
272             if ( withDefaults )
273             {
274             }
275         }
276 
277         Builder( CiManagement base, boolean forceCopy )
278         {
279             if ( forceCopy )
280             {
281                 this.system = base.system;
282                 this.url = base.url;
283                 this.notifiers = base.notifiers;
284             }
285             else
286             {
287                 this.base = base;
288             }
289         }
290 
291         @Nonnull
292         public Builder system( String system )
293         {
294             this.system = system;
295             return this;
296         }
297 
298         @Nonnull
299         public Builder url( String url )
300         {
301             this.url = url;
302             return this;
303         }
304 
305         @Nonnull
306         public Builder notifiers( Collection<Notifier> notifiers )
307         {
308             this.notifiers = notifiers;
309             return this;
310         }
311 
312 
313         @Nonnull
314         public Builder location( Object key, InputLocation location )
315         {
316             if ( location != null )
317             {
318                 if ( this.locations == null )
319                 {
320                     this.locations = new HashMap<>();
321                 }
322                 this.locations.put( key, location );
323             }
324             return this;
325         }
326 
327         @Nonnull
328         public CiManagement build()
329         {
330             if ( base != null
331                     && ( system == null || system == base.system )
332                     && ( url == null || url == base.url )
333                     && ( notifiers == null || notifiers == base.notifiers )
334             )
335             {
336                 return base;
337             }
338             Map<Object, InputLocation> locations = null;
339             InputLocation location = null;
340             InputLocation systemLocation = null;
341             InputLocation urlLocation = null;
342             InputLocation notifiersLocation = null;
343             if ( this.locations != null )
344             {
345                 locations = this.locations;
346                 location = locations.remove( "" );
347                 systemLocation = locations.remove( "system" );
348                 urlLocation = locations.remove( "url" );
349                 notifiersLocation = locations.remove( "notifiers" );
350             }
351             return new CiManagement(
352                 system != null ? system : ( base != null ? base.system : null ),
353                 url != null ? url : ( base != null ? base.url : null ),
354                 notifiers != null ? notifiers : ( base != null ? base.notifiers : null ),
355                 locations != null ? locations : ( base != null ? base.locations : null ),
356                 location != null ? location : ( base != null ? base.location : null ),
357                 systemLocation != null ? systemLocation : ( base != null ? base.systemLocation : null ),
358                 urlLocation != null ? urlLocation : ( base != null ? base.urlLocation : null ),
359                 notifiersLocation != null ? notifiersLocation : ( base != null ? base.notifiersLocation : null )
360             );
361         }
362     }
363 
364 }