29
29
import java .util .Optional ;
30
30
import java .util .stream .Collectors ;
31
31
32
+ import org .apache .maven .api .annotations .Nonnull ;
33
+ import org .apache .maven .api .annotations .Nullable ;
32
34
import org .apache .maven .artifact .handler .ArtifactHandler ;
33
35
import org .apache .maven .artifact .handler .DefaultArtifactHandler ;
34
36
import org .apache .maven .artifact .handler .manager .ArtifactHandlerManager ;
65
67
*/
66
68
public class RepositoryUtils {
67
69
68
- private static String nullify (String string ) {
70
+ @ Nullable
71
+ private static String nullify (@ Nullable String string ) {
69
72
return (string == null || string .isEmpty ()) ? null : string ;
70
73
}
71
74
72
- public static org .apache .maven .artifact .Artifact toArtifact (Dependency dependency ) {
75
+ @ Nullable
76
+ public static org .apache .maven .artifact .Artifact toArtifact (@ Nullable Dependency dependency ) {
73
77
if (dependency == null ) {
74
78
return null ;
75
79
}
@@ -81,7 +85,8 @@ public static org.apache.maven.artifact.Artifact toArtifact(Dependency dependenc
81
85
return result ;
82
86
}
83
87
84
- public static org .apache .maven .artifact .Artifact toArtifact (Artifact artifact ) {
88
+ @ Nullable
89
+ public static org .apache .maven .artifact .Artifact toArtifact (@ Nullable Artifact artifact ) {
85
90
if (artifact == null ) {
86
91
return null ;
87
92
}
@@ -112,10 +117,10 @@ public static org.apache.maven.artifact.Artifact toArtifact(Artifact artifact) {
112
117
}
113
118
114
119
public static void toArtifacts (
115
- Collection <org .apache .maven .artifact .Artifact > artifacts ,
116
- Collection <? extends DependencyNode > nodes ,
117
- List <String > trail ,
118
- DependencyFilter filter ) {
120
+ @ Nonnull Collection <org .apache .maven .artifact .Artifact > artifacts ,
121
+ @ Nonnull Collection <? extends DependencyNode > nodes ,
122
+ @ Nonnull List <String > trail ,
123
+ @ Nullable DependencyFilter filter ) {
119
124
for (DependencyNode node : nodes ) {
120
125
org .apache .maven .artifact .Artifact artifact = toArtifact (node .getDependency ());
121
126
@@ -132,7 +137,8 @@ public static void toArtifacts(
132
137
}
133
138
}
134
139
135
- public static Artifact toArtifact (org .apache .maven .artifact .Artifact artifact ) {
140
+ @ Nullable
141
+ public static Artifact toArtifact (@ Nullable org .apache .maven .artifact .Artifact artifact ) {
136
142
if (artifact == null ) {
137
143
return null ;
138
144
}
@@ -162,7 +168,8 @@ public static Artifact toArtifact(org.apache.maven.artifact.Artifact artifact) {
162
168
}
163
169
164
170
public static Dependency toDependency (
165
- org .apache .maven .artifact .Artifact artifact , Collection <org .apache .maven .model .Exclusion > exclusions ) {
171
+ @ Nullable org .apache .maven .artifact .Artifact artifact ,
172
+ @ Nullable Collection <org .apache .maven .model .Exclusion > exclusions ) {
166
173
if (artifact == null ) {
167
174
return null ;
168
175
}
@@ -175,13 +182,15 @@ public static Dependency toDependency(
175
182
return new Dependency (result , artifact .getScope (), artifact .isOptional (), excl );
176
183
}
177
184
178
- public static List <RemoteRepository > toRepos (List <ArtifactRepository > repos ) {
185
+ @ Nonnull
186
+ public static List <RemoteRepository > toRepos (@ Nullable List <ArtifactRepository > repos ) {
179
187
return Optional .ofNullable (repos ).orElse (Collections .emptyList ()).stream ()
180
188
.map (RepositoryUtils ::toRepo )
181
189
.collect (Collectors .toList ());
182
190
}
183
191
184
- public static RemoteRepository toRepo (ArtifactRepository repo ) {
192
+ @ Nullable
193
+ public static RemoteRepository toRepo (@ Nullable ArtifactRepository repo ) {
185
194
RemoteRepository result = null ;
186
195
if (repo != null ) {
187
196
RemoteRepository .Builder builder =
@@ -197,7 +206,8 @@ public static RemoteRepository toRepo(ArtifactRepository repo) {
197
206
return result ;
198
207
}
199
208
200
- public static String getLayout (ArtifactRepository repo ) {
209
+ @ Nonnull
210
+ public static String getLayout (@ Nonnull ArtifactRepository repo ) {
201
211
try {
202
212
return repo .getLayout ().getId ();
203
213
} catch (LinkageError e ) {
@@ -216,15 +226,17 @@ public static String getLayout(ArtifactRepository repo) {
216
226
}
217
227
}
218
228
219
- private static RepositoryPolicy toPolicy (ArtifactRepositoryPolicy policy ) {
229
+ @ Nullable
230
+ private static RepositoryPolicy toPolicy (@ Nullable ArtifactRepositoryPolicy policy ) {
220
231
RepositoryPolicy result = null ;
221
232
if (policy != null ) {
222
233
result = new RepositoryPolicy (policy .isEnabled (), policy .getUpdatePolicy (), policy .getChecksumPolicy ());
223
234
}
224
235
return result ;
225
236
}
226
237
227
- private static Authentication toAuthentication (org .apache .maven .artifact .repository .Authentication auth ) {
238
+ @ Nullable
239
+ private static Authentication toAuthentication (@ Nullable org .apache .maven .artifact .repository .Authentication auth ) {
228
240
Authentication result = null ;
229
241
if (auth != null ) {
230
242
AuthenticationBuilder authBuilder = new AuthenticationBuilder ();
@@ -235,7 +247,8 @@ private static Authentication toAuthentication(org.apache.maven.artifact.reposit
235
247
return result ;
236
248
}
237
249
238
- private static Proxy toProxy (org .apache .maven .repository .Proxy proxy ) {
250
+ @ Nullable
251
+ private static Proxy toProxy (@ Nullable org .apache .maven .repository .Proxy proxy ) {
239
252
Proxy result = null ;
240
253
if (proxy != null ) {
241
254
AuthenticationBuilder authBuilder = new AuthenticationBuilder ();
@@ -245,7 +258,8 @@ private static Proxy toProxy(org.apache.maven.repository.Proxy proxy) {
245
258
return result ;
246
259
}
247
260
248
- public static ArtifactHandler newHandler (Artifact artifact ) {
261
+ @ Nonnull
262
+ public static ArtifactHandler newHandler (@ Nonnull Artifact artifact ) {
249
263
String type = artifact .getProperty (ArtifactProperties .TYPE , artifact .getExtension ());
250
264
return new DefaultArtifactHandler (
251
265
type ,
@@ -258,7 +272,8 @@ public static ArtifactHandler newHandler(Artifact artifact) {
258
272
Boolean .parseBoolean (artifact .getProperty (MavenArtifactProperties .CONSTITUTES_BUILD_PATH , "" )));
259
273
}
260
274
261
- public static ArtifactType newArtifactType (String id , ArtifactHandler handler ) {
275
+ @ Nonnull
276
+ public static ArtifactType newArtifactType (@ Nonnull String id , @ Nonnull ArtifactHandler handler ) {
262
277
return new DefaultArtifactType (
263
278
id ,
264
279
handler .getExtension (),
@@ -268,8 +283,9 @@ public static ArtifactType newArtifactType(String id, ArtifactHandler handler) {
268
283
handler .isIncludesDependencies ());
269
284
}
270
285
286
+ @ Nonnull
271
287
public static Dependency toDependency (
272
- org .apache .maven .model .Dependency dependency , ArtifactTypeRegistry stereotypes ) {
288
+ @ Nonnull org .apache .maven .model .Dependency dependency , @ Nonnull ArtifactTypeRegistry stereotypes ) {
273
289
ArtifactType stereotype = stereotypes .get (dependency .getType ());
274
290
if (stereotype == null ) {
275
291
stereotype = new DefaultArtifactType (dependency .getType ());
@@ -303,38 +319,46 @@ public static Dependency toDependency(
303
319
exclusions );
304
320
}
305
321
306
- private static Exclusion toExclusion (org .apache .maven .model .Exclusion exclusion ) {
322
+ @ Nonnull
323
+ public static Exclusion toExclusion (@ Nonnull org .apache .maven .model .Exclusion exclusion ) {
307
324
return new Exclusion (exclusion .getGroupId (), exclusion .getArtifactId (), "*" , "*" );
308
325
}
309
326
310
- public static ArtifactTypeRegistry newArtifactTypeRegistry (ArtifactHandlerManager handlerManager ) {
327
+ @ Nonnull
328
+ public static ArtifactTypeRegistry newArtifactTypeRegistry (@ Nonnull ArtifactHandlerManager handlerManager ) {
311
329
return new MavenArtifactTypeRegistry (handlerManager );
312
330
}
313
331
314
332
static class MavenArtifactTypeRegistry implements ArtifactTypeRegistry {
315
333
334
+ @ Nonnull
316
335
private final ArtifactHandlerManager handlerManager ;
317
336
318
- MavenArtifactTypeRegistry (ArtifactHandlerManager handlerManager ) {
337
+ MavenArtifactTypeRegistry (@ Nonnull ArtifactHandlerManager handlerManager ) {
319
338
this .handlerManager = handlerManager ;
320
339
}
321
340
322
- public ArtifactType get (String stereotypeId ) {
341
+ @ Nullable
342
+ @ Override
343
+ public ArtifactType get (@ Nonnull String stereotypeId ) {
323
344
ArtifactHandler handler = handlerManager .getArtifactHandler (stereotypeId );
324
345
return newArtifactType (stereotypeId , handler );
325
346
}
326
347
}
327
348
328
- public static Collection <Artifact > toArtifacts (Collection <org .apache .maven .artifact .Artifact > artifactsToConvert ) {
349
+ @ Nonnull
350
+ public static Collection <Artifact > toArtifacts (
351
+ @ Nonnull Collection <org .apache .maven .artifact .Artifact > artifactsToConvert ) {
329
352
return artifactsToConvert .stream ().map (RepositoryUtils ::toArtifact ).collect (Collectors .toList ());
330
353
}
331
354
332
- public static WorkspaceRepository getWorkspace (RepositorySystemSession session ) {
355
+ @ Nullable
356
+ public static WorkspaceRepository getWorkspace (@ Nonnull RepositorySystemSession session ) {
333
357
WorkspaceReader reader = session .getWorkspaceReader ();
334
358
return (reader != null ) ? reader .getRepository () : null ;
335
359
}
336
360
337
- public static boolean repositoriesEquals (List <RemoteRepository > r1 , List <RemoteRepository > r2 ) {
361
+ public static boolean repositoriesEquals (@ Nonnull List <RemoteRepository > r1 , @ Nonnull List <RemoteRepository > r2 ) {
338
362
if (r1 .size () != r2 .size ()) {
339
363
return false ;
340
364
}
@@ -348,16 +372,19 @@ public static boolean repositoriesEquals(List<RemoteRepository> r1, List<RemoteR
348
372
return true ;
349
373
}
350
374
351
- public static int repositoriesHashCode (List <RemoteRepository > repositories ) {
375
+ public static int repositoriesHashCode (@ Nonnull List <RemoteRepository > repositories ) {
352
376
int result = 17 ;
353
377
for (RemoteRepository repository : repositories ) {
354
378
result = 31 * result + repositoryHashCode (repository );
355
379
}
356
380
return result ;
357
381
}
358
382
383
+ @ Nullable
359
384
public static RepositorySystemSession overlay (
360
- ArtifactRepository repository , RepositorySystemSession session , RepositorySystem system ) {
385
+ @ Nullable ArtifactRepository repository ,
386
+ @ Nullable RepositorySystemSession session ,
387
+ @ Nonnull RepositorySystem system ) {
361
388
if (repository == null || repository .getBasedir () == null ) {
362
389
return session ;
363
390
}
@@ -379,22 +406,22 @@ public static RepositorySystemSession overlay(
379
406
return newSession ;
380
407
}
381
408
382
- private static int repositoryHashCode (RemoteRepository repository ) {
409
+ private static int repositoryHashCode (@ Nonnull RemoteRepository repository ) {
383
410
int result = 17 ;
384
411
Object obj = repository .getUrl ();
385
412
result = 31 * result + (obj != null ? obj .hashCode () : 0 );
386
413
return result ;
387
414
}
388
415
389
- private static boolean policyEquals (RepositoryPolicy p1 , RepositoryPolicy p2 ) {
416
+ private static boolean policyEquals (@ Nonnull RepositoryPolicy p1 , @ Nonnull RepositoryPolicy p2 ) {
390
417
if (p1 == p2 ) {
391
418
return true ;
392
419
}
393
420
// update policy doesn't affect contents
394
421
return p1 .isEnabled () == p2 .isEnabled () && Objects .equals (p1 .getChecksumPolicy (), p2 .getChecksumPolicy ());
395
422
}
396
423
397
- private static boolean repositoryEquals (RemoteRepository r1 , RemoteRepository r2 ) {
424
+ private static boolean repositoryEquals (@ Nonnull RemoteRepository r1 , @ Nonnull RemoteRepository r2 ) {
398
425
if (r1 == r2 ) {
399
426
return true ;
400
427
}
0 commit comments