1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.api.plugin.testing.stubs;
20
21 import java.util.Objects;
22
23 import org.apache.maven.api.Artifact;
24 import org.apache.maven.api.ArtifactCoordinate;
25 import org.apache.maven.api.Version;
26 import org.apache.maven.api.VersionRange;
27 import org.apache.maven.api.annotations.Nonnull;
28 import org.apache.maven.internal.impl.DefaultVersionParser;
29
30
31
32
33 public class ArtifactStub implements Artifact {
34 private String groupId;
35 private String artifactId;
36 private String classifier;
37 private String version;
38 private String extension;
39
40 public ArtifactStub() {
41 groupId = "";
42 artifactId = "";
43 version = "";
44 classifier = "";
45 extension = "";
46 }
47
48 public ArtifactStub(String groupId, String artifactId, String classifier, String version, String extension) {
49 this.groupId = groupId;
50 this.artifactId = artifactId;
51 this.classifier = classifier;
52 this.version = version;
53 this.extension = extension;
54 }
55
56 @Nonnull
57 @Override
58 public String getGroupId() {
59 return groupId;
60 }
61
62 public void setGroupId(String groupId) {
63 this.groupId = groupId;
64 }
65
66 @Nonnull
67 @Override
68 public String getArtifactId() {
69 return artifactId;
70 }
71
72 public void setArtifactId(String artifactId) {
73 this.artifactId = artifactId;
74 }
75
76 @Nonnull
77 @Override
78 public String getClassifier() {
79 return classifier;
80 }
81
82 public void setClassifier(String classifier) {
83 this.classifier = classifier;
84 }
85
86 @Nonnull
87 @Override
88 public Version getVersion() {
89 return new DefaultVersionParser().parseVersion(version);
90 }
91
92 public void setVersion(String version) {
93 this.version = version;
94 }
95
96 @Nonnull
97 @Override
98 public String getExtension() {
99 return extension;
100 }
101
102 public void setExtension(String extension) {
103 this.extension = extension;
104 }
105
106 @Override
107 public boolean isSnapshot() {
108 return false;
109 }
110
111 @Override
112 public ArtifactCoordinate toCoordinate() {
113 return new ArtifactCoordinate() {
114 @Override
115 public String getGroupId() {
116 return groupId;
117 }
118
119 @Override
120 public String getArtifactId() {
121 return artifactId;
122 }
123
124 @Override
125 public String getClassifier() {
126 return classifier;
127 }
128
129 @Override
130 public VersionRange getVersion() {
131 return new DefaultVersionParser().parseVersionRange(version);
132 }
133
134 @Override
135 public String getExtension() {
136 return extension;
137 }
138 };
139 }
140
141 @Override
142 public String toString() {
143 return "ArtifactStub["
144 + "groupId='" + groupId + '\''
145 + ", artifactId='" + artifactId + '\''
146 + ", classifier='" + classifier + '\''
147 + ", version='" + version + '\''
148 + ", extension='" + extension + '\''
149 + ']';
150 }
151
152 @Override
153 public boolean equals(Object o) {
154 if (this == o) {
155 return true;
156 }
157 if (!(o instanceof ArtifactStub)) {
158 return false;
159 }
160 ArtifactStub that = (ArtifactStub) o;
161 return Objects.equals(groupId, that.groupId)
162 && Objects.equals(artifactId, that.artifactId)
163 && Objects.equals(classifier, that.classifier)
164 && Objects.equals(version, that.version)
165 && Objects.equals(extension, that.extension);
166 }
167
168 @Override
169 public int hashCode() {
170 return Objects.hash(groupId, artifactId, classifier, version, extension);
171 }
172 }