1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.repository.metadata;
20
21 import java.util.Collection;
22 import org.apache.maven.artifact.Artifact;
23 import org.apache.maven.artifact.ArtifactScopeEnum;
24
25
26
27
28
29
30 public class ArtifactMetadata {
31
32
33
34 protected String groupId;
35
36 protected String artifactId;
37 protected String version;
38 protected String type;
39 protected ArtifactScopeEnum artifactScope;
40 protected String classifier;
41
42
43
44
45
46 protected String why;
47
48
49 protected Collection<ArtifactMetadata> dependencies;
50
51
52 protected String uri;
53
54
55 protected boolean resolved = false;
56
57
58 protected boolean artifactExists = false;
59
60 protected String artifactUri;
61
62
63 private String error;
64
65
66
67
68
69 public ArtifactMetadata(String name) {
70 if (name == null) {
71 return;
72 }
73 int ind1 = name.indexOf(':');
74 int ind2 = name.lastIndexOf(':');
75
76 if (ind1 == -1 || ind2 == -1) {
77 return;
78 }
79
80 this.groupId = name.substring(0, ind1);
81 if (ind1 == ind2) {
82 this.artifactId = name.substring(ind1 + 1);
83 } else {
84 this.artifactId = name.substring(ind1 + 1, ind2);
85 this.version = name.substring(ind2 + 1);
86 }
87 }
88
89 public ArtifactMetadata(String groupId, String name, String version) {
90 this(groupId, name, version, null);
91 }
92
93 public ArtifactMetadata(String groupId, String name, String version, String type) {
94 this(groupId, name, version, type, null);
95 }
96
97 public ArtifactMetadata(String groupId, String name, String version, String type, ArtifactScopeEnum artifactScope) {
98 this(groupId, name, version, type, artifactScope, null);
99 }
100
101 public ArtifactMetadata(
102 String groupId,
103 String name,
104 String version,
105 String type,
106 ArtifactScopeEnum artifactScope,
107 String classifier) {
108 this(groupId, name, version, type, artifactScope, classifier, null);
109 }
110
111 public ArtifactMetadata(
112 String groupId,
113 String name,
114 String version,
115 String type,
116 ArtifactScopeEnum artifactScope,
117 String classifier,
118 String artifactUri) {
119 this(groupId, name, version, type, artifactScope, classifier, artifactUri, null, true, null);
120 }
121
122 @SuppressWarnings("checkstyle:parameternumber")
123 public ArtifactMetadata(
124 String groupId,
125 String name,
126 String version,
127 String type,
128 ArtifactScopeEnum artifactScope,
129 String classifier,
130 String artifactUri,
131 String why,
132 boolean resolved,
133 String error) {
134 this.groupId = groupId;
135 this.artifactId = name;
136 this.version = version;
137 this.type = type;
138 this.artifactScope = artifactScope;
139 this.classifier = classifier;
140 this.artifactUri = artifactUri;
141 this.why = why;
142 this.resolved = resolved;
143 this.error = error;
144 }
145
146 @SuppressWarnings("checkstyle:parameternumber")
147 public ArtifactMetadata(
148 String groupId,
149 String name,
150 String version,
151 String type,
152 String scopeString,
153 String classifier,
154 String artifactUri,
155 String why,
156 boolean resolved,
157 String error) {
158 this(
159 groupId,
160 name,
161 version,
162 type,
163 scopeString == null ? ArtifactScopeEnum.DEFAULT_SCOPE : ArtifactScopeEnum.valueOf(scopeString),
164 classifier,
165 artifactUri,
166 why,
167 resolved,
168 error);
169 }
170
171 public ArtifactMetadata(Artifact af) {
172
173
174
175
176
177
178 }
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193 @Override
194 public String toString() {
195 return groupId + ":" + artifactId + ":" + version;
196 }
197
198 public String toDomainString() {
199 return groupId + ":" + artifactId;
200 }
201
202 public String getGroupId() {
203 return groupId;
204 }
205
206 public void setGroupId(String groupId) {
207 this.groupId = groupId;
208 }
209
210 public String getArtifactId() {
211 return artifactId;
212 }
213
214 public void setArtifactId(String name) {
215 this.artifactId = name;
216 }
217
218 public String getVersion() {
219 return version;
220 }
221
222 public void setVersion(String version) {
223 this.version = version;
224 }
225
226 public String getType() {
227 return type;
228 }
229
230 public String getCheckedType() {
231 return type == null ? "jar" : type;
232 }
233
234 public void setType(String type) {
235 this.type = type;
236 }
237
238 public ArtifactScopeEnum getArtifactScope() {
239 return artifactScope == null ? ArtifactScopeEnum.DEFAULT_SCOPE : artifactScope;
240 }
241
242 public void setArtifactScope(ArtifactScopeEnum artifactScope) {
243 this.artifactScope = artifactScope;
244 }
245
246 public void setScope(String scope) {
247 this.artifactScope = scope == null ? ArtifactScopeEnum.DEFAULT_SCOPE : ArtifactScopeEnum.valueOf(scope);
248 }
249
250 public String getClassifier() {
251 return classifier;
252 }
253
254 public void setClassifier(String classifier) {
255 this.classifier = classifier;
256 }
257
258 public boolean isResolved() {
259 return resolved;
260 }
261
262 public void setResolved(boolean resolved) {
263 this.resolved = resolved;
264 }
265
266 public String getUri() {
267 return uri;
268 }
269
270 public void setUri(String uri) {
271 this.uri = uri;
272 }
273
274 public String getScope() {
275 return getArtifactScope().getScope();
276 }
277
278 public ArtifactScopeEnum getScopeAsEnum() {
279 return artifactScope == null ? ArtifactScopeEnum.DEFAULT_SCOPE : artifactScope;
280 }
281
282 public boolean isArtifactExists() {
283 return artifactExists;
284 }
285
286 public void setArtifactExists(boolean artifactExists) {
287 this.artifactExists = artifactExists;
288 }
289
290 public Collection<ArtifactMetadata> getDependencies() {
291 return dependencies;
292 }
293
294 public void setDependencies(Collection<ArtifactMetadata> dependencies) {
295 this.dependencies = dependencies;
296 }
297
298 public String getArtifactUri() {
299 return artifactUri;
300 }
301
302 public void setArtifactUri(String artifactUri) {
303 this.artifactUri = artifactUri;
304 }
305
306 public String getWhy() {
307 return why;
308 }
309
310 public void setWhy(String why) {
311 this.why = why;
312 }
313
314 public String getError() {
315 return error;
316 }
317
318 public void setError(String error) {
319 this.error = error;
320 }
321
322 public boolean isError() {
323 return error == null;
324 }
325
326 public String getDependencyConflictId() {
327 return groupId + ":" + artifactId;
328 }
329 }