1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.repository.metadata;
20
21 import javax.inject.Named;
22 import javax.inject.Singleton;
23
24 import org.apache.maven.artifact.versioning.ArtifactVersion;
25 import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
26 import org.codehaus.plexus.component.annotations.Configuration;
27
28
29
30
31 @Named
32 @Singleton
33 @Deprecated
34 public class DefaultGraphConflictResolutionPolicy implements GraphConflictResolutionPolicy {
35
36
37
38 @Configuration(name = "closer-first", value = "true")
39 private boolean closerFirst = true;
40
41
42
43
44 @Configuration(name = "newer-first", value = "true")
45 private boolean newerFirst = true;
46
47 public MetadataGraphEdge apply(MetadataGraphEdge e1, MetadataGraphEdge e2) {
48 int depth1 = e1.getDepth();
49 int depth2 = e2.getDepth();
50
51 if (depth1 == depth2) {
52 ArtifactVersion v1 = new DefaultArtifactVersion(e1.getVersion());
53 ArtifactVersion v2 = new DefaultArtifactVersion(e2.getVersion());
54
55 if (newerFirst) {
56 return v1.compareTo(v2) > 0 ? e1 : e2;
57 }
58
59 return v1.compareTo(v2) > 0 ? e2 : e1;
60 }
61
62 if (closerFirst) {
63 return depth1 < depth2 ? e1 : e2;
64 }
65
66 return depth1 < depth2 ? e2 : e1;
67 }
68 }