1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.repository.internal.scopes;
20
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.Collection;
24 import java.util.Collections;
25 import java.util.stream.Collectors;
26
27 import org.eclipse.aether.artifact.ArtifactProperties;
28 import org.eclipse.aether.impl.scope.BuildScopeMatrixSource;
29 import org.eclipse.aether.impl.scope.BuildScopeSource;
30 import org.eclipse.aether.impl.scope.CommonBuilds;
31 import org.eclipse.aether.impl.scope.InternalScopeManager;
32 import org.eclipse.aether.impl.scope.ScopeManagerConfiguration;
33 import org.eclipse.aether.internal.impl.scope.ScopeManagerDump;
34 import org.eclipse.aether.scope.DependencyScope;
35 import org.eclipse.aether.scope.ResolutionScope;
36
37 import static org.eclipse.aether.impl.scope.BuildScopeQuery.all;
38 import static org.eclipse.aether.impl.scope.BuildScopeQuery.byBuildPath;
39 import static org.eclipse.aether.impl.scope.BuildScopeQuery.byProjectPath;
40 import static org.eclipse.aether.impl.scope.BuildScopeQuery.select;
41 import static org.eclipse.aether.impl.scope.BuildScopeQuery.singleton;
42 import static org.eclipse.aether.impl.scope.BuildScopeQuery.union;
43
44
45
46
47
48
49
50
51
52 @Deprecated(since = "4.0.0")
53 public final class Maven3ScopeManagerConfiguration implements ScopeManagerConfiguration {
54 public static final Maven3ScopeManagerConfiguration INSTANCE = new Maven3ScopeManagerConfiguration();
55 public static final String DS_COMPILE = "compile";
56 public static final String DS_RUNTIME = "runtime";
57 public static final String DS_PROVIDED = "provided";
58 public static final String DS_SYSTEM = "system";
59 public static final String DS_TEST = "test";
60 public static final String RS_NONE = "none";
61 public static final String RS_MAIN_COMPILE = "main-compile";
62 public static final String RS_MAIN_COMPILE_PLUS_RUNTIME = "main-compilePlusRuntime";
63 public static final String RS_MAIN_RUNTIME = "main-runtime";
64 public static final String RS_MAIN_RUNTIME_PLUS_SYSTEM = "main-runtimePlusSystem";
65 public static final String RS_TEST_COMPILE = "test-compile";
66 public static final String RS_TEST_RUNTIME = "test-runtime";
67
68 private Maven3ScopeManagerConfiguration() {}
69
70 @Override
71 public String getId() {
72 return "Maven3";
73 }
74
75 @Override
76 public boolean isStrictDependencyScopes() {
77 return false;
78 }
79
80 @Override
81 public boolean isStrictResolutionScopes() {
82 return false;
83 }
84
85 @Override
86 public BuildScopeSource getBuildScopeSource() {
87 return new BuildScopeMatrixSource(
88 Collections.singletonList(CommonBuilds.PROJECT_PATH_MAIN),
89 Arrays.asList(CommonBuilds.BUILD_PATH_COMPILE, CommonBuilds.BUILD_PATH_RUNTIME),
90 CommonBuilds.MAVEN_TEST_BUILD_SCOPE);
91 }
92
93 @Override
94 public Collection<DependencyScope> buildDependencyScopes(InternalScopeManager internalScopeManager) {
95 ArrayList<DependencyScope> result = new ArrayList<>();
96 result.add(internalScopeManager.createDependencyScope(DS_COMPILE, true, all()));
97 result.add(internalScopeManager.createDependencyScope(
98 DS_RUNTIME, true, byBuildPath(CommonBuilds.BUILD_PATH_RUNTIME)));
99 result.add(internalScopeManager.createDependencyScope(
100 DS_PROVIDED,
101 false,
102 union(
103 byBuildPath(CommonBuilds.BUILD_PATH_COMPILE),
104 select(CommonBuilds.PROJECT_PATH_TEST, CommonBuilds.BUILD_PATH_RUNTIME))));
105 result.add(internalScopeManager.createDependencyScope(
106 DS_TEST, false, byProjectPath(CommonBuilds.PROJECT_PATH_TEST)));
107 result.add(internalScopeManager.createSystemDependencyScope(
108 DS_SYSTEM, false, all(), ArtifactProperties.LOCAL_PATH));
109 return result;
110 }
111
112 @Override
113 public Collection<ResolutionScope> buildResolutionScopes(InternalScopeManager internalScopeManager) {
114 Collection<DependencyScope> allDependencyScopes = internalScopeManager.getDependencyScopeUniverse();
115 Collection<DependencyScope> nonTransitiveDependencyScopes =
116 allDependencyScopes.stream().filter(s -> !s.isTransitive()).collect(Collectors.toSet());
117 DependencyScope system =
118 internalScopeManager.getDependencyScope(DS_SYSTEM).orElse(null);
119
120 ArrayList<ResolutionScope> result = new ArrayList<>();
121 result.add(internalScopeManager.createResolutionScope(
122 RS_NONE,
123 InternalScopeManager.Mode.REMOVE,
124 Collections.emptySet(),
125 Collections.emptySet(),
126 allDependencyScopes));
127 result.add(internalScopeManager.createResolutionScope(
128 RS_MAIN_COMPILE,
129 InternalScopeManager.Mode.ELIMINATE,
130 singleton(CommonBuilds.PROJECT_PATH_MAIN, CommonBuilds.BUILD_PATH_COMPILE),
131 Collections.singletonList(system),
132 nonTransitiveDependencyScopes));
133 result.add(internalScopeManager.createResolutionScope(
134 RS_MAIN_COMPILE_PLUS_RUNTIME,
135 InternalScopeManager.Mode.ELIMINATE,
136 byProjectPath(CommonBuilds.PROJECT_PATH_MAIN),
137 Collections.singletonList(system),
138 nonTransitiveDependencyScopes));
139 result.add(internalScopeManager.createResolutionScope(
140 RS_MAIN_RUNTIME,
141 InternalScopeManager.Mode.ELIMINATE,
142 singleton(CommonBuilds.PROJECT_PATH_MAIN, CommonBuilds.BUILD_PATH_RUNTIME),
143 Collections.emptySet(),
144 nonTransitiveDependencyScopes));
145 result.add(internalScopeManager.createResolutionScope(
146 RS_MAIN_RUNTIME_PLUS_SYSTEM,
147 InternalScopeManager.Mode.ELIMINATE,
148 singleton(CommonBuilds.PROJECT_PATH_MAIN, CommonBuilds.BUILD_PATH_RUNTIME),
149 Collections.singletonList(system),
150 nonTransitiveDependencyScopes));
151 result.add(internalScopeManager.createResolutionScope(
152 RS_TEST_COMPILE,
153 InternalScopeManager.Mode.ELIMINATE,
154 select(CommonBuilds.PROJECT_PATH_TEST, CommonBuilds.BUILD_PATH_COMPILE),
155 Collections.singletonList(system),
156 nonTransitiveDependencyScopes));
157 result.add(internalScopeManager.createResolutionScope(
158 RS_TEST_RUNTIME,
159 InternalScopeManager.Mode.ELIMINATE,
160 select(CommonBuilds.PROJECT_PATH_TEST, CommonBuilds.BUILD_PATH_RUNTIME),
161 Collections.singletonList(system),
162 nonTransitiveDependencyScopes));
163 return result;
164 }
165
166
167
168 public static void main(String... args) {
169 ScopeManagerDump.dump(Maven3ScopeManagerConfiguration.INSTANCE);
170 }
171 }