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