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