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 @Component( role = DependencyManagementInjector.class )
42 public class DefaultDependencyManagementInjector
43 implements DependencyManagementInjector
44 {
45
46 private ManagementModelMerger merger = new ManagementModelMerger();
47
48 @Override
49 public void injectManagement( Model model, ModelBuildingRequest request, ModelProblemCollector problems )
50 {
51 merger.mergeManagedDependencies( model );
52 }
53
54 protected static class ManagementModelMerger
55 extends MavenModelMerger
56 {
57
58 public void mergeManagedDependencies( Model model )
59 {
60 DependencyManagement dependencyManagement = model.getDependencyManagement();
61 if ( dependencyManagement != null )
62 {
63 Map<Object, Dependency> dependencies = new HashMap<Object, Dependency>();
64 Map<Object, Object> context = Collections.emptyMap();
65
66 for ( Dependency dependency : model.getDependencies() )
67 {
68 Object key = getDependencyKey( dependency );
69 dependencies.put( key, dependency );
70 }
71
72 for ( Dependency managedDependency : dependencyManagement.getDependencies() )
73 {
74 Object key = getDependencyKey( managedDependency );
75 Dependency dependency = dependencies.get( key );
76 if ( dependency != null )
77 {
78 mergeDependency( dependency, managedDependency, false, context );
79 }
80 }
81 }
82 }
83
84 @Override
85 protected void mergeDependency_Optional( Dependency target, Dependency source, boolean sourceDominant,
86 Map<Object, Object> context )
87 {
88
89 }
90
91 @Override
92 protected void mergeDependency_Exclusions( Dependency target, Dependency source, boolean sourceDominant,
93 Map<Object, Object> context )
94 {
95 List<Exclusion> tgt = target.getExclusions();
96 if ( tgt.isEmpty() )
97 {
98 List<Exclusion> src = source.getExclusions();
99
100 for ( Exclusion element : src )
101 {
102 Exclusion clone = element.clone();
103 target.addExclusion( clone );
104 }
105 }
106 }
107
108 }
109
110 }