1 package org.apache.maven.model.management;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Collections;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26
27 import org.apache.maven.model.Dependency;
28 import org.apache.maven.model.DependencyManagement;
29 import org.apache.maven.model.Exclusion;
30 import org.apache.maven.model.Model;
31 import org.apache.maven.model.building.ModelBuildingRequest;
32 import org.apache.maven.model.building.ModelProblemCollector;
33 import org.apache.maven.model.merge.MavenModelMerger;
34 import org.codehaus.plexus.component.annotations.Component;
35
36
37
38
39
40
41 @SuppressWarnings( { "checkstyle:methodname" } )
42 @Component( role = DependencyManagementInjector.class )
43 public class DefaultDependencyManagementInjector
44 implements DependencyManagementInjector
45 {
46
47 private ManagementModelMerger merger = new ManagementModelMerger();
48
49 @Override
50 public void injectManagement( Model model, ModelBuildingRequest request, ModelProblemCollector problems )
51 {
52 merger.mergeManagedDependencies( model );
53 }
54
55
56
57
58 protected static class ManagementModelMerger
59 extends MavenModelMerger
60 {
61
62 public void mergeManagedDependencies( Model model )
63 {
64 DependencyManagement dependencyManagement = model.getDependencyManagement();
65 if ( dependencyManagement != null )
66 {
67 Map<Object, Dependency> dependencies = new HashMap<>();
68 Map<Object, Object> context = Collections.emptyMap();
69
70 for ( Dependency dependency : model.getDependencies() )
71 {
72 Object key = getDependencyKey( dependency );
73 dependencies.put( key, dependency );
74 }
75
76 for ( Dependency managedDependency : dependencyManagement.getDependencies() )
77 {
78 Object key = getDependencyKey( managedDependency );
79 Dependency dependency = dependencies.get( key );
80 if ( dependency != null )
81 {
82 mergeDependency( dependency, managedDependency, false, context );
83 }
84 }
85 }
86 }
87
88 @Override
89 protected void mergeDependency_Optional( Dependency target, Dependency source, boolean sourceDominant,
90 Map<Object, Object> context )
91 {
92
93 }
94
95 @Override
96 protected void mergeDependency_Exclusions( Dependency target, Dependency source, boolean sourceDominant,
97 Map<Object, Object> context )
98 {
99 List<Exclusion> tgt = target.getExclusions();
100 if ( tgt.isEmpty() )
101 {
102 List<Exclusion> src = source.getExclusions();
103
104 for ( Exclusion element : src )
105 {
106 Exclusion clone = element.clone();
107 target.addExclusion( clone );
108 }
109 }
110 }
111
112 }
113
114 }