1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.shared.dependency.graph;
20
21 import java.util.HashMap;
22 import java.util.Map;
23 import java.util.Objects;
24
25 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
26 import org.apache.maven.project.ProjectBuildingRequest;
27 import org.apache.maven.shared.dependency.graph.internal.DirectScopeDependencySelector;
28 import org.apache.maven.shared.dependency.graph.internal.VerboseJavaScopeSelector;
29 import org.eclipse.aether.collection.DependencyGraphTransformer;
30 import org.eclipse.aether.collection.DependencySelector;
31 import org.eclipse.aether.util.artifact.JavaScopes;
32 import org.eclipse.aether.util.graph.manager.DependencyManagerUtils;
33 import org.eclipse.aether.util.graph.selector.AndDependencySelector;
34 import org.eclipse.aether.util.graph.selector.ExclusionDependencySelector;
35 import org.eclipse.aether.util.graph.selector.OptionalDependencySelector;
36 import org.eclipse.aether.util.graph.transformer.ConflictResolver;
37 import org.eclipse.aether.util.graph.transformer.JavaScopeDeriver;
38 import org.eclipse.aether.util.graph.transformer.NearestVersionSelector;
39 import org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector;
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79 public class DependencyCollectorRequest {
80
81 private final ProjectBuildingRequest buildingRequest;
82
83 private ArtifactFilter filter;
84
85 private Map<String, Object> configProperties = new HashMap<>();
86
87 private DependencySelector dependencySelector = new AndDependencySelector(
88 new DirectScopeDependencySelector(JavaScopes.TEST),
89 new DirectScopeDependencySelector(JavaScopes.PROVIDED),
90 new OptionalDependencySelector(),
91 new ExclusionDependencySelector());
92
93 private DependencyGraphTransformer dependencyGraphTransformer = new ConflictResolver(
94 new NearestVersionSelector(),
95 new VerboseJavaScopeSelector(),
96 new SimpleOptionalitySelector(),
97 new JavaScopeDeriver());
98
99 public DependencyCollectorRequest(ProjectBuildingRequest buildingRequest) {
100 this(buildingRequest, null);
101 }
102
103 public DependencyCollectorRequest(ProjectBuildingRequest buildingRequest, ArtifactFilter filter) {
104 Objects.requireNonNull(buildingRequest, "ProjectBuildingRequest cannot be null");
105 this.buildingRequest = buildingRequest;
106 this.filter = filter;
107 configProperties.put(ConflictResolver.CONFIG_PROP_VERBOSE, true);
108 configProperties.put(DependencyManagerUtils.CONFIG_PROP_VERBOSE, true);
109 }
110
111 public ProjectBuildingRequest getBuildingRequest() {
112 return buildingRequest;
113 }
114
115 public ArtifactFilter getFilter() {
116 return filter;
117 }
118
119 public DependencySelector getDependencySelector() {
120 return dependencySelector;
121 }
122
123 public DependencyCollectorRequest dependencySelector(DependencySelector dependencySelector) {
124 this.dependencySelector = dependencySelector;
125 return this;
126 }
127
128 public DependencyGraphTransformer getDependencyGraphTransformer() {
129 return dependencyGraphTransformer;
130 }
131
132 public DependencyCollectorRequest dependencyGraphTransformer(
133 DependencyGraphTransformer dependencyGraphTransformer) {
134 this.dependencyGraphTransformer = dependencyGraphTransformer;
135 return this;
136 }
137
138 public Map<String, Object> getConfigProperties() {
139 return this.configProperties;
140 }
141
142 public void addConfigProperty(String key, Object value) {
143 this.configProperties.put(key, value);
144 }
145
146 public void removeConfigProperty(String key) {
147 this.configProperties.remove(key);
148 }
149 }