1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.model.composition;
20
21 import javax.inject.Named;
22 import javax.inject.Singleton;
23
24 import java.util.ArrayList;
25 import java.util.LinkedHashMap;
26 import java.util.List;
27 import java.util.Map;
28
29 import org.apache.maven.model.Dependency;
30 import org.apache.maven.model.DependencyManagement;
31 import org.apache.maven.model.Model;
32 import org.apache.maven.model.building.ModelBuildingRequest;
33 import org.apache.maven.model.building.ModelProblemCollector;
34
35
36
37
38
39
40 @Named
41 @Singleton
42 public class DefaultDependencyManagementImporter implements DependencyManagementImporter {
43
44 @Override
45 public void importManagement(
46 Model target,
47 List<? extends DependencyManagement> sources,
48 ModelBuildingRequest request,
49 ModelProblemCollector problems) {
50 if (sources != null && !sources.isEmpty()) {
51 Map<String, Dependency> dependencies = new LinkedHashMap<>();
52
53 DependencyManagement depMgmt = target.getDependencyManagement();
54
55 if (depMgmt != null) {
56 for (Dependency dependency : depMgmt.getDependencies()) {
57 dependencies.put(dependency.getManagementKey(), dependency);
58 }
59 } else {
60 depMgmt = new DependencyManagement();
61 target.setDependencyManagement(depMgmt);
62 }
63
64 for (DependencyManagement source : sources) {
65 for (Dependency dependency : source.getDependencies()) {
66 String key = dependency.getManagementKey();
67 if (!dependencies.containsKey(key)) {
68 dependencies.put(key, dependency);
69 }
70 }
71 }
72
73 depMgmt.setDependencies(new ArrayList<>(dependencies.values()));
74 }
75 }
76 }