1 package org.apache.maven.shared.dependency.graph.internal.maven30;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Arrays;
23 import java.util.Comparator;
24 import java.util.List;
25
26 import org.apache.maven.shared.dependency.graph.internal.maven30.ConflictResolver.ConflictContext;
27 import org.apache.maven.shared.dependency.graph.internal.maven30.ConflictResolver.ScopeSelector;
28 import org.sonatype.aether.RepositoryException;
29
30
31
32
33
34 public class VerboseJavaScopeSelector extends ScopeSelector
35 {
36 public static final String REDUCED_SCOPE = "REDUCED_SCOPE";
37
38 private final ScopeSelector scopeSelector = new JavaScopeSelector();
39
40 @Override
41 public void selectScope( ConflictContext context )
42 throws RepositoryException
43 {
44 scopeSelector.selectScope( context );
45
46 context.getItems().stream()
47 .flatMap( i -> i.getScopes().stream() )
48 .distinct()
49 .max( new ScopeComparator() )
50 .filter( s -> s != context.getScope() )
51 .ifPresent( s -> context.getWinner().getNode().setData( REDUCED_SCOPE, s ) );
52 }
53
54 static class ScopeComparator implements Comparator<String>
55 {
56 List<String> orderedScopes = Arrays.asList( "compile", "runtime", "provided", "test" );
57
58 @Override
59 public int compare( String lhs, String rhs )
60 {
61 return orderedScopes.indexOf( rhs ) - orderedScopes.indexOf( lhs );
62 }
63 }
64 }