1
2
3
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
25
26
27 @Experimental
28 @Generated @ThreadSafe @Immutable
29 public class Scm
30 implements Serializable, InputLocationTracker
31 {
32
33
34
35
36
37
38
39
40
41
42 final String connection;
43
44
45
46
47
48
49 final String developerConnection;
50
51
52
53 final String tag;
54
55
56
57
58
59 final String url;
60
61
62
63
64
65
66
67 final String childScmConnectionInheritAppendPath;
68
69
70
71
72
73
74
75 final String childScmDeveloperConnectionInheritAppendPath;
76
77
78
79
80
81
82
83 final String childScmUrlInheritAppendPath;
84
85 final Map<Object, InputLocation> locations;
86
87 final InputLocation importedFrom;
88
89
90
91
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
107
108
109
110
111
112
113
114
115
116
117 public String getConnection() {
118 return this.connection;
119 }
120
121
122
123
124
125
126
127
128
129 public String getDeveloperConnection() {
130 return this.developerConnection;
131 }
132
133
134
135
136
137
138 public String getTag() {
139 return this.tag;
140 }
141
142
143
144
145
146
147
148
149 public String getUrl() {
150 return this.url;
151 }
152
153
154
155
156
157
158
159
160
161
162 public String getChildScmConnectionInheritAppendPath() {
163 return this.childScmConnectionInheritAppendPath;
164 }
165
166
167
168
169
170
171
172
173
174
175 public String getChildScmDeveloperConnectionInheritAppendPath() {
176 return this.childScmDeveloperConnectionInheritAppendPath;
177 }
178
179
180
181
182
183
184
185
186
187
188 public String getChildScmUrlInheritAppendPath() {
189 return this.childScmUrlInheritAppendPath;
190 }
191
192
193
194
195 public InputLocation getLocation(Object key) {
196 return locations.get(key);
197 }
198
199
200
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
212
213 public InputLocation getImportedFrom() {
214 return importedFrom;
215 }
216
217
218
219
220
221
222 @Nonnull
223 public Builder with() {
224 return newBuilder(this);
225 }
226
227
228
229
230
231
232 @Nonnull
233 public Scm withConnection(String connection) {
234 return newBuilder(this, true).connection(connection).build();
235 }
236
237
238
239
240
241
242 @Nonnull
243 public Scm withDeveloperConnection(String developerConnection) {
244 return newBuilder(this, true).developerConnection(developerConnection).build();
245 }
246
247
248
249
250
251
252 @Nonnull
253 public Scm withTag(String tag) {
254 return newBuilder(this, true).tag(tag).build();
255 }
256
257
258
259
260
261
262 @Nonnull
263 public Scm withUrl(String url) {
264 return newBuilder(this, true).url(url).build();
265 }
266
267
268
269
270
271
272 @Nonnull
273 public Scm withChildScmConnectionInheritAppendPath(String childScmConnectionInheritAppendPath) {
274 return newBuilder(this, true).childScmConnectionInheritAppendPath(childScmConnectionInheritAppendPath).build();
275 }
276
277
278
279
280
281
282 @Nonnull
283 public Scm withChildScmDeveloperConnectionInheritAppendPath(String childScmDeveloperConnectionInheritAppendPath) {
284 return newBuilder(this, true).childScmDeveloperConnectionInheritAppendPath(childScmDeveloperConnectionInheritAppendPath).build();
285 }
286
287
288
289
290
291
292 @Nonnull
293 public Scm withChildScmUrlInheritAppendPath(String childScmUrlInheritAppendPath) {
294 return newBuilder(this, true).childScmUrlInheritAppendPath(childScmUrlInheritAppendPath).build();
295 }
296
297
298
299
300
301
302
303
304 @Nonnull
305 public static Scm newInstance() {
306 return newInstance(true);
307 }
308
309
310
311
312
313
314
315
316 @Nonnull
317 public static Scm newInstance(boolean withDefaults) {
318 return newBuilder(withDefaults).build();
319 }
320
321
322
323
324
325
326
327
328 @Nonnull
329 public static Builder newBuilder() {
330 return newBuilder(true);
331 }
332
333
334
335
336
337
338
339 @Nonnull
340 public static Builder newBuilder(boolean withDefaults) {
341 return new Builder(withDefaults);
342 }
343
344
345
346
347
348
349
350
351 @Nonnull
352 public static Builder newBuilder(Scm from) {
353 return newBuilder(from, false);
354 }
355
356
357
358
359
360
361
362
363 @Nonnull
364 public static Builder newBuilder(Scm from, boolean forceCopy) {
365 return new Builder(from, forceCopy);
366 }
367
368
369
370
371
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
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
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
522
523 public String toString() {
524 return "Scm {connection=" + getConnection() + "}";
525 }
526
527
528 }