1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.util.artifact;
20
21 import java.util.Objects;
22
23 import org.eclipse.aether.artifact.Artifact;
24
25
26
27
28 public final class ArtifactIdUtils {
29
30 private static final char SEP = ':';
31
32 private ArtifactIdUtils() {
33
34 }
35
36
37
38
39
40
41
42 public static String toId(Artifact artifact) {
43 String id = null;
44 if (artifact != null) {
45 id = toId(
46 artifact.getGroupId(),
47 artifact.getArtifactId(),
48 artifact.getExtension(),
49 artifact.getClassifier(),
50 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 StringBuilder buffer = concat(groupId, artifactId, extension, classifier);
67 buffer.append(SEP);
68 if (version != null) {
69 buffer.append(version);
70 }
71 return buffer.toString();
72 }
73
74
75
76
77
78
79
80
81 public static String toBaseId(Artifact artifact) {
82 String id = null;
83 if (artifact != null) {
84 id = toId(
85 artifact.getGroupId(),
86 artifact.getArtifactId(),
87 artifact.getExtension(),
88 artifact.getClassifier(),
89 artifact.getBaseVersion());
90 }
91 return id;
92 }
93
94
95
96
97
98
99
100 public static String toVersionlessId(Artifact artifact) {
101 String id = null;
102 if (artifact != null) {
103 id = toVersionlessId(
104 artifact.getGroupId(), artifact.getArtifactId(), artifact.getExtension(), artifact.getClassifier());
105 }
106 return id;
107 }
108
109
110
111
112
113
114
115
116
117
118 public static String toVersionlessId(String groupId, String artifactId, String extension, String classifier) {
119 return concat(groupId, artifactId, extension, classifier).toString();
120 }
121
122 private static StringBuilder concat(String groupId, String artifactId, String extension, String classifier) {
123 StringBuilder buffer = new StringBuilder(128);
124
125 if (groupId != null) {
126 buffer.append(groupId);
127 }
128 buffer.append(SEP);
129 if (artifactId != null) {
130 buffer.append(artifactId);
131 }
132 buffer.append(SEP);
133 if (extension != null) {
134 buffer.append(extension);
135 }
136 if (classifier != null && classifier.length() > 0) {
137 buffer.append(SEP).append(classifier);
138 }
139
140 return buffer;
141 }
142
143
144
145
146
147
148
149
150
151
152 public static boolean equalsId(Artifact artifact1, Artifact artifact2) {
153 if (artifact1 == null || artifact2 == null) {
154 return false;
155 }
156 if (!Objects.equals(artifact1.getArtifactId(), artifact2.getArtifactId())) {
157 return false;
158 }
159 if (!Objects.equals(artifact1.getGroupId(), artifact2.getGroupId())) {
160 return false;
161 }
162 if (!Objects.equals(artifact1.getExtension(), artifact2.getExtension())) {
163 return false;
164 }
165 if (!Objects.equals(artifact1.getClassifier(), artifact2.getClassifier())) {
166 return false;
167 }
168 return Objects.equals(artifact1.getVersion(), artifact2.getVersion());
169 }
170
171
172
173
174
175
176
177
178
179
180 public static boolean equalsBaseId(Artifact artifact1, Artifact artifact2) {
181 if (artifact1 == null || artifact2 == null) {
182 return false;
183 }
184 if (!Objects.equals(artifact1.getArtifactId(), artifact2.getArtifactId())) {
185 return false;
186 }
187 if (!Objects.equals(artifact1.getGroupId(), artifact2.getGroupId())) {
188 return false;
189 }
190 if (!Objects.equals(artifact1.getExtension(), artifact2.getExtension())) {
191 return false;
192 }
193 if (!Objects.equals(artifact1.getClassifier(), artifact2.getClassifier())) {
194 return false;
195 }
196 return Objects.equals(artifact1.getBaseVersion(), artifact2.getBaseVersion());
197 }
198
199
200
201
202
203
204
205
206
207
208
209 public static boolean equalsVersionlessId(Artifact artifact1, Artifact artifact2) {
210 if (artifact1 == null || artifact2 == null) {
211 return false;
212 }
213 if (!Objects.equals(artifact1.getArtifactId(), artifact2.getArtifactId())) {
214 return false;
215 }
216 if (!Objects.equals(artifact1.getGroupId(), artifact2.getGroupId())) {
217 return false;
218 }
219 if (!Objects.equals(artifact1.getExtension(), artifact2.getExtension())) {
220 return false;
221 }
222 return Objects.equals(artifact1.getClassifier(), artifact2.getClassifier());
223 }
224 }