1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.basepom.mojo.dvc.version;
16
17 import static com.google.common.base.Preconditions.checkNotNull;
18
19 import org.basepom.mojo.dvc.QualifiedName;
20
21 import java.util.Objects;
22
23 import com.google.common.base.MoreObjects;
24 import org.apache.maven.artifact.versioning.ComparableVersion;
25
26 public final class VersionResolution {
27
28
29
30
31 private final VersionResolutionElement requestingDependency;
32
33
34
35
36 private final ComparableVersion expectedVersion;
37
38 public static VersionResolution forDirectDependency(final QualifiedName requestingDependency,
39 final ComparableVersion expectedVersion,
40 final boolean managedDependency) {
41 return new VersionResolution(requestingDependency, expectedVersion, managedDependency, true);
42 }
43
44 public static VersionResolution forTransitiveDependency(final QualifiedName requestingDependency,
45 final ComparableVersion expectedVersion,
46 final boolean managedDependency) {
47 return new VersionResolution(requestingDependency, expectedVersion, managedDependency, false);
48 }
49
50 private VersionResolution(
51 final QualifiedName requestingDependency,
52 final ComparableVersion expectedVersion,
53 final boolean manageDependency,
54 final boolean directDependency) {
55 checkNotNull(requestingDependency, "requestingDependencyName is null");
56 this.requestingDependency = new VersionResolutionElement(requestingDependency, manageDependency, directDependency);
57 this.expectedVersion = checkNotNull(expectedVersion, "expectedVersion is null");
58 }
59
60 public VersionResolutionElement getRequestingDependency() {
61 return requestingDependency;
62 }
63
64 public ComparableVersion getExpectedVersion() {
65 return expectedVersion;
66 }
67
68 public void conflict() {
69 requestingDependency.conflict();
70 }
71
72 @Override
73 public boolean equals(final Object o) {
74 if (this == o) {
75 return true;
76 }
77 if (o == null || getClass() != o.getClass()) {
78 return false;
79 }
80 final VersionResolution that = (VersionResolution) o;
81 return requestingDependency.equals(that.requestingDependency)
82 && expectedVersion.equals(that.expectedVersion);
83 }
84
85 @Override
86 public int hashCode() {
87 return Objects.hash(requestingDependency, expectedVersion);
88 }
89
90 @Override
91 public String toString() {
92 return MoreObjects.toStringHelper(this)
93 .add("requestingDependency", requestingDependency)
94 .add("expectedVersion", expectedVersion)
95 .toString();
96 }
97 }