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