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