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