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       * @param key the key of the field, must not be {@code null}
98       * @return the location of the field in the input source or {@code null} if unknown
99       * @throws NullPointerException if {@code key} is {@code null}
100      */
101     public InputLocation getLocation(Object key) {
102         Objects.requireNonNull(key, "key");
103         return locations.get(key);
104     }
105 
106     /**
107      * Gets the keys of the locations of the input source.
108      */
109     public Set<Object> getLocationKeys() {
110         return locations.keySet();
111     }
112 
113     protected Stream<Object> getLocationKeyStream() {
114         return locations.keySet().stream();
115     }
116 
117     /**
118      * Gets the input location that caused this model to be read.
119      */
120     public InputLocation getImportedFrom() {
121         return importedFrom;
122     }
123 
124     /**
125      * Creates a new builder with this object as the basis.
126      *
127      * @return a {@code Builder}
128      */
129     @Nonnull
130     public Builder with() {
131         return newBuilder(this);
132     }
133     /**
134      * Creates a new {@code CiManagement} instance using the specified system.
135      *
136      * @param system the new {@code String} to use
137      * @return a {@code CiManagement} with the specified system
138      */
139     @Nonnull
140     public CiManagement withSystem(String system) {
141         return newBuilder(this, true).system(system).build();
142     }
143     /**
144      * Creates a new {@code CiManagement} instance using the specified url.
145      *
146      * @param url the new {@code String} to use
147      * @return a {@code CiManagement} with the specified url
148      */
149     @Nonnull
150     public CiManagement withUrl(String url) {
151         return newBuilder(this, true).url(url).build();
152     }
153     /**
154      * Creates a new {@code CiManagement} instance using the specified notifiers.
155      *
156      * @param notifiers the new {@code Collection<Notifier>} to use
157      * @return a {@code CiManagement} with the specified notifiers
158      */
159     @Nonnull
160     public CiManagement withNotifiers(Collection<Notifier> notifiers) {
161         return newBuilder(this, true).notifiers(notifiers).build();
162     }
163 
164     /**
165      * Creates a new {@code CiManagement} instance.
166      * Equivalent to {@code newInstance(true)}.
167      * @see #newInstance(boolean)
168      *
169      * @return a new {@code CiManagement}
170      */
171     @Nonnull
172     public static CiManagement newInstance() {
173         return newInstance(true);
174     }
175 
176     /**
177      * Creates a new {@code CiManagement} instance using default values or not.
178      * Equivalent to {@code newBuilder(withDefaults).build()}.
179      *
180      * @param withDefaults the boolean indicating whether default values should be used
181      * @return a new {@code CiManagement}
182      */
183     @Nonnull
184     public static CiManagement newInstance(boolean withDefaults) {
185         return newBuilder(withDefaults).build();
186     }
187 
188     /**
189      * Creates a new {@code CiManagement} builder instance.
190      * Equivalent to {@code newBuilder(true)}.
191      * @see #newBuilder(boolean)
192      *
193      * @return a new {@code Builder}
194      */
195     @Nonnull
196     public static Builder newBuilder() {
197         return newBuilder(true);
198     }
199 
200     /**
201      * Creates a new {@code CiManagement} builder instance using default values or not.
202      *
203      * @param withDefaults the boolean indicating whether default values should be used
204      * @return a new {@code Builder}
205      */
206     @Nonnull
207     public static Builder newBuilder(boolean withDefaults) {
208         return new Builder(withDefaults);
209     }
210 
211     /**
212      * Creates a new {@code CiManagement} builder instance using the specified object as a basis.
213      * Equivalent to {@code newBuilder(from, false)}.
214      *
215      * @param from the {@code CiManagement} instance to use as a basis
216      * @return a new {@code Builder}
217      */
218     @Nonnull
219     public static Builder newBuilder(CiManagement from) {
220         return newBuilder(from, false);
221     }
222 
223     /**
224      * Creates a new {@code CiManagement} builder instance using the specified object as a basis.
225      *
226      * @param from the {@code CiManagement} instance to use as a basis
227      * @param forceCopy the boolean indicating if a copy should be forced
228      * @return a new {@code Builder}
229      */
230     @Nonnull
231     public static Builder newBuilder(CiManagement from, boolean forceCopy) {
232         return new Builder(from, forceCopy);
233     }
234 
235     /**
236      * Builder class used to create CiManagement instances.
237      * @see #with()
238      * @see #newBuilder()
239      */
240     @NotThreadSafe
241     public static class Builder
242     {
243         CiManagement base;
244         String system;
245         String url;
246         Collection<Notifier> notifiers;
247         Map<Object, InputLocation> locations;
248         InputLocation importedFrom;
249 
250         protected Builder(boolean withDefaults) {
251             if (withDefaults) {
252             }
253         }
254 
255         protected Builder(CiManagement base, boolean forceCopy) {
256             if (forceCopy) {
257                 this.system = base.system;
258                 this.url = base.url;
259                 this.notifiers = base.notifiers;
260                 this.locations = base.locations;
261                 this.importedFrom = base.importedFrom;
262             } else {
263                 this.base = base;
264             }
265         }
266 
267         @Nonnull
268         public Builder system(String system) {
269             this.system = system;
270             return this;
271         }
272 
273         @Nonnull
274         public Builder url(String url) {
275             this.url = url;
276             return this;
277         }
278 
279         @Nonnull
280         public Builder notifiers(Collection<Notifier> notifiers) {
281             this.notifiers = notifiers;
282             return this;
283         }
284 
285 
286         @Nonnull
287         public Builder location(Object key, InputLocation location) {
288             if (location != null) {
289                 if (!(this.locations instanceof HashMap)) {
290                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
291                 }
292                 this.locations.put(key, location);
293             }
294             return this;
295         }
296 
297         @Nonnull
298         public Builder importedFrom(InputLocation importedFrom) {
299             this.importedFrom = importedFrom;
300             return this;
301         }
302 
303         @Nonnull
304         public CiManagement build() {
305             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
306             if (base != null
307                     && (system == null || system == base.system)
308                     && (url == null || url == base.url)
309                     && (notifiers == null || notifiers == base.notifiers)
310             ) {
311                 return base;
312             }
313             return new CiManagement(this);
314         }
315 
316         Map<Object, InputLocation> computeLocations() {
317             Map<Object, InputLocation> newlocs = locations != null ? locations : Map.of();
318             Map<Object, InputLocation> oldlocs = base != null ? base.locations : Map.of();
319             if (newlocs.isEmpty()) {
320                 return Map.copyOf(oldlocs);
321             }
322             if (oldlocs.isEmpty()) {
323                 return Map.copyOf(newlocs);
324             }
325             return Stream.concat(newlocs.entrySet().stream(), oldlocs.entrySet().stream())
326                     // Keep value from newlocs in case of duplicates
327                     .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1));
328         }
329     }
330 
331 }