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