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     public InputLocation getLocation(Object key) {
196         return locations.get(key);
197     }
198 
199     /**
200      * Gets the keys of the locations of the input source.
201      */
202     public Set<Object> getLocationKeys() {
203         return locations.keySet();
204     }
205 
206     protected Stream<Object> getLocationKeyStream() {
207         return locations.keySet().stream();
208     }
209 
210     /**
211      * Gets the input location that caused this model to be read.
212      */
213     public InputLocation getImportedFrom()
214     {
215         return importedFrom;
216     }
217 
218     /**
219      * Creates a new builder with this object as the basis.
220      *
221      * @return a {@code Builder}
222      */
223     @Nonnull
224     public Builder with() {
225         return newBuilder(this);
226     }
227     /**
228      * Creates a new {@code Scm} instance using the specified connection.
229      *
230      * @param connection the new {@code String} to use
231      * @return a {@code Scm} with the specified connection
232      */
233     @Nonnull
234     public Scm withConnection(String connection) {
235         return newBuilder(this, true).connection(connection).build();
236     }
237     /**
238      * Creates a new {@code Scm} instance using the specified developerConnection.
239      *
240      * @param developerConnection the new {@code String} to use
241      * @return a {@code Scm} with the specified developerConnection
242      */
243     @Nonnull
244     public Scm withDeveloperConnection(String developerConnection) {
245         return newBuilder(this, true).developerConnection(developerConnection).build();
246     }
247     /**
248      * Creates a new {@code Scm} instance using the specified tag.
249      *
250      * @param tag the new {@code String} to use
251      * @return a {@code Scm} with the specified tag
252      */
253     @Nonnull
254     public Scm withTag(String tag) {
255         return newBuilder(this, true).tag(tag).build();
256     }
257     /**
258      * Creates a new {@code Scm} instance using the specified url.
259      *
260      * @param url the new {@code String} to use
261      * @return a {@code Scm} with the specified url
262      */
263     @Nonnull
264     public Scm withUrl(String url) {
265         return newBuilder(this, true).url(url).build();
266     }
267     /**
268      * Creates a new {@code Scm} instance using the specified childScmConnectionInheritAppendPath.
269      *
270      * @param childScmConnectionInheritAppendPath the new {@code String} to use
271      * @return a {@code Scm} with the specified childScmConnectionInheritAppendPath
272      */
273     @Nonnull
274     public Scm withChildScmConnectionInheritAppendPath(String childScmConnectionInheritAppendPath) {
275         return newBuilder(this, true).childScmConnectionInheritAppendPath(childScmConnectionInheritAppendPath).build();
276     }
277     /**
278      * Creates a new {@code Scm} instance using the specified childScmDeveloperConnectionInheritAppendPath.
279      *
280      * @param childScmDeveloperConnectionInheritAppendPath the new {@code String} to use
281      * @return a {@code Scm} with the specified childScmDeveloperConnectionInheritAppendPath
282      */
283     @Nonnull
284     public Scm withChildScmDeveloperConnectionInheritAppendPath(String childScmDeveloperConnectionInheritAppendPath) {
285         return newBuilder(this, true).childScmDeveloperConnectionInheritAppendPath(childScmDeveloperConnectionInheritAppendPath).build();
286     }
287     /**
288      * Creates a new {@code Scm} instance using the specified childScmUrlInheritAppendPath.
289      *
290      * @param childScmUrlInheritAppendPath the new {@code String} to use
291      * @return a {@code Scm} with the specified childScmUrlInheritAppendPath
292      */
293     @Nonnull
294     public Scm withChildScmUrlInheritAppendPath(String childScmUrlInheritAppendPath) {
295         return newBuilder(this, true).childScmUrlInheritAppendPath(childScmUrlInheritAppendPath).build();
296     }
297 
298     /**
299      * Creates a new {@code Scm} instance.
300      * Equivalent to {@code newInstance(true)}.
301      * @see #newInstance(boolean)
302      *
303      * @return a new {@code Scm}
304      */
305     @Nonnull
306     public static Scm newInstance() {
307         return newInstance(true);
308     }
309 
310     /**
311      * Creates a new {@code Scm} instance using default values or not.
312      * Equivalent to {@code newBuilder(withDefaults).build()}.
313      *
314      * @param withDefaults the boolean indicating whether default values should be used
315      * @return a new {@code Scm}
316      */
317     @Nonnull
318     public static Scm newInstance(boolean withDefaults) {
319         return newBuilder(withDefaults).build();
320     }
321 
322     /**
323      * Creates a new {@code Scm} builder instance.
324      * Equivalent to {@code newBuilder(true)}.
325      * @see #newBuilder(boolean)
326      *
327      * @return a new {@code Builder}
328      */
329     @Nonnull
330     public static Builder newBuilder() {
331         return newBuilder(true);
332     }
333 
334     /**
335      * Creates a new {@code Scm} builder instance using default values or not.
336      *
337      * @param withDefaults the boolean indicating whether default values should be used
338      * @return a new {@code Builder}
339      */
340     @Nonnull
341     public static Builder newBuilder(boolean withDefaults) {
342         return new Builder(withDefaults);
343     }
344 
345     /**
346      * Creates a new {@code Scm} builder instance using the specified object as a basis.
347      * Equivalent to {@code newBuilder(from, false)}.
348      *
349      * @param from the {@code Scm} instance to use as a basis
350      * @return a new {@code Builder}
351      */
352     @Nonnull
353     public static Builder newBuilder(Scm from) {
354         return newBuilder(from, false);
355     }
356 
357     /**
358      * Creates a new {@code Scm} builder instance using the specified object as a basis.
359      *
360      * @param from the {@code Scm} instance to use as a basis
361      * @param forceCopy the boolean indicating if a copy should be forced
362      * @return a new {@code Builder}
363      */
364     @Nonnull
365     public static Builder newBuilder(Scm from, boolean forceCopy) {
366         return new Builder(from, forceCopy);
367     }
368 
369     /**
370      * Builder class used to create Scm instances.
371      * @see #with()
372      * @see #newBuilder()
373      */
374     @NotThreadSafe
375     public static class Builder
376     {
377         Scm base;
378         String connection;
379         String developerConnection;
380         String tag;
381         String url;
382         String childScmConnectionInheritAppendPath;
383         String childScmDeveloperConnectionInheritAppendPath;
384         String childScmUrlInheritAppendPath;
385         Map<Object, InputLocation> locations;
386         InputLocation importedFrom;
387 
388         protected Builder(boolean withDefaults) {
389             if (withDefaults) {
390                 this.tag = "HEAD";
391             }
392         }
393 
394         protected Builder(Scm base, boolean forceCopy) {
395             if (forceCopy) {
396                 this.connection = base.connection;
397                 this.developerConnection = base.developerConnection;
398                 this.tag = base.tag;
399                 this.url = base.url;
400                 this.childScmConnectionInheritAppendPath = base.childScmConnectionInheritAppendPath;
401                 this.childScmDeveloperConnectionInheritAppendPath = base.childScmDeveloperConnectionInheritAppendPath;
402                 this.childScmUrlInheritAppendPath = base.childScmUrlInheritAppendPath;
403                 this.locations = base.locations;
404                 this.importedFrom = base.importedFrom;
405             } else {
406                 this.base = base;
407             }
408         }
409 
410         @Nonnull
411         public Builder connection(String connection) {
412             this.connection = connection;
413             return this;
414         }
415 
416         @Nonnull
417         public Builder developerConnection(String developerConnection) {
418             this.developerConnection = developerConnection;
419             return this;
420         }
421 
422         @Nonnull
423         public Builder tag(String tag) {
424             this.tag = tag;
425             return this;
426         }
427 
428         @Nonnull
429         public Builder url(String url) {
430             this.url = url;
431             return this;
432         }
433 
434         @Nonnull
435         public Builder childScmConnectionInheritAppendPath(String childScmConnectionInheritAppendPath) {
436             this.childScmConnectionInheritAppendPath = childScmConnectionInheritAppendPath;
437             return this;
438         }
439 
440         @Nonnull
441         public Builder childScmDeveloperConnectionInheritAppendPath(String childScmDeveloperConnectionInheritAppendPath) {
442             this.childScmDeveloperConnectionInheritAppendPath = childScmDeveloperConnectionInheritAppendPath;
443             return this;
444         }
445 
446         @Nonnull
447         public Builder childScmUrlInheritAppendPath(String childScmUrlInheritAppendPath) {
448             this.childScmUrlInheritAppendPath = childScmUrlInheritAppendPath;
449             return this;
450         }
451 
452 
453         @Nonnull
454         public Builder location(Object key, InputLocation location) {
455             if (location != null) {
456                 if (!(this.locations instanceof HashMap)) {
457                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
458                 }
459                 this.locations.put(key, location);
460             }
461             return this;
462         }
463 
464         @Nonnull
465         public Builder importedFrom(InputLocation importedFrom) {
466             this.importedFrom = importedFrom;
467             return this;
468         }
469 
470         @Nonnull
471         public Scm build() {
472             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
473             if (base != null
474                     && (connection == null || connection == base.connection)
475                     && (developerConnection == null || developerConnection == base.developerConnection)
476                     && (tag == null || tag == base.tag)
477                     && (url == null || url == base.url)
478                     && (childScmConnectionInheritAppendPath == null || childScmConnectionInheritAppendPath == base.childScmConnectionInheritAppendPath)
479                     && (childScmDeveloperConnectionInheritAppendPath == null || childScmDeveloperConnectionInheritAppendPath == base.childScmDeveloperConnectionInheritAppendPath)
480                     && (childScmUrlInheritAppendPath == null || childScmUrlInheritAppendPath == base.childScmUrlInheritAppendPath)
481             ) {
482                 return base;
483             }
484             return new Scm(this);
485         }
486 
487         Map<Object, InputLocation> computeLocations() {
488             Map<Object, InputLocation> newlocs = locations != null ? locations : Map.of();
489             Map<Object, InputLocation> oldlocs = base != null ? base.locations : Map.of();
490             if (newlocs.isEmpty()) {
491                 return Map.copyOf(oldlocs);
492             }
493             if (oldlocs.isEmpty()) {
494                 return Map.copyOf(newlocs);
495             }
496             return Stream.concat(newlocs.entrySet().stream(), oldlocs.entrySet().stream())
497                     // Keep value from newlocs in case of duplicates
498                     .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1));
499         }
500     }
501 
502 
503             
504 
505     public boolean isChildScmConnectionInheritAppendPath() {
506         return (getChildScmConnectionInheritAppendPath() != null) ? Boolean.parseBoolean(getChildScmConnectionInheritAppendPath()) : true;
507     }
508 
509     public boolean isChildScmDeveloperConnectionInheritAppendPath() {
510         return (getChildScmDeveloperConnectionInheritAppendPath() != null) ? Boolean.parseBoolean(getChildScmDeveloperConnectionInheritAppendPath()) : true;
511     }
512 
513     public boolean isChildScmUrlInheritAppendPath() {
514         return (getChildScmUrlInheritAppendPath() != null) ? Boolean.parseBoolean(getChildScmUrlInheritAppendPath()) : true;
515     }
516 
517             
518           
519 
520             
521     /**
522      * @see java.lang.Object#toString()
523      */
524     public String toString() {
525         return "Scm {connection=" + getConnection() + "}";
526     }
527             
528           
529 }