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 {
215 return importedFrom;
216 }
217
218
219
220
221
222
223 @Nonnull
224 public Builder with() {
225 return newBuilder(this);
226 }
227
228
229
230
231
232
233 @Nonnull
234 public Scm withConnection(String connection) {
235 return newBuilder(this, true).connection(connection).build();
236 }
237
238
239
240
241
242
243 @Nonnull
244 public Scm withDeveloperConnection(String developerConnection) {
245 return newBuilder(this, true).developerConnection(developerConnection).build();
246 }
247
248
249
250
251
252
253 @Nonnull
254 public Scm withTag(String tag) {
255 return newBuilder(this, true).tag(tag).build();
256 }
257
258
259
260
261
262
263 @Nonnull
264 public Scm withUrl(String url) {
265 return newBuilder(this, true).url(url).build();
266 }
267
268
269
270
271
272
273 @Nonnull
274 public Scm withChildScmConnectionInheritAppendPath(String childScmConnectionInheritAppendPath) {
275 return newBuilder(this, true).childScmConnectionInheritAppendPath(childScmConnectionInheritAppendPath).build();
276 }
277
278
279
280
281
282
283 @Nonnull
284 public Scm withChildScmDeveloperConnectionInheritAppendPath(String childScmDeveloperConnectionInheritAppendPath) {
285 return newBuilder(this, true).childScmDeveloperConnectionInheritAppendPath(childScmDeveloperConnectionInheritAppendPath).build();
286 }
287
288
289
290
291
292
293 @Nonnull
294 public Scm withChildScmUrlInheritAppendPath(String childScmUrlInheritAppendPath) {
295 return newBuilder(this, true).childScmUrlInheritAppendPath(childScmUrlInheritAppendPath).build();
296 }
297
298
299
300
301
302
303
304
305 @Nonnull
306 public static Scm newInstance() {
307 return newInstance(true);
308 }
309
310
311
312
313
314
315
316
317 @Nonnull
318 public static Scm newInstance(boolean withDefaults) {
319 return newBuilder(withDefaults).build();
320 }
321
322
323
324
325
326
327
328
329 @Nonnull
330 public static Builder newBuilder() {
331 return newBuilder(true);
332 }
333
334
335
336
337
338
339
340 @Nonnull
341 public static Builder newBuilder(boolean withDefaults) {
342 return new Builder(withDefaults);
343 }
344
345
346
347
348
349
350
351
352 @Nonnull
353 public static Builder newBuilder(Scm from) {
354 return newBuilder(from, false);
355 }
356
357
358
359
360
361
362
363
364 @Nonnull
365 public static Builder newBuilder(Scm from, boolean forceCopy) {
366 return new Builder(from, forceCopy);
367 }
368
369
370
371
372
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
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
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
523
524 public String toString() {
525 return "Scm {connection=" + getConnection() + "}";
526 }
527
528
529 }