1 package org.apache.maven.index.artifact;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 public class Gav
29 {
30
31
32
33 public enum HashType
34 {
35 sha1, md5
36 }
37
38
39
40
41 public enum SignatureType
42 {
43 gpg;
44
45 @Override
46 public String toString()
47 {
48 switch ( this )
49 {
50 case gpg:
51 {
52 return "asc";
53 }
54
55 default:
56 {
57 return "unknown-signature-type";
58 }
59 }
60 }
61 }
62
63 private final String groupId;
64
65 private final String artifactId;
66
67 private final String version;
68
69 private final String baseVersion;
70
71 private final String classifier;
72
73 private final String extension;
74
75 private final Integer snapshotBuildNumber;
76
77 private final Long snapshotTimeStamp;
78
79 private final String name;
80
81 private final boolean snapshot;
82
83 private final boolean hash;
84
85 private final HashType hashType;
86
87 private final boolean signature;
88
89 private final SignatureType signatureType;
90
91 public Gav( String groupId, String artifactId, String version )
92 {
93 this( groupId, artifactId, version, null, null, null, null, null, false, null, false, null );
94 }
95
96 public Gav( String groupId, String artifactId, String version, String classifier, String extension,
97 Integer snapshotBuildNumber, Long snapshotTimeStamp, String name, boolean hash, HashType hashType,
98 boolean signature, SignatureType signatureType )
99 {
100 this.groupId = groupId;
101 this.artifactId = artifactId;
102 this.version = version;
103 this.snapshot = VersionUtils.isSnapshot( version );
104
105 if ( !snapshot )
106 {
107 this.baseVersion = null;
108 }
109 else
110 {
111 if ( version.contains( "SNAPSHOT" ) )
112 {
113
114 this.baseVersion = null;
115 }
116 else
117 {
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132 String tempBaseVersion = version.substring( 0, version.lastIndexOf( '-' ) );
133 tempBaseVersion = tempBaseVersion.substring( 0, tempBaseVersion.length() - 15 );
134
135 if ( tempBaseVersion.length() > 0 )
136 {
137 this.baseVersion = tempBaseVersion + "SNAPSHOT";
138 }
139 else
140 {
141 this.baseVersion = "SNAPSHOT";
142 }
143
144 }
145 }
146
147 this.classifier = classifier;
148 this.extension = extension;
149 this.snapshotBuildNumber = snapshotBuildNumber;
150 this.snapshotTimeStamp = snapshotTimeStamp;
151 this.name = name;
152 this.hash = hash;
153 this.hashType = hashType;
154 this.signature = signature;
155 this.signatureType = signatureType;
156 }
157
158 public String getGroupId()
159 {
160 return groupId;
161 }
162
163 public String getArtifactId()
164 {
165 return artifactId;
166 }
167
168 public String getVersion()
169 {
170 return version;
171 }
172
173 public String getBaseVersion()
174 {
175 if ( baseVersion == null )
176 {
177 return getVersion();
178 }
179 else
180 {
181 return baseVersion;
182 }
183 }
184
185 public String getClassifier()
186 {
187 return classifier;
188 }
189
190 public String getExtension()
191 {
192 return extension;
193 }
194
195 public String getName()
196 {
197 return name;
198 }
199
200 public boolean isSnapshot()
201 {
202 return snapshot;
203 }
204
205 public Integer getSnapshotBuildNumber()
206 {
207 return snapshotBuildNumber;
208 }
209
210 public Long getSnapshotTimeStamp()
211 {
212 return snapshotTimeStamp;
213 }
214
215 public boolean isHash()
216 {
217 return hash;
218 }
219
220 public HashType getHashType()
221 {
222 return hashType;
223 }
224
225 public boolean isSignature()
226 {
227 return signature;
228 }
229
230 public SignatureType getSignatureType()
231 {
232 return signatureType;
233 }
234
235 @Override
236 public int hashCode()
237 {
238 int result = 1;
239 result = 31 * result + ( groupId == null ? 0 : groupId.hashCode() );
240 result = 31 * result + ( artifactId == null ? 0 : artifactId.hashCode() );
241 result = 31 * result + ( version == null ? 0 : version.hashCode() );
242 result = 31 * result + ( baseVersion == null ? 0 : baseVersion.hashCode() );
243 result = 31 * result + ( classifier == null ? 0 : classifier.hashCode() );
244 result = 31 * result + ( extension == null ? 0 : extension.hashCode() );
245 result = 31 * result + ( name == null ? 0 : name.hashCode() );
246 result = 31 * result + ( snapshot ? 1231 : 1237 );
247 result = 31 * result + ( snapshotBuildNumber == null ? 0 : snapshotBuildNumber.hashCode() );
248 result = 31 * result + ( snapshotTimeStamp == null ? 0 : snapshotTimeStamp.hashCode() );
249 result = 31 * result + ( hash ? 1231 : 1237 );
250 result = 31 * result + ( hashType == null ? 0 : hashType.hashCode() );
251 result = 31 * result + ( signature ? 1231 : 1237 );
252 result = 31 * result + ( signatureType == null ? 0 : signatureType.hashCode() );
253 return result;
254 }
255
256 @Override
257 public boolean equals( Object obj )
258 {
259 if ( this == obj )
260 {
261 return true;
262 }
263 if ( obj == null )
264 {
265 return false;
266 }
267 if ( getClass() != obj.getClass() )
268 {
269 return false;
270 }
271
272 Gav other = (Gav) obj;
273
274 if ( groupId == null )
275 {
276 if ( other.groupId != null )
277 {
278 return false;
279 }
280 }
281 else if ( !groupId.equals( other.groupId ) )
282 {
283 return false;
284 }
285
286 if ( artifactId == null )
287 {
288 if ( other.artifactId != null )
289 {
290 return false;
291 }
292 }
293 else if ( !artifactId.equals( other.artifactId ) )
294 {
295 return false;
296 }
297
298 if ( version == null )
299 {
300 if ( other.version != null )
301 {
302 return false;
303 }
304 }
305 else if ( !version.equals( other.version ) )
306 {
307 return false;
308 }
309
310 if ( baseVersion == null )
311 {
312 if ( other.baseVersion != null )
313 {
314 return false;
315 }
316 }
317 else if ( !baseVersion.equals( other.baseVersion ) )
318 {
319 return false;
320 }
321
322 if ( classifier == null )
323 {
324 if ( other.classifier != null )
325 {
326 return false;
327 }
328 }
329 else if ( !classifier.equals( other.classifier ) )
330 {
331 return false;
332 }
333
334 if ( extension == null )
335 {
336 if ( other.extension != null )
337 {
338 return false;
339 }
340 }
341 else if ( !extension.equals( other.extension ) )
342 {
343 return false;
344 }
345
346 if ( name == null )
347 {
348 if ( other.name != null )
349 {
350 return false;
351 }
352 }
353 else if ( !name.equals( other.name ) )
354 {
355 return false;
356 }
357
358 if ( snapshot != other.snapshot )
359 {
360 return false;
361 }
362
363 if ( snapshotBuildNumber == null )
364 {
365 if ( other.snapshotBuildNumber != null )
366 {
367 return false;
368 }
369 }
370 else if ( !snapshotBuildNumber.equals( other.snapshotBuildNumber ) )
371 {
372 return false;
373 }
374
375 if ( snapshotTimeStamp == null )
376 {
377 if ( other.snapshotTimeStamp != null )
378 {
379 return false;
380 }
381 }
382 else if ( !snapshotTimeStamp.equals( other.snapshotTimeStamp ) )
383 {
384 return false;
385 }
386
387 if ( hash != other.hash )
388 {
389 return false;
390 }
391
392 if ( hashType == null )
393 {
394 if ( other.hashType != null )
395 {
396 return false;
397 }
398 }
399 else if ( !hashType.equals( other.hashType ) )
400 {
401 return false;
402 }
403
404 if ( signature != other.signature )
405 {
406 return false;
407 }
408
409 if ( signatureType == null )
410 {
411 if ( other.signatureType != null )
412 {
413 return false;
414 }
415 }
416 else if ( !signatureType.equals( other.signatureType ) )
417 {
418 return false;
419 }
420
421 return true;
422 }
423 }