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.Collections;
9   import java.util.HashMap;
10  import java.util.Map;
11  import java.util.Objects;
12  import java.util.Optional;
13  import java.util.Set;
14  import java.util.stream.Collectors;
15  import java.util.stream.Stream;
16  import org.apache.maven.api.annotations.Experimental;
17  import org.apache.maven.api.annotations.Generated;
18  import org.apache.maven.api.annotations.Immutable;
19  import org.apache.maven.api.annotations.Nonnull;
20  import org.apache.maven.api.annotations.NotThreadSafe;
21  import org.apache.maven.api.annotations.ThreadSafe;
22  
23  /**
24   * The {@code <scm>} element contains information required to the SCM
25   * (Source Control Management) of the project.
26   */
27  @Experimental
28  @Generated @ThreadSafe @Immutable
29  public class Scm
30      implements Serializable, InputLocationTracker
31  {
32      /**
33       * The source control management system URL
34       * that describes the repository and how to connect to the
35       * repository.
36       * This connection is read-only.
37       * <br><b>Default value is</b>: parent value [+ path adjustment] + (artifactId or project.directory property), or just parent value if
38       * scm's {@code child.scm.connection.inherit.append.path="false"}
39       * @see <a href="https://maven.apache.org/scm/scm-url-format.html">URL format</a>
40       * @see <a href="https://maven.apache.org/scm/scms-overview.html">list of supported SCMs</a>
41       */
42      final String connection;
43      /**
44       * Just like {@code connection}, but for developers, i.e. this scm connection
45       * will not be read only.
46       * <p><b>Default value is</b>: parent value [+ path adjustment] + (artifactId or project.directory property), or just parent value if
47       * scm's {@code child.scm.developerConnection.inherit.append.path="false"}.</p>
48       */
49      final String developerConnection;
50      /**
51       * The tag of current code. By default, it's set to HEAD during development.
52       */
53      final String tag;
54      /**
55       * The URL to the project's browsable SCM repository, such as ViewVC or Fisheye.
56       * <p><b>Default value is</b>: parent value [+ path adjustment] + (artifactId or project.directory property), or just parent value if
57       * scm's {@code child.scm.url.inherit.append.path="false"}</p>
58       */
59      final String url;
60      /**
61       * When children inherit from scm connection, append path or not? Note: While the type
62       * of this field is {@code String} for technical reasons, the semantic type is actually
63       * {@code Boolean}
64       * <p><b>Default value is</b>: {@code true}</p>
65       * @since Maven 3.6.1
66       */
67      final String childScmConnectionInheritAppendPath;
68      /**
69       * When children inherit from scm developer connection, append path or not? Note: While the type
70       * of this field is {@code String} for technical reasons, the semantic type is actually
71       * {@code Boolean}
72       * <p><b>Default value is</b>: {@code true}</p>
73       * @since Maven 3.6.1
74       */
75      final String childScmDeveloperConnectionInheritAppendPath;
76      /**
77       * When children inherit from scm url, append path or not? Note: While the type
78       * of this field is {@code String} for technical reasons, the semantic type is actually
79       * {@code Boolean}
80       * <br><b>Default value is</b>: {@code true}
81       * @since Maven 3.6.1
82       */
83      final String childScmUrlInheritAppendPath;
84      /** Locations */
85      final Map<Object, InputLocation> locations;
86      /** Location tracking */
87      final InputLocation importedFrom;
88  
89      /**
90        * Constructor for this class, to be called from its subclasses and {@link Builder}.
91        * @see Builder#build()
92        */
93      protected Scm(Builder builder) {
94          this.connection = builder.connection != null ? builder.connection : (builder.base != null ? builder.base.connection : null);
95          this.developerConnection = builder.developerConnection != null ? builder.developerConnection : (builder.base != null ? builder.base.developerConnection : null);
96          this.tag = builder.tag != null ? builder.tag : (builder.base != null ? builder.base.tag : null);
97          this.url = builder.url != null ? builder.url : (builder.base != null ? builder.base.url : null);
98          this.childScmConnectionInheritAppendPath = builder.childScmConnectionInheritAppendPath != null ? builder.childScmConnectionInheritAppendPath : (builder.base != null ? builder.base.childScmConnectionInheritAppendPath : null);
99          this.childScmDeveloperConnectionInheritAppendPath = builder.childScmDeveloperConnectionInheritAppendPath != null ? builder.childScmDeveloperConnectionInheritAppendPath : (builder.base != null ? builder.base.childScmDeveloperConnectionInheritAppendPath : null);
100         this.childScmUrlInheritAppendPath = builder.childScmUrlInheritAppendPath != null ? builder.childScmUrlInheritAppendPath : (builder.base != null ? builder.base.childScmUrlInheritAppendPath : null);
101         this.locations = builder.computeLocations();
102         this.importedFrom = builder.importedFrom;
103     }
104 
105     /**
106      * The source control management system URL
107      * that describes the repository and how to connect to the
108      * repository.
109      * This connection is read-only.
110      * <br><b>Default value is</b>: parent value [+ path adjustment] + (artifactId or project.directory property), or just parent value if
111      * scm's {@code child.scm.connection.inherit.append.path="false"}
112      * @see <a href="https://maven.apache.org/scm/scm-url-format.html">URL format</a>
113      * @see <a href="https://maven.apache.org/scm/scms-overview.html">list of supported SCMs</a>
114      *
115      * @return a {@code String}
116      */
117     public String getConnection() {
118         return this.connection;
119     }
120 
121     /**
122      * Just like {@code connection}, but for developers, i.e. this scm connection
123      * will not be read only.
124      * <p><b>Default value is</b>: parent value [+ path adjustment] + (artifactId or project.directory property), or just parent value if
125      * scm's {@code child.scm.developerConnection.inherit.append.path="false"}.</p>
126      *
127      * @return a {@code String}
128      */
129     public String getDeveloperConnection() {
130         return this.developerConnection;
131     }
132 
133     /**
134      * The tag of current code. By default, it's set to HEAD during development.
135      *
136      * @return a {@code String}
137      */
138     public String getTag() {
139         return this.tag;
140     }
141 
142     /**
143      * The URL to the project's browsable SCM repository, such as ViewVC or Fisheye.
144      * <p><b>Default value is</b>: parent value [+ path adjustment] + (artifactId or project.directory property), or just parent value if
145      * scm's {@code child.scm.url.inherit.append.path="false"}</p>
146      *
147      * @return a {@code String}
148      */
149     public String getUrl() {
150         return this.url;
151     }
152 
153     /**
154      * When children inherit from scm connection, append path or not? Note: While the type
155      * of this field is {@code String} for technical reasons, the semantic type is actually
156      * {@code Boolean}
157      * <p><b>Default value is</b>: {@code true}</p>
158      * @since Maven 3.6.1
159      *
160      * @return a {@code String}
161      */
162     public String getChildScmConnectionInheritAppendPath() {
163         return this.childScmConnectionInheritAppendPath;
164     }
165 
166     /**
167      * When children inherit from scm developer connection, append path or not? Note: While the type
168      * of this field is {@code String} for technical reasons, the semantic type is actually
169      * {@code Boolean}
170      * <p><b>Default value is</b>: {@code true}</p>
171      * @since Maven 3.6.1
172      *
173      * @return a {@code String}
174      */
175     public String getChildScmDeveloperConnectionInheritAppendPath() {
176         return this.childScmDeveloperConnectionInheritAppendPath;
177     }
178 
179     /**
180      * When children inherit from scm url, append path or not? Note: While the type
181      * of this field is {@code String} for technical reasons, the semantic type is actually
182      * {@code Boolean}
183      * <br><b>Default value is</b>: {@code true}
184      * @since Maven 3.6.1
185      *
186      * @return a {@code String}
187      */
188     public String getChildScmUrlInheritAppendPath() {
189         return this.childScmUrlInheritAppendPath;
190     }
191 
192     /**
193      * Gets the location of the specified field in the input source.
194      *
195      * @param key the key of the field, must not be {@code null}
196      * @return the location of the field in the input source or {@code null} if unknown
197      * @throws NullPointerException if {@code key} is {@code null}
198      */
199     public InputLocation getLocation(Object key) {
200         Objects.requireNonNull(key, "key");
201         return locations.get(key);
202     }
203 
204     /**
205      * Gets the keys of the locations of the input source.
206      */
207     public Set<Object> getLocationKeys() {
208         return locations.keySet();
209     }
210 
211     protected Stream<Object> getLocationKeyStream() {
212         return locations.keySet().stream();
213     }
214 
215     /**
216      * Gets the input location that caused this model to be read.
217      */
218     public InputLocation getImportedFrom() {
219         return importedFrom;
220     }
221 
222     /**
223      * Creates a new builder with this object as the basis.
224      *
225      * @return a {@code Builder}
226      */
227     @Nonnull
228     public Builder with() {
229         return newBuilder(this);
230     }
231     /**
232      * Creates a new {@code Scm} instance using the specified connection.
233      *
234      * @param connection the new {@code String} to use
235      * @return a {@code Scm} with the specified connection
236      */
237     @Nonnull
238     public Scm withConnection(String connection) {
239         return newBuilder(this, true).connection(connection).build();
240     }
241     /**
242      * Creates a new {@code Scm} instance using the specified developerConnection.
243      *
244      * @param developerConnection the new {@code String} to use
245      * @return a {@code Scm} with the specified developerConnection
246      */
247     @Nonnull
248     public Scm withDeveloperConnection(String developerConnection) {
249         return newBuilder(this, true).developerConnection(developerConnection).build();
250     }
251     /**
252      * Creates a new {@code Scm} instance using the specified tag.
253      *
254      * @param tag the new {@code String} to use
255      * @return a {@code Scm} with the specified tag
256      */
257     @Nonnull
258     public Scm withTag(String tag) {
259         return newBuilder(this, true).tag(tag).build();
260     }
261     /**
262      * Creates a new {@code Scm} instance using the specified url.
263      *
264      * @param url the new {@code String} to use
265      * @return a {@code Scm} with the specified url
266      */
267     @Nonnull
268     public Scm withUrl(String url) {
269         return newBuilder(this, true).url(url).build();
270     }
271     /**
272      * Creates a new {@code Scm} instance using the specified childScmConnectionInheritAppendPath.
273      *
274      * @param childScmConnectionInheritAppendPath the new {@code String} to use
275      * @return a {@code Scm} with the specified childScmConnectionInheritAppendPath
276      */
277     @Nonnull
278     public Scm withChildScmConnectionInheritAppendPath(String childScmConnectionInheritAppendPath) {
279         return newBuilder(this, true).childScmConnectionInheritAppendPath(childScmConnectionInheritAppendPath).build();
280     }
281     /**
282      * Creates a new {@code Scm} instance using the specified childScmDeveloperConnectionInheritAppendPath.
283      *
284      * @param childScmDeveloperConnectionInheritAppendPath the new {@code String} to use
285      * @return a {@code Scm} with the specified childScmDeveloperConnectionInheritAppendPath
286      */
287     @Nonnull
288     public Scm withChildScmDeveloperConnectionInheritAppendPath(String childScmDeveloperConnectionInheritAppendPath) {
289         return newBuilder(this, true).childScmDeveloperConnectionInheritAppendPath(childScmDeveloperConnectionInheritAppendPath).build();
290     }
291     /**
292      * Creates a new {@code Scm} instance using the specified childScmUrlInheritAppendPath.
293      *
294      * @param childScmUrlInheritAppendPath the new {@code String} to use
295      * @return a {@code Scm} with the specified childScmUrlInheritAppendPath
296      */
297     @Nonnull
298     public Scm withChildScmUrlInheritAppendPath(String childScmUrlInheritAppendPath) {
299         return newBuilder(this, true).childScmUrlInheritAppendPath(childScmUrlInheritAppendPath).build();
300     }
301 
302     /**
303      * Creates a new {@code Scm} instance.
304      * Equivalent to {@code newInstance(true)}.
305      * @see #newInstance(boolean)
306      *
307      * @return a new {@code Scm}
308      */
309     @Nonnull
310     public static Scm newInstance() {
311         return newInstance(true);
312     }
313 
314     /**
315      * Creates a new {@code Scm} instance using default values or not.
316      * Equivalent to {@code newBuilder(withDefaults).build()}.
317      *
318      * @param withDefaults the boolean indicating whether default values should be used
319      * @return a new {@code Scm}
320      */
321     @Nonnull
322     public static Scm newInstance(boolean withDefaults) {
323         return newBuilder(withDefaults).build();
324     }
325 
326     /**
327      * Creates a new {@code Scm} builder instance.
328      * Equivalent to {@code newBuilder(true)}.
329      * @see #newBuilder(boolean)
330      *
331      * @return a new {@code Builder}
332      */
333     @Nonnull
334     public static Builder newBuilder() {
335         return newBuilder(true);
336     }
337 
338     /**
339      * Creates a new {@code Scm} builder instance using default values or not.
340      *
341      * @param withDefaults the boolean indicating whether default values should be used
342      * @return a new {@code Builder}
343      */
344     @Nonnull
345     public static Builder newBuilder(boolean withDefaults) {
346         return new Builder(withDefaults);
347     }
348 
349     /**
350      * Creates a new {@code Scm} builder instance using the specified object as a basis.
351      * Equivalent to {@code newBuilder(from, false)}.
352      *
353      * @param from the {@code Scm} instance to use as a basis
354      * @return a new {@code Builder}
355      */
356     @Nonnull
357     public static Builder newBuilder(Scm from) {
358         return newBuilder(from, false);
359     }
360 
361     /**
362      * Creates a new {@code Scm} builder instance using the specified object as a basis.
363      *
364      * @param from the {@code Scm} instance to use as a basis
365      * @param forceCopy the boolean indicating if a copy should be forced
366      * @return a new {@code Builder}
367      */
368     @Nonnull
369     public static Builder newBuilder(Scm from, boolean forceCopy) {
370         return new Builder(from, forceCopy);
371     }
372 
373     /**
374      * Builder class used to create Scm instances.
375      * @see #with()
376      * @see #newBuilder()
377      */
378     @NotThreadSafe
379     public static class Builder
380     {
381         Scm base;
382         String connection;
383         String developerConnection;
384         String tag;
385         String url;
386         String childScmConnectionInheritAppendPath;
387         String childScmDeveloperConnectionInheritAppendPath;
388         String childScmUrlInheritAppendPath;
389         Map<Object, InputLocation> locations;
390         InputLocation importedFrom;
391 
392         protected Builder(boolean withDefaults) {
393             if (withDefaults) {
394                 this.tag = "HEAD";
395             }
396         }
397 
398         protected Builder(Scm base, boolean forceCopy) {
399             if (forceCopy) {
400                 this.connection = base.connection;
401                 this.developerConnection = base.developerConnection;
402                 this.tag = base.tag;
403                 this.url = base.url;
404                 this.childScmConnectionInheritAppendPath = base.childScmConnectionInheritAppendPath;
405                 this.childScmDeveloperConnectionInheritAppendPath = base.childScmDeveloperConnectionInheritAppendPath;
406                 this.childScmUrlInheritAppendPath = base.childScmUrlInheritAppendPath;
407                 this.locations = base.locations;
408                 this.importedFrom = base.importedFrom;
409             } else {
410                 this.base = base;
411             }
412         }
413 
414         @Nonnull
415         public Builder connection(String connection) {
416             this.connection = connection;
417             return this;
418         }
419 
420         @Nonnull
421         public Builder developerConnection(String developerConnection) {
422             this.developerConnection = developerConnection;
423             return this;
424         }
425 
426         @Nonnull
427         public Builder tag(String tag) {
428             this.tag = tag;
429             return this;
430         }
431 
432         @Nonnull
433         public Builder url(String url) {
434             this.url = url;
435             return this;
436         }
437 
438         @Nonnull
439         public Builder childScmConnectionInheritAppendPath(String childScmConnectionInheritAppendPath) {
440             this.childScmConnectionInheritAppendPath = childScmConnectionInheritAppendPath;
441             return this;
442         }
443 
444         @Nonnull
445         public Builder childScmDeveloperConnectionInheritAppendPath(String childScmDeveloperConnectionInheritAppendPath) {
446             this.childScmDeveloperConnectionInheritAppendPath = childScmDeveloperConnectionInheritAppendPath;
447             return this;
448         }
449 
450         @Nonnull
451         public Builder childScmUrlInheritAppendPath(String childScmUrlInheritAppendPath) {
452             this.childScmUrlInheritAppendPath = childScmUrlInheritAppendPath;
453             return this;
454         }
455 
456 
457         @Nonnull
458         public Builder location(Object key, InputLocation location) {
459             if (location != null) {
460                 if (!(this.locations instanceof HashMap)) {
461                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
462                 }
463                 this.locations.put(key, location);
464             }
465             return this;
466         }
467 
468         @Nonnull
469         public Builder importedFrom(InputLocation importedFrom) {
470             this.importedFrom = importedFrom;
471             return this;
472         }
473 
474         @Nonnull
475         public Scm build() {
476             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
477             if (base != null
478                     && (connection == null || connection == base.connection)
479                     && (developerConnection == null || developerConnection == base.developerConnection)
480                     && (tag == null || tag == base.tag)
481                     && (url == null || url == base.url)
482                     && (childScmConnectionInheritAppendPath == null || childScmConnectionInheritAppendPath == base.childScmConnectionInheritAppendPath)
483                     && (childScmDeveloperConnectionInheritAppendPath == null || childScmDeveloperConnectionInheritAppendPath == base.childScmDeveloperConnectionInheritAppendPath)
484                     && (childScmUrlInheritAppendPath == null || childScmUrlInheritAppendPath == base.childScmUrlInheritAppendPath)
485             ) {
486                 return base;
487             }
488             return new Scm(this);
489         }
490 
491         Map<Object, InputLocation> computeLocations() {
492             Map<Object, InputLocation> newlocs = locations != null ? locations : Map.of();
493             Map<Object, InputLocation> oldlocs = base != null ? base.locations : Map.of();
494             if (newlocs.isEmpty()) {
495                 return Map.copyOf(oldlocs);
496             }
497             if (oldlocs.isEmpty()) {
498                 return Map.copyOf(newlocs);
499             }
500             return Stream.concat(newlocs.entrySet().stream(), oldlocs.entrySet().stream())
501                     // Keep value from newlocs in case of duplicates
502                     .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1));
503         }
504     }
505 
506 
507             
508 
509     public boolean isChildScmConnectionInheritAppendPath() {
510         return (getChildScmConnectionInheritAppendPath() != null) ? Boolean.parseBoolean(getChildScmConnectionInheritAppendPath()) : true;
511     }
512 
513     public boolean isChildScmDeveloperConnectionInheritAppendPath() {
514         return (getChildScmDeveloperConnectionInheritAppendPath() != null) ? Boolean.parseBoolean(getChildScmDeveloperConnectionInheritAppendPath()) : true;
515     }
516 
517     public boolean isChildScmUrlInheritAppendPath() {
518         return (getChildScmUrlInheritAppendPath() != null) ? Boolean.parseBoolean(getChildScmUrlInheritAppendPath()) : true;
519     }
520 
521             
522           
523 
524             
525     /**
526      * @see java.lang.Object#toString()
527      */
528     public String toString() {
529         return "Scm {connection=" + getConnection() + "}";
530     }
531             
532           
533 }