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