1
2
3
4 package org.apache.maven.settings.v4;
5
6 import java.io.ObjectStreamException;
7 import java.util.AbstractList;
8 import java.util.ArrayList;
9 import java.util.Collection;
10 import java.util.HashMap;
11 import java.util.Iterator;
12 import java.util.LinkedHashMap;
13 import java.util.List;
14 import java.util.Map;
15 import java.util.Objects;
16 import java.util.function.BinaryOperator;
17 import java.util.function.Function;
18 import java.util.stream.Collectors;
19
20 import org.apache.maven.api.annotations.Generated;
21 import org.apache.maven.api.xml.Dom;
22 import org.apache.maven.api.settings.TrackableBase;
23 import org.apache.maven.api.settings.IdentifiableBase;
24 import org.apache.maven.api.settings.Settings;
25 import org.apache.maven.api.settings.Proxy;
26 import org.apache.maven.api.settings.Server;
27 import org.apache.maven.api.settings.Mirror;
28 import org.apache.maven.api.settings.Profile;
29 import org.apache.maven.api.settings.Activation;
30 import org.apache.maven.api.settings.RepositoryBase;
31 import org.apache.maven.api.settings.Repository;
32 import org.apache.maven.api.settings.RepositoryPolicy;
33 import org.apache.maven.api.settings.ActivationProperty;
34 import org.apache.maven.api.settings.ActivationOS;
35 import org.apache.maven.api.settings.ActivationFile;
36
37 @Generated
38 public class SettingsMerger
39 {
40
41
42
43
44
45
46
47
48
49
50
51
52
53 public Settings merge( Settings target, Settings source, boolean sourceDominant, Map<?, ?> hints )
54 {
55 Objects.requireNonNull( target, "target cannot be null" );
56 if ( source == null )
57 {
58 return target;
59 }
60 Map<Object, Object> context = new HashMap<>();
61 if ( hints != null )
62 {
63 context.putAll( hints );
64 }
65 return mergeSettings( target, source, sourceDominant, context );
66 }
67
68 protected TrackableBase mergeTrackableBase( TrackableBase target, TrackableBase source, boolean sourceDominant, Map<Object, Object> context )
69 {
70 TrackableBase.Builder builder = TrackableBase.newBuilder( target );
71 mergeTrackableBase( builder, target, source, sourceDominant, context );
72 return builder.build();
73 }
74
75 protected void mergeTrackableBase( TrackableBase.Builder builder, TrackableBase target, TrackableBase source, boolean sourceDominant, Map<Object, Object> context )
76 {
77 }
78
79
80 protected IdentifiableBase mergeIdentifiableBase( IdentifiableBase target, IdentifiableBase source, boolean sourceDominant, Map<Object, Object> context )
81 {
82 IdentifiableBase.Builder builder = IdentifiableBase.newBuilder( target );
83 mergeIdentifiableBase( builder, target, source, sourceDominant, context );
84 return builder.build();
85 }
86
87 protected void mergeIdentifiableBase( IdentifiableBase.Builder builder, IdentifiableBase target, IdentifiableBase source, boolean sourceDominant, Map<Object, Object> context )
88 {
89 mergeTrackableBase( builder, target ,source, sourceDominant, context );
90 mergeIdentifiableBase_Id( builder, target, source, sourceDominant, context );
91 }
92
93 protected void mergeIdentifiableBase_Id( IdentifiableBase.Builder builder, IdentifiableBase target, IdentifiableBase source, boolean sourceDominant, Map<Object, Object> context )
94 {
95 String src = source.getId();
96 String tgt = target.getId();
97 if ( src != null && ( sourceDominant || tgt == null ) )
98 {
99 builder.id( src );
100 }
101 }
102
103 protected Settings mergeSettings( Settings target, Settings source, boolean sourceDominant, Map<Object, Object> context )
104 {
105 Settings.Builder builder = Settings.newBuilder( target );
106 mergeSettings( builder, target, source, sourceDominant, context );
107 return builder.build();
108 }
109
110 protected void mergeSettings( Settings.Builder builder, Settings target, Settings source, boolean sourceDominant, Map<Object, Object> context )
111 {
112 mergeTrackableBase( builder, target ,source, sourceDominant, context );
113 mergeSettings_LocalRepository( builder, target, source, sourceDominant, context );
114 mergeSettings_InteractiveMode( builder, target, source, sourceDominant, context );
115 mergeSettings_UsePluginRegistry( builder, target, source, sourceDominant, context );
116 mergeSettings_Offline( builder, target, source, sourceDominant, context );
117 mergeSettings_Proxies( builder, target, source, sourceDominant, context );
118 mergeSettings_Servers( builder, target, source, sourceDominant, context );
119 mergeSettings_Mirrors( builder, target, source, sourceDominant, context );
120 mergeSettings_Profiles( builder, target, source, sourceDominant, context );
121 mergeSettings_ActiveProfiles( builder, target, source, sourceDominant, context );
122 mergeSettings_PluginGroups( builder, target, source, sourceDominant, context );
123 }
124
125 protected void mergeSettings_LocalRepository( Settings.Builder builder, Settings target, Settings source, boolean sourceDominant, Map<Object, Object> context )
126 {
127 String src = source.getLocalRepository();
128 String tgt = target.getLocalRepository();
129 if ( src != null && ( sourceDominant || tgt == null ) )
130 {
131 builder.localRepository( src );
132 }
133 }
134 protected void mergeSettings_InteractiveMode( Settings.Builder builder, Settings target, Settings source, boolean sourceDominant, Map<Object, Object> context )
135 {
136 if ( sourceDominant )
137 {
138 builder.interactiveMode( source.isInteractiveMode() );
139 }
140 }
141 protected void mergeSettings_UsePluginRegistry( Settings.Builder builder, Settings target, Settings source, boolean sourceDominant, Map<Object, Object> context )
142 {
143 if ( sourceDominant )
144 {
145 builder.usePluginRegistry( source.isUsePluginRegistry() );
146 }
147 }
148 protected void mergeSettings_Offline( Settings.Builder builder, Settings target, Settings source, boolean sourceDominant, Map<Object, Object> context )
149 {
150 if ( sourceDominant )
151 {
152 builder.offline( source.isOffline() );
153 }
154 }
155 protected void mergeSettings_Proxies( Settings.Builder builder, Settings target, Settings source, boolean sourceDominant, Map<Object, Object> context )
156 {
157 builder.proxies( merge( target.getProxies(), source.getProxies(), sourceDominant, getProxyKey() ) );
158 }
159 protected void mergeSettings_Servers( Settings.Builder builder, Settings target, Settings source, boolean sourceDominant, Map<Object, Object> context )
160 {
161 builder.servers( merge( target.getServers(), source.getServers(), sourceDominant, getServerKey() ) );
162 }
163 protected void mergeSettings_Mirrors( Settings.Builder builder, Settings target, Settings source, boolean sourceDominant, Map<Object, Object> context )
164 {
165 builder.mirrors( merge( target.getMirrors(), source.getMirrors(), sourceDominant, getMirrorKey() ) );
166 }
167 protected void mergeSettings_Profiles( Settings.Builder builder, Settings target, Settings source, boolean sourceDominant, Map<Object, Object> context )
168 {
169 builder.profiles( merge( target.getProfiles(), source.getProfiles(), sourceDominant, getProfileKey() ) );
170 }
171 protected void mergeSettings_ActiveProfiles( Settings.Builder builder, Settings target, Settings source, boolean sourceDominant, Map<Object, Object> context )
172 {
173 builder.activeProfiles( merge( target.getActiveProfiles(), source.getActiveProfiles(), sourceDominant, e -> e ) );
174 }
175 protected void mergeSettings_PluginGroups( Settings.Builder builder, Settings target, Settings source, boolean sourceDominant, Map<Object, Object> context )
176 {
177 builder.pluginGroups( merge( target.getPluginGroups(), source.getPluginGroups(), sourceDominant, e -> e ) );
178 }
179
180 protected Proxy mergeProxy( Proxy target, Proxy source, boolean sourceDominant, Map<Object, Object> context )
181 {
182 Proxy.Builder builder = Proxy.newBuilder( target );
183 mergeProxy( builder, target, source, sourceDominant, context );
184 return builder.build();
185 }
186
187 protected void mergeProxy( Proxy.Builder builder, Proxy target, Proxy source, boolean sourceDominant, Map<Object, Object> context )
188 {
189 mergeIdentifiableBase( builder, target ,source, sourceDominant, context );
190 mergeProxy_Active( builder, target, source, sourceDominant, context );
191 mergeProxy_Protocol( builder, target, source, sourceDominant, context );
192 mergeProxy_Username( builder, target, source, sourceDominant, context );
193 mergeProxy_Password( builder, target, source, sourceDominant, context );
194 mergeProxy_Port( builder, target, source, sourceDominant, context );
195 mergeProxy_Host( builder, target, source, sourceDominant, context );
196 mergeProxy_NonProxyHosts( builder, target, source, sourceDominant, context );
197 }
198
199 protected void mergeProxy_Id( Proxy.Builder builder, Proxy target, Proxy source, boolean sourceDominant, Map<Object, Object> context )
200 {
201 String src = source.getId();
202 String tgt = target.getId();
203 if ( src != null && ( sourceDominant || tgt == null ) )
204 {
205 builder.id( src );
206 }
207 }
208 protected void mergeProxy_Active( Proxy.Builder builder, Proxy target, Proxy source, boolean sourceDominant, Map<Object, Object> context )
209 {
210 if ( sourceDominant )
211 {
212 builder.active( source.isActive() );
213 }
214 }
215 protected void mergeProxy_Protocol( Proxy.Builder builder, Proxy target, Proxy source, boolean sourceDominant, Map<Object, Object> context )
216 {
217 String src = source.getProtocol();
218 String tgt = target.getProtocol();
219 if ( src != null && ( sourceDominant || tgt == null ) )
220 {
221 builder.protocol( src );
222 }
223 }
224 protected void mergeProxy_Username( Proxy.Builder builder, Proxy target, Proxy source, boolean sourceDominant, Map<Object, Object> context )
225 {
226 String src = source.getUsername();
227 String tgt = target.getUsername();
228 if ( src != null && ( sourceDominant || tgt == null ) )
229 {
230 builder.username( src );
231 }
232 }
233 protected void mergeProxy_Password( Proxy.Builder builder, Proxy target, Proxy source, boolean sourceDominant, Map<Object, Object> context )
234 {
235 String src = source.getPassword();
236 String tgt = target.getPassword();
237 if ( src != null && ( sourceDominant || tgt == null ) )
238 {
239 builder.password( src );
240 }
241 }
242 protected void mergeProxy_Port( Proxy.Builder builder, Proxy target, Proxy source, boolean sourceDominant, Map<Object, Object> context )
243 {
244 if ( sourceDominant )
245 {
246 builder.port( source.getPort() );
247 }
248 }
249 protected void mergeProxy_Host( Proxy.Builder builder, Proxy target, Proxy source, boolean sourceDominant, Map<Object, Object> context )
250 {
251 String src = source.getHost();
252 String tgt = target.getHost();
253 if ( src != null && ( sourceDominant || tgt == null ) )
254 {
255 builder.host( src );
256 }
257 }
258 protected void mergeProxy_NonProxyHosts( Proxy.Builder builder, Proxy target, Proxy source, boolean sourceDominant, Map<Object, Object> context )
259 {
260 String src = source.getNonProxyHosts();
261 String tgt = target.getNonProxyHosts();
262 if ( src != null && ( sourceDominant || tgt == null ) )
263 {
264 builder.nonProxyHosts( src );
265 }
266 }
267
268 protected Server mergeServer( Server target, Server source, boolean sourceDominant, Map<Object, Object> context )
269 {
270 Server.Builder builder = Server.newBuilder( target );
271 mergeServer( builder, target, source, sourceDominant, context );
272 return builder.build();
273 }
274
275 protected void mergeServer( Server.Builder builder, Server target, Server source, boolean sourceDominant, Map<Object, Object> context )
276 {
277 mergeIdentifiableBase( builder, target ,source, sourceDominant, context );
278 mergeServer_Username( builder, target, source, sourceDominant, context );
279 mergeServer_Password( builder, target, source, sourceDominant, context );
280 mergeServer_PrivateKey( builder, target, source, sourceDominant, context );
281 mergeServer_Passphrase( builder, target, source, sourceDominant, context );
282 mergeServer_FilePermissions( builder, target, source, sourceDominant, context );
283 mergeServer_DirectoryPermissions( builder, target, source, sourceDominant, context );
284 mergeServer_Configuration( builder, target, source, sourceDominant, context );
285 }
286
287 protected void mergeServer_Id( Server.Builder builder, Server target, Server source, boolean sourceDominant, Map<Object, Object> context )
288 {
289 String src = source.getId();
290 String tgt = target.getId();
291 if ( src != null && ( sourceDominant || tgt == null ) )
292 {
293 builder.id( src );
294 }
295 }
296 protected void mergeServer_Username( Server.Builder builder, Server target, Server source, boolean sourceDominant, Map<Object, Object> context )
297 {
298 String src = source.getUsername();
299 String tgt = target.getUsername();
300 if ( src != null && ( sourceDominant || tgt == null ) )
301 {
302 builder.username( src );
303 }
304 }
305 protected void mergeServer_Password( Server.Builder builder, Server target, Server source, boolean sourceDominant, Map<Object, Object> context )
306 {
307 String src = source.getPassword();
308 String tgt = target.getPassword();
309 if ( src != null && ( sourceDominant || tgt == null ) )
310 {
311 builder.password( src );
312 }
313 }
314 protected void mergeServer_PrivateKey( Server.Builder builder, Server target, Server source, boolean sourceDominant, Map<Object, Object> context )
315 {
316 String src = source.getPrivateKey();
317 String tgt = target.getPrivateKey();
318 if ( src != null && ( sourceDominant || tgt == null ) )
319 {
320 builder.privateKey( src );
321 }
322 }
323 protected void mergeServer_Passphrase( Server.Builder builder, Server target, Server source, boolean sourceDominant, Map<Object, Object> context )
324 {
325 String src = source.getPassphrase();
326 String tgt = target.getPassphrase();
327 if ( src != null && ( sourceDominant || tgt == null ) )
328 {
329 builder.passphrase( src );
330 }
331 }
332 protected void mergeServer_FilePermissions( Server.Builder builder, Server target, Server source, boolean sourceDominant, Map<Object, Object> context )
333 {
334 String src = source.getFilePermissions();
335 String tgt = target.getFilePermissions();
336 if ( src != null && ( sourceDominant || tgt == null ) )
337 {
338 builder.filePermissions( src );
339 }
340 }
341 protected void mergeServer_DirectoryPermissions( Server.Builder builder, Server target, Server source, boolean sourceDominant, Map<Object, Object> context )
342 {
343 String src = source.getDirectoryPermissions();
344 String tgt = target.getDirectoryPermissions();
345 if ( src != null && ( sourceDominant || tgt == null ) )
346 {
347 builder.directoryPermissions( src );
348 }
349 }
350 protected void mergeServer_Configuration( Server.Builder builder, Server target, Server source, boolean sourceDominant, Map<Object, Object> context )
351 {
352 Dom src = source.getConfiguration();
353 if ( src != null )
354 {
355 Dom tgt = target.getConfiguration();
356 if ( tgt == null )
357 {
358 builder.configuration( src );
359 }
360 else if ( sourceDominant )
361 {
362 builder.configuration( src.merge( tgt ) );
363 }
364 else
365 {
366 builder.configuration( tgt.merge( src ) );
367 }
368 }
369 }
370
371 protected Mirror mergeMirror( Mirror target, Mirror source, boolean sourceDominant, Map<Object, Object> context )
372 {
373 Mirror.Builder builder = Mirror.newBuilder( target );
374 mergeMirror( builder, target, source, sourceDominant, context );
375 return builder.build();
376 }
377
378 protected void mergeMirror( Mirror.Builder builder, Mirror target, Mirror source, boolean sourceDominant, Map<Object, Object> context )
379 {
380 mergeIdentifiableBase( builder, target ,source, sourceDominant, context );
381 mergeMirror_MirrorOf( builder, target, source, sourceDominant, context );
382 mergeMirror_Name( builder, target, source, sourceDominant, context );
383 mergeMirror_Url( builder, target, source, sourceDominant, context );
384 mergeMirror_Layout( builder, target, source, sourceDominant, context );
385 mergeMirror_MirrorOfLayouts( builder, target, source, sourceDominant, context );
386 mergeMirror_Blocked( builder, target, source, sourceDominant, context );
387 }
388
389 protected void mergeMirror_Id( Mirror.Builder builder, Mirror target, Mirror source, boolean sourceDominant, Map<Object, Object> context )
390 {
391 String src = source.getId();
392 String tgt = target.getId();
393 if ( src != null && ( sourceDominant || tgt == null ) )
394 {
395 builder.id( src );
396 }
397 }
398 protected void mergeMirror_MirrorOf( Mirror.Builder builder, Mirror target, Mirror source, boolean sourceDominant, Map<Object, Object> context )
399 {
400 String src = source.getMirrorOf();
401 String tgt = target.getMirrorOf();
402 if ( src != null && ( sourceDominant || tgt == null ) )
403 {
404 builder.mirrorOf( src );
405 }
406 }
407 protected void mergeMirror_Name( Mirror.Builder builder, Mirror target, Mirror source, boolean sourceDominant, Map<Object, Object> context )
408 {
409 String src = source.getName();
410 String tgt = target.getName();
411 if ( src != null && ( sourceDominant || tgt == null ) )
412 {
413 builder.name( src );
414 }
415 }
416 protected void mergeMirror_Url( Mirror.Builder builder, Mirror target, Mirror source, boolean sourceDominant, Map<Object, Object> context )
417 {
418 String src = source.getUrl();
419 String tgt = target.getUrl();
420 if ( src != null && ( sourceDominant || tgt == null ) )
421 {
422 builder.url( src );
423 }
424 }
425 protected void mergeMirror_Layout( Mirror.Builder builder, Mirror target, Mirror source, boolean sourceDominant, Map<Object, Object> context )
426 {
427 String src = source.getLayout();
428 String tgt = target.getLayout();
429 if ( src != null && ( sourceDominant || tgt == null ) )
430 {
431 builder.layout( src );
432 }
433 }
434 protected void mergeMirror_MirrorOfLayouts( Mirror.Builder builder, Mirror target, Mirror source, boolean sourceDominant, Map<Object, Object> context )
435 {
436 String src = source.getMirrorOfLayouts();
437 String tgt = target.getMirrorOfLayouts();
438 if ( src != null && ( sourceDominant || tgt == null ) )
439 {
440 builder.mirrorOfLayouts( src );
441 }
442 }
443 protected void mergeMirror_Blocked( Mirror.Builder builder, Mirror target, Mirror source, boolean sourceDominant, Map<Object, Object> context )
444 {
445 if ( sourceDominant )
446 {
447 builder.blocked( source.isBlocked() );
448 }
449 }
450
451 protected Profile mergeProfile( Profile target, Profile source, boolean sourceDominant, Map<Object, Object> context )
452 {
453 Profile.Builder builder = Profile.newBuilder( target );
454 mergeProfile( builder, target, source, sourceDominant, context );
455 return builder.build();
456 }
457
458 protected void mergeProfile( Profile.Builder builder, Profile target, Profile source, boolean sourceDominant, Map<Object, Object> context )
459 {
460 mergeIdentifiableBase( builder, target ,source, sourceDominant, context );
461 mergeProfile_Activation( builder, target, source, sourceDominant, context );
462 mergeProfile_Properties( builder, target, source, sourceDominant, context );
463 mergeProfile_Repositories( builder, target, source, sourceDominant, context );
464 mergeProfile_PluginRepositories( builder, target, source, sourceDominant, context );
465 }
466
467 protected void mergeProfile_Id( Profile.Builder builder, Profile target, Profile source, boolean sourceDominant, Map<Object, Object> context )
468 {
469 String src = source.getId();
470 String tgt = target.getId();
471 if ( src != null && ( sourceDominant || tgt == null ) )
472 {
473 builder.id( src );
474 }
475 }
476 protected void mergeProfile_Activation( Profile.Builder builder, Profile target, Profile source, boolean sourceDominant, Map<Object, Object> context )
477 {
478 Activation src = source.getActivation();
479 if ( src != null )
480 {
481 Activation tgt = target.getActivation();
482 if ( tgt == null )
483 {
484 tgt = Activation.newInstance( false );
485 }
486 Activation merged = mergeActivation( tgt, src, sourceDominant, context );
487 if ( merged == src )
488 {
489 builder.activation( merged );
490 }
491 else if ( merged != tgt )
492 {
493 builder.activation( merged );
494 }
495 }
496 }
497 protected void mergeProfile_Properties( Profile.Builder builder, Profile target, Profile source, boolean sourceDominant, Map<Object, Object> context )
498 {
499 Map<String, String> src = source.getProperties();
500 if ( !src.isEmpty() )
501 {
502 Map<String, String> tgt = target.getProperties();
503 if ( tgt.isEmpty() )
504 {
505 builder.properties( src );
506 }
507 else
508 {
509 Map<String, String> merged = new HashMap<>();
510 merged.putAll( sourceDominant ? target.getProperties() : source.getProperties() );
511 merged.putAll( sourceDominant ? source.getProperties() : target.getProperties() );
512 builder.properties( merged );
513 }
514 }
515 }
516 protected void mergeProfile_Repositories( Profile.Builder builder, Profile target, Profile source, boolean sourceDominant, Map<Object, Object> context )
517 {
518 builder.repositories( merge( target.getRepositories(), source.getRepositories(), sourceDominant, getRepositoryKey() ) );
519 }
520 protected void mergeProfile_PluginRepositories( Profile.Builder builder, Profile target, Profile source, boolean sourceDominant, Map<Object, Object> context )
521 {
522 builder.pluginRepositories( merge( target.getPluginRepositories(), source.getPluginRepositories(), sourceDominant, getRepositoryKey() ) );
523 }
524
525 protected Activation mergeActivation( Activation target, Activation source, boolean sourceDominant, Map<Object, Object> context )
526 {
527 Activation.Builder builder = Activation.newBuilder( target );
528 mergeActivation( builder, target, source, sourceDominant, context );
529 return builder.build();
530 }
531
532 protected void mergeActivation( Activation.Builder builder, Activation target, Activation source, boolean sourceDominant, Map<Object, Object> context )
533 {
534 mergeActivation_ActiveByDefault( builder, target, source, sourceDominant, context );
535 mergeActivation_Jdk( builder, target, source, sourceDominant, context );
536 mergeActivation_Os( builder, target, source, sourceDominant, context );
537 mergeActivation_Property( builder, target, source, sourceDominant, context );
538 mergeActivation_File( builder, target, source, sourceDominant, context );
539 }
540
541 protected void mergeActivation_ActiveByDefault( Activation.Builder builder, Activation target, Activation source, boolean sourceDominant, Map<Object, Object> context )
542 {
543 if ( sourceDominant )
544 {
545 builder.activeByDefault( source.isActiveByDefault() );
546 }
547 }
548 protected void mergeActivation_Jdk( Activation.Builder builder, Activation target, Activation source, boolean sourceDominant, Map<Object, Object> context )
549 {
550 String src = source.getJdk();
551 String tgt = target.getJdk();
552 if ( src != null && ( sourceDominant || tgt == null ) )
553 {
554 builder.jdk( src );
555 }
556 }
557 protected void mergeActivation_Os( Activation.Builder builder, Activation target, Activation source, boolean sourceDominant, Map<Object, Object> context )
558 {
559 ActivationOS src = source.getOs();
560 if ( src != null )
561 {
562 ActivationOS tgt = target.getOs();
563 if ( tgt == null )
564 {
565 tgt = ActivationOS.newInstance( false );
566 }
567 ActivationOS merged = mergeActivationOS( tgt, src, sourceDominant, context );
568 if ( merged == src )
569 {
570 builder.os( merged );
571 }
572 else if ( merged != tgt )
573 {
574 builder.os( merged );
575 }
576 }
577 }
578 protected void mergeActivation_Property( Activation.Builder builder, Activation target, Activation source, boolean sourceDominant, Map<Object, Object> context )
579 {
580 ActivationProperty src = source.getProperty();
581 if ( src != null )
582 {
583 ActivationProperty tgt = target.getProperty();
584 if ( tgt == null )
585 {
586 tgt = ActivationProperty.newInstance( false );
587 }
588 ActivationProperty merged = mergeActivationProperty( tgt, src, sourceDominant, context );
589 if ( merged == src )
590 {
591 builder.property( merged );
592 }
593 else if ( merged != tgt )
594 {
595 builder.property( merged );
596 }
597 }
598 }
599 protected void mergeActivation_File( Activation.Builder builder, Activation target, Activation source, boolean sourceDominant, Map<Object, Object> context )
600 {
601 ActivationFile src = source.getFile();
602 if ( src != null )
603 {
604 ActivationFile tgt = target.getFile();
605 if ( tgt == null )
606 {
607 tgt = ActivationFile.newInstance( false );
608 }
609 ActivationFile merged = mergeActivationFile( tgt, src, sourceDominant, context );
610 if ( merged == src )
611 {
612 builder.file( merged );
613 }
614 else if ( merged != tgt )
615 {
616 builder.file( merged );
617 }
618 }
619 }
620
621 protected RepositoryBase mergeRepositoryBase( RepositoryBase target, RepositoryBase source, boolean sourceDominant, Map<Object, Object> context )
622 {
623 RepositoryBase.Builder builder = RepositoryBase.newBuilder( target );
624 mergeRepositoryBase( builder, target, source, sourceDominant, context );
625 return builder.build();
626 }
627
628 protected void mergeRepositoryBase( RepositoryBase.Builder builder, RepositoryBase target, RepositoryBase source, boolean sourceDominant, Map<Object, Object> context )
629 {
630 mergeRepositoryBase_Id( builder, target, source, sourceDominant, context );
631 mergeRepositoryBase_Name( builder, target, source, sourceDominant, context );
632 mergeRepositoryBase_Url( builder, target, source, sourceDominant, context );
633 mergeRepositoryBase_Layout( builder, target, source, sourceDominant, context );
634 }
635
636 protected void mergeRepositoryBase_Id( RepositoryBase.Builder builder, RepositoryBase target, RepositoryBase source, boolean sourceDominant, Map<Object, Object> context )
637 {
638 String src = source.getId();
639 String tgt = target.getId();
640 if ( src != null && ( sourceDominant || tgt == null ) )
641 {
642 builder.id( src );
643 }
644 }
645 protected void mergeRepositoryBase_Name( RepositoryBase.Builder builder, RepositoryBase target, RepositoryBase source, boolean sourceDominant, Map<Object, Object> context )
646 {
647 String src = source.getName();
648 String tgt = target.getName();
649 if ( src != null && ( sourceDominant || tgt == null ) )
650 {
651 builder.name( src );
652 }
653 }
654 protected void mergeRepositoryBase_Url( RepositoryBase.Builder builder, RepositoryBase target, RepositoryBase source, boolean sourceDominant, Map<Object, Object> context )
655 {
656 String src = source.getUrl();
657 String tgt = target.getUrl();
658 if ( src != null && ( sourceDominant || tgt == null ) )
659 {
660 builder.url( src );
661 }
662 }
663 protected void mergeRepositoryBase_Layout( RepositoryBase.Builder builder, RepositoryBase target, RepositoryBase source, boolean sourceDominant, Map<Object, Object> context )
664 {
665 String src = source.getLayout();
666 String tgt = target.getLayout();
667 if ( src != null && ( sourceDominant || tgt == null ) )
668 {
669 builder.layout( src );
670 }
671 }
672
673 protected Repository mergeRepository( Repository target, Repository source, boolean sourceDominant, Map<Object, Object> context )
674 {
675 Repository.Builder builder = Repository.newBuilder( target );
676 mergeRepository( builder, target, source, sourceDominant, context );
677 return builder.build();
678 }
679
680 protected void mergeRepository( Repository.Builder builder, Repository target, Repository source, boolean sourceDominant, Map<Object, Object> context )
681 {
682 mergeRepositoryBase( builder, target ,source, sourceDominant, context );
683 mergeRepository_Releases( builder, target, source, sourceDominant, context );
684 mergeRepository_Snapshots( builder, target, source, sourceDominant, context );
685 }
686
687 protected void mergeRepository_Id( Repository.Builder builder, Repository target, Repository source, boolean sourceDominant, Map<Object, Object> context )
688 {
689 String src = source.getId();
690 String tgt = target.getId();
691 if ( src != null && ( sourceDominant || tgt == null ) )
692 {
693 builder.id( src );
694 }
695 }
696 protected void mergeRepository_Name( Repository.Builder builder, Repository target, Repository source, boolean sourceDominant, Map<Object, Object> context )
697 {
698 String src = source.getName();
699 String tgt = target.getName();
700 if ( src != null && ( sourceDominant || tgt == null ) )
701 {
702 builder.name( src );
703 }
704 }
705 protected void mergeRepository_Url( Repository.Builder builder, Repository target, Repository source, boolean sourceDominant, Map<Object, Object> context )
706 {
707 String src = source.getUrl();
708 String tgt = target.getUrl();
709 if ( src != null && ( sourceDominant || tgt == null ) )
710 {
711 builder.url( src );
712 }
713 }
714 protected void mergeRepository_Layout( Repository.Builder builder, Repository target, Repository source, boolean sourceDominant, Map<Object, Object> context )
715 {
716 String src = source.getLayout();
717 String tgt = target.getLayout();
718 if ( src != null && ( sourceDominant || tgt == null ) )
719 {
720 builder.layout( src );
721 }
722 }
723 protected void mergeRepository_Releases( Repository.Builder builder, Repository target, Repository source, boolean sourceDominant, Map<Object, Object> context )
724 {
725 RepositoryPolicy src = source.getReleases();
726 if ( src != null )
727 {
728 RepositoryPolicy tgt = target.getReleases();
729 if ( tgt == null )
730 {
731 tgt = RepositoryPolicy.newInstance( false );
732 }
733 RepositoryPolicy merged = mergeRepositoryPolicy( tgt, src, sourceDominant, context );
734 if ( merged == src )
735 {
736 builder.releases( merged );
737 }
738 else if ( merged != tgt )
739 {
740 builder.releases( merged );
741 }
742 }
743 }
744 protected void mergeRepository_Snapshots( Repository.Builder builder, Repository target, Repository source, boolean sourceDominant, Map<Object, Object> context )
745 {
746 RepositoryPolicy src = source.getSnapshots();
747 if ( src != null )
748 {
749 RepositoryPolicy tgt = target.getSnapshots();
750 if ( tgt == null )
751 {
752 tgt = RepositoryPolicy.newInstance( false );
753 }
754 RepositoryPolicy merged = mergeRepositoryPolicy( tgt, src, sourceDominant, context );
755 if ( merged == src )
756 {
757 builder.snapshots( merged );
758 }
759 else if ( merged != tgt )
760 {
761 builder.snapshots( merged );
762 }
763 }
764 }
765
766 protected RepositoryPolicy mergeRepositoryPolicy( RepositoryPolicy target, RepositoryPolicy source, boolean sourceDominant, Map<Object, Object> context )
767 {
768 RepositoryPolicy.Builder builder = RepositoryPolicy.newBuilder( target );
769 mergeRepositoryPolicy( builder, target, source, sourceDominant, context );
770 return builder.build();
771 }
772
773 protected void mergeRepositoryPolicy( RepositoryPolicy.Builder builder, RepositoryPolicy target, RepositoryPolicy source, boolean sourceDominant, Map<Object, Object> context )
774 {
775 mergeRepositoryPolicy_Enabled( builder, target, source, sourceDominant, context );
776 mergeRepositoryPolicy_UpdatePolicy( builder, target, source, sourceDominant, context );
777 mergeRepositoryPolicy_ChecksumPolicy( builder, target, source, sourceDominant, context );
778 }
779
780 protected void mergeRepositoryPolicy_Enabled( RepositoryPolicy.Builder builder, RepositoryPolicy target, RepositoryPolicy source, boolean sourceDominant, Map<Object, Object> context )
781 {
782 if ( sourceDominant )
783 {
784 builder.enabled( source.isEnabled() );
785 }
786 }
787 protected void mergeRepositoryPolicy_UpdatePolicy( RepositoryPolicy.Builder builder, RepositoryPolicy target, RepositoryPolicy source, boolean sourceDominant, Map<Object, Object> context )
788 {
789 String src = source.getUpdatePolicy();
790 String tgt = target.getUpdatePolicy();
791 if ( src != null && ( sourceDominant || tgt == null ) )
792 {
793 builder.updatePolicy( src );
794 }
795 }
796 protected void mergeRepositoryPolicy_ChecksumPolicy( RepositoryPolicy.Builder builder, RepositoryPolicy target, RepositoryPolicy source, boolean sourceDominant, Map<Object, Object> context )
797 {
798 String src = source.getChecksumPolicy();
799 String tgt = target.getChecksumPolicy();
800 if ( src != null && ( sourceDominant || tgt == null ) )
801 {
802 builder.checksumPolicy( src );
803 }
804 }
805
806 protected ActivationProperty mergeActivationProperty( ActivationProperty target, ActivationProperty source, boolean sourceDominant, Map<Object, Object> context )
807 {
808 ActivationProperty.Builder builder = ActivationProperty.newBuilder( target );
809 mergeActivationProperty( builder, target, source, sourceDominant, context );
810 return builder.build();
811 }
812
813 protected void mergeActivationProperty( ActivationProperty.Builder builder, ActivationProperty target, ActivationProperty source, boolean sourceDominant, Map<Object, Object> context )
814 {
815 mergeActivationProperty_Name( builder, target, source, sourceDominant, context );
816 mergeActivationProperty_Value( builder, target, source, sourceDominant, context );
817 }
818
819 protected void mergeActivationProperty_Name( ActivationProperty.Builder builder, ActivationProperty target, ActivationProperty source, boolean sourceDominant, Map<Object, Object> context )
820 {
821 String src = source.getName();
822 String tgt = target.getName();
823 if ( src != null && ( sourceDominant || tgt == null ) )
824 {
825 builder.name( src );
826 }
827 }
828 protected void mergeActivationProperty_Value( ActivationProperty.Builder builder, ActivationProperty target, ActivationProperty source, boolean sourceDominant, Map<Object, Object> context )
829 {
830 String src = source.getValue();
831 String tgt = target.getValue();
832 if ( src != null && ( sourceDominant || tgt == null ) )
833 {
834 builder.value( src );
835 }
836 }
837
838 protected ActivationOS mergeActivationOS( ActivationOS target, ActivationOS source, boolean sourceDominant, Map<Object, Object> context )
839 {
840 ActivationOS.Builder builder = ActivationOS.newBuilder( target );
841 mergeActivationOS( builder, target, source, sourceDominant, context );
842 return builder.build();
843 }
844
845 protected void mergeActivationOS( ActivationOS.Builder builder, ActivationOS target, ActivationOS source, boolean sourceDominant, Map<Object, Object> context )
846 {
847 mergeActivationOS_Name( builder, target, source, sourceDominant, context );
848 mergeActivationOS_Family( builder, target, source, sourceDominant, context );
849 mergeActivationOS_Arch( builder, target, source, sourceDominant, context );
850 mergeActivationOS_Version( builder, target, source, sourceDominant, context );
851 }
852
853 protected void mergeActivationOS_Name( ActivationOS.Builder builder, ActivationOS target, ActivationOS source, boolean sourceDominant, Map<Object, Object> context )
854 {
855 String src = source.getName();
856 String tgt = target.getName();
857 if ( src != null && ( sourceDominant || tgt == null ) )
858 {
859 builder.name( src );
860 }
861 }
862 protected void mergeActivationOS_Family( ActivationOS.Builder builder, ActivationOS target, ActivationOS source, boolean sourceDominant, Map<Object, Object> context )
863 {
864 String src = source.getFamily();
865 String tgt = target.getFamily();
866 if ( src != null && ( sourceDominant || tgt == null ) )
867 {
868 builder.family( src );
869 }
870 }
871 protected void mergeActivationOS_Arch( ActivationOS.Builder builder, ActivationOS target, ActivationOS source, boolean sourceDominant, Map<Object, Object> context )
872 {
873 String src = source.getArch();
874 String tgt = target.getArch();
875 if ( src != null && ( sourceDominant || tgt == null ) )
876 {
877 builder.arch( src );
878 }
879 }
880 protected void mergeActivationOS_Version( ActivationOS.Builder builder, ActivationOS target, ActivationOS source, boolean sourceDominant, Map<Object, Object> context )
881 {
882 String src = source.getVersion();
883 String tgt = target.getVersion();
884 if ( src != null && ( sourceDominant || tgt == null ) )
885 {
886 builder.version( src );
887 }
888 }
889
890 protected ActivationFile mergeActivationFile( ActivationFile target, ActivationFile source, boolean sourceDominant, Map<Object, Object> context )
891 {
892 ActivationFile.Builder builder = ActivationFile.newBuilder( target );
893 mergeActivationFile( builder, target, source, sourceDominant, context );
894 return builder.build();
895 }
896
897 protected void mergeActivationFile( ActivationFile.Builder builder, ActivationFile target, ActivationFile source, boolean sourceDominant, Map<Object, Object> context )
898 {
899 mergeActivationFile_Missing( builder, target, source, sourceDominant, context );
900 mergeActivationFile_Exists( builder, target, source, sourceDominant, context );
901 }
902
903 protected void mergeActivationFile_Missing( ActivationFile.Builder builder, ActivationFile target, ActivationFile source, boolean sourceDominant, Map<Object, Object> context )
904 {
905 String src = source.getMissing();
906 String tgt = target.getMissing();
907 if ( src != null && ( sourceDominant || tgt == null ) )
908 {
909 builder.missing( src );
910 }
911 }
912 protected void mergeActivationFile_Exists( ActivationFile.Builder builder, ActivationFile target, ActivationFile source, boolean sourceDominant, Map<Object, Object> context )
913 {
914 String src = source.getExists();
915 String tgt = target.getExists();
916 if ( src != null && ( sourceDominant || tgt == null ) )
917 {
918 builder.exists( src );
919 }
920 }
921
922
923 protected KeyComputer<TrackableBase> getTrackableBaseKey()
924 {
925 return v -> v;
926 }
927 protected KeyComputer<IdentifiableBase> getIdentifiableBaseKey()
928 {
929 return v -> v;
930 }
931 protected KeyComputer<Settings> getSettingsKey()
932 {
933 return v -> v;
934 }
935 protected KeyComputer<Proxy> getProxyKey()
936 {
937 return v -> v;
938 }
939 protected KeyComputer<Server> getServerKey()
940 {
941 return v -> v;
942 }
943 protected KeyComputer<Mirror> getMirrorKey()
944 {
945 return v -> v;
946 }
947 protected KeyComputer<Profile> getProfileKey()
948 {
949 return v -> v;
950 }
951 protected KeyComputer<Activation> getActivationKey()
952 {
953 return v -> v;
954 }
955 protected KeyComputer<RepositoryBase> getRepositoryBaseKey()
956 {
957 return v -> v;
958 }
959 protected KeyComputer<Repository> getRepositoryKey()
960 {
961 return v -> v;
962 }
963 protected KeyComputer<RepositoryPolicy> getRepositoryPolicyKey()
964 {
965 return v -> v;
966 }
967 protected KeyComputer<ActivationProperty> getActivationPropertyKey()
968 {
969 return v -> v;
970 }
971 protected KeyComputer<ActivationOS> getActivationOSKey()
972 {
973 return v -> v;
974 }
975 protected KeyComputer<ActivationFile> getActivationFileKey()
976 {
977 return v -> v;
978 }
979
980
981
982
983
984 @FunctionalInterface
985 public interface KeyComputer<T> extends Function<T, Object>
986 {
987 }
988
989
990
991
992 public static <T> List<T> merge( List<T> tgt, List<T> src, boolean sourceDominant, KeyComputer<T> computer )
993 {
994 return merge( tgt, src, computer, ( t, s ) -> sourceDominant ? s : t );
995 }
996
997 public static <T> List<T> merge( List<T> tgt, List<T> src, KeyComputer<T> computer, BinaryOperator<T> remapping )
998 {
999 if ( src.isEmpty() )
1000 {
1001 return tgt;
1002 }
1003
1004 MergingList<T> list;
1005 if ( tgt instanceof MergingList )
1006 {
1007 list = (MergingList<T>) tgt;
1008 }
1009 else
1010 {
1011 list = new MergingList<>( computer, src.size() + tgt.size() );
1012 list.mergeAll( tgt, ( t, s ) -> s );
1013 }
1014
1015 list.mergeAll( src, remapping );
1016 return list;
1017 }
1018
1019
1020
1021
1022
1023 private static class MergingList<V> extends AbstractList<V> implements java.io.Serializable
1024 {
1025
1026 private final KeyComputer<V> keyComputer;
1027 private Map<Object, V> map;
1028 private List<V> list;
1029
1030 MergingList( KeyComputer<V> keyComputer, int initialCapacity )
1031 {
1032 this.map = new LinkedHashMap<>( initialCapacity );
1033 this.keyComputer = keyComputer;
1034 }
1035
1036 Object writeReplace() throws ObjectStreamException
1037 {
1038 return new ArrayList<>( this );
1039 }
1040
1041 @Override
1042 public Iterator<V> iterator()
1043 {
1044 if ( map != null )
1045 {
1046 return map.values().iterator();
1047 }
1048 else
1049 {
1050 return list.iterator();
1051 }
1052 }
1053
1054 void mergeAll( Collection<V> vs, BinaryOperator<V> remapping )
1055 {
1056 if ( map == null )
1057 {
1058 map = list.stream().collect( Collectors.toMap( keyComputer,
1059 Function.identity(),
1060 null,
1061 LinkedHashMap::new ) );
1062
1063 list = null;
1064 }
1065
1066 if ( vs instanceof MergingList && ( (MergingList<V>) vs ).map != null )
1067 {
1068 for ( Map.Entry<Object, V> e : ( (MergingList<V>) vs ).map.entrySet() )
1069 {
1070 Object key = e.getKey();
1071 V v = e.getValue();
1072 map.merge( key, v, remapping );
1073 }
1074 }
1075 else
1076 {
1077 for ( V v : vs )
1078 {
1079 Object key = keyComputer.apply( v );
1080
1081 map.merge( key, v, remapping );
1082 }
1083 }
1084 }
1085
1086 @Override
1087 public boolean contains( Object o )
1088 {
1089 if ( map != null )
1090 {
1091 return map.containsValue( o );
1092 }
1093 else
1094 {
1095 return list.contains( o );
1096 }
1097 }
1098
1099 private List<V> asList()
1100 {
1101 if ( list == null )
1102 {
1103 list = new ArrayList<>( map.values() );
1104 map = null;
1105 }
1106 return list;
1107 }
1108
1109 @Override
1110 public void add( int index, V element )
1111 {
1112 asList().add( index, element );
1113 }
1114
1115 @Override
1116 public V remove( int index )
1117 {
1118 return asList().remove( index );
1119 }
1120
1121 @Override
1122 public V get( int index )
1123 {
1124 return asList().get( index );
1125 }
1126
1127 @Override
1128 public int size()
1129 {
1130 if ( map != null )
1131 {
1132 return map.size();
1133 }
1134 else
1135 {
1136 return list.size();
1137 }
1138 }
1139 }
1140 }