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