1 package org.eclipse.aether.util.artifact;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.eclipse.aether.artifact.Artifact;
23
24
25
26
27 public final class ArtifactIdUtils
28 {
29
30 private static final char SEP = ':';
31
32 private ArtifactIdUtils()
33 {
34
35 }
36
37
38
39
40
41
42
43 public static String toId( Artifact artifact )
44 {
45 String id = null;
46 if ( artifact != null )
47 {
48 id =
49 toId( artifact.getGroupId(), artifact.getArtifactId(), artifact.getExtension(),
50 artifact.getClassifier(), artifact.getVersion() );
51 }
52 return id;
53 }
54
55
56
57
58
59
60
61
62
63
64
65 public static String toId( String groupId, String artifactId, String extension, String classifier, String version )
66 {
67 StringBuilder buffer = concat( groupId, artifactId, extension, classifier );
68 buffer.append( SEP );
69 if ( version != null )
70 {
71 buffer.append( version );
72 }
73 return buffer.toString();
74 }
75
76
77
78
79
80
81
82
83 public static String toBaseId( Artifact artifact )
84 {
85 String id = null;
86 if ( artifact != null )
87 {
88 id =
89 toId( artifact.getGroupId(), artifact.getArtifactId(), artifact.getExtension(),
90 artifact.getClassifier(), artifact.getBaseVersion() );
91 }
92 return id;
93 }
94
95
96
97
98
99
100
101 public static String toVersionlessId( Artifact artifact )
102 {
103 String id = null;
104 if ( artifact != null )
105 {
106 id =
107 toVersionlessId( artifact.getGroupId(), artifact.getArtifactId(), artifact.getExtension(),
108 artifact.getClassifier() );
109 }
110 return id;
111 }
112
113
114
115
116
117
118
119
120
121
122 public static String toVersionlessId( String groupId, String artifactId, String extension, String classifier )
123 {
124 return concat( groupId, artifactId, extension, classifier ).toString();
125 }
126
127 private static StringBuilder concat( String groupId, String artifactId, String extension, String classifier )
128 {
129 StringBuilder buffer = new StringBuilder( 128 );
130
131 if ( groupId != null )
132 {
133 buffer.append( groupId );
134 }
135 buffer.append( SEP );
136 if ( artifactId != null )
137 {
138 buffer.append( artifactId );
139 }
140 buffer.append( SEP );
141 if ( extension != null )
142 {
143 buffer.append( extension );
144 }
145 if ( classifier != null && classifier.length() > 0 )
146 {
147 buffer.append( SEP ).append( classifier );
148 }
149
150 return buffer;
151 }
152
153
154
155
156
157
158
159
160
161
162 public static boolean equalsId( Artifact artifact1, Artifact artifact2 )
163 {
164 if ( artifact1 == null || artifact2 == null )
165 {
166 return false;
167 }
168 if ( !eq( artifact1.getArtifactId(), artifact2.getArtifactId() ) )
169 {
170 return false;
171 }
172 if ( !eq( artifact1.getGroupId(), artifact2.getGroupId() ) )
173 {
174 return false;
175 }
176 if ( !eq( artifact1.getExtension(), artifact2.getExtension() ) )
177 {
178 return false;
179 }
180 if ( !eq( artifact1.getClassifier(), artifact2.getClassifier() ) )
181 {
182 return false;
183 }
184 if ( !eq( artifact1.getVersion(), artifact2.getVersion() ) )
185 {
186 return false;
187 }
188 return true;
189 }
190
191
192
193
194
195
196
197
198
199
200 public static boolean equalsBaseId( Artifact artifact1, Artifact artifact2 )
201 {
202 if ( artifact1 == null || artifact2 == null )
203 {
204 return false;
205 }
206 if ( !eq( artifact1.getArtifactId(), artifact2.getArtifactId() ) )
207 {
208 return false;
209 }
210 if ( !eq( artifact1.getGroupId(), artifact2.getGroupId() ) )
211 {
212 return false;
213 }
214 if ( !eq( artifact1.getExtension(), artifact2.getExtension() ) )
215 {
216 return false;
217 }
218 if ( !eq( artifact1.getClassifier(), artifact2.getClassifier() ) )
219 {
220 return false;
221 }
222 if ( !eq( artifact1.getBaseVersion(), artifact2.getBaseVersion() ) )
223 {
224 return false;
225 }
226 return true;
227 }
228
229
230
231
232
233
234
235
236
237
238
239 public static boolean equalsVersionlessId( Artifact artifact1, Artifact artifact2 )
240 {
241 if ( artifact1 == null || artifact2 == null )
242 {
243 return false;
244 }
245 if ( !eq( artifact1.getArtifactId(), artifact2.getArtifactId() ) )
246 {
247 return false;
248 }
249 if ( !eq( artifact1.getGroupId(), artifact2.getGroupId() ) )
250 {
251 return false;
252 }
253 if ( !eq( artifact1.getExtension(), artifact2.getExtension() ) )
254 {
255 return false;
256 }
257 if ( !eq( artifact1.getClassifier(), artifact2.getClassifier() ) )
258 {
259 return false;
260 }
261 return true;
262 }
263
264 private static <T> boolean eq( T s1, T s2 )
265 {
266 return s1 != null ? s1.equals( s2 ) : s2 == null;
267 }
268
269 }