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