1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.war.stub;
20
21 import java.util.Objects;
22
23 import org.apache.maven.artifact.Artifact;
24 import org.apache.maven.artifact.handler.ArtifactHandler;
25 import org.apache.maven.artifact.handler.DefaultArtifactHandler;
26 import org.apache.maven.artifact.versioning.VersionRange;
27 import org.apache.maven.plugin.testing.stubs.ArtifactStub;
28
29 public abstract class AbstractArtifactStub extends ArtifactStub {
30 protected String basedir;
31
32 public AbstractArtifactStub(String basedir) {
33 this.basedir = basedir;
34 }
35
36 public String getVersion() {
37 return "0.0-Test";
38 }
39
40 @Override
41 public String getBaseVersion() {
42 return getVersion();
43 }
44
45 public String getScope() {
46 return Artifact.SCOPE_RUNTIME;
47 }
48
49 public VersionRange getVersionRange() {
50 return VersionRange.createFromVersion(getVersion());
51 }
52
53 public boolean isOptional() {
54 return false;
55 }
56
57 public ArtifactHandler getArtifactHandler() {
58 return new DefaultArtifactHandler(getType());
59 }
60
61
62
63
64 public int compareTo(Artifact a) {
65
66 int result;
67 if (a.getGroupId() != null) {
68 result = getGroupId().compareTo(a.getGroupId());
69 } else {
70 result = (getGroupId() == null ? 0 : -1);
71 }
72
73
74 if (result == 0) {
75 result = getArtifactId().compareTo(a.getArtifactId());
76 if (result == 0) {
77 result = getType().compareTo(a.getType());
78 if (result == 0) {
79 if (getClassifier() == null) {
80 if (a.getClassifier() != null) {
81 result = 1;
82 }
83 } else {
84 if (a.getClassifier() != null) {
85 result = getClassifier().compareTo(a.getClassifier());
86 } else {
87 result = -1;
88 }
89 }
90 if (result == 0) {
91
92 result = getVersion().compareTo(a.getVersion());
93 }
94 }
95 }
96 }
97 return result;
98 }
99
100
101
102
103 public boolean equals(Object o) {
104 if (o == this) {
105 return true;
106 }
107
108 if (!(o instanceof Artifact)) {
109 return false;
110 }
111
112 Artifact a = (Artifact) o;
113
114
115 if (a.getGroupId() == null ? (getGroupId() != null) : a.getGroupId().equals(getGroupId())) {
116 return false;
117 } else if (!a.getArtifactId().equals(getArtifactId())) {
118 return false;
119 } else if (!a.getVersion().equals(getVersion())) {
120 return false;
121 } else if (!a.getType().equals(getType())) {
122 return false;
123 } else if (a.getClassifier() == null
124 ? getClassifier() != null
125 : !a.getClassifier().equals(getClassifier())) {
126 return false;
127 }
128
129
130
131 return true;
132 }
133
134 @Override
135 public int hashCode() {
136 return Objects.hashCode(basedir);
137 }
138 }