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 org.eclipse.aether.RepositoryException;
22 import org.eclipse.aether.util.graph.transformer.ConflictResolver;
23 import org.eclipse.aether.util.graph.transformer.ConflictResolver.ScopeContext;
24 import org.eclipse.aether.util.graph.transformer.ConflictResolver.ScopeDeriver;
25
26
27
28
29
30
31 public final class MavenScopeDeriver extends ScopeDeriver {
32
33 public MavenScopeDeriver() {}
34
35 @Override
36 public void deriveScope(ScopeContext context) throws RepositoryException {
37 context.setDerivedScope(getDerivedScope(context.getParentScope(), context.getChildScope()));
38 }
39
40 private String getDerivedScope(String parentScope, String childScope) {
41 String derivedScope;
42
43 if (MavenDependencyScopes.SYSTEM.equals(childScope) || MavenDependencyScopes.TEST.equals(childScope)) {
44 derivedScope = childScope;
45 } else if (parentScope == null || parentScope.isEmpty() || MavenDependencyScopes.COMPILE.equals(parentScope)) {
46 derivedScope = childScope;
47 } else if (MavenDependencyScopes.TEST.equals(parentScope)
48 || MavenDependencyScopes.RUNTIME.equals(parentScope)) {
49 derivedScope = parentScope;
50 } else if (MavenDependencyScopes.SYSTEM.equals(parentScope)
51 || MavenDependencyScopes.PROVIDED.equals(parentScope)) {
52 derivedScope = MavenDependencyScopes.PROVIDED;
53 } else {
54 derivedScope = MavenDependencyScopes.RUNTIME;
55 }
56
57 return derivedScope;
58 }
59 }