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