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