2929import java .util .Optional ;
3030import java .util .stream .Collectors ;
3131
32+ import org .apache .maven .api .annotations .Nonnull ;
33+ import org .apache .maven .api .annotations .Nullable ;
3234import org .apache .maven .artifact .handler .ArtifactHandler ;
3335import org .apache .maven .artifact .handler .DefaultArtifactHandler ;
3436import org .apache .maven .artifact .handler .manager .ArtifactHandlerManager ;
6567 */
6668public class RepositoryUtils {
6769
68- private static String nullify (String string ) {
70+ @ Nullable
71+ private static String nullify (@ Nullable String string ) {
6972 return (string == null || string .isEmpty ()) ? null : string ;
7073 }
7174
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 ) {
7377 if (dependency == null ) {
7478 return null ;
7579 }
@@ -81,7 +85,8 @@ public static org.apache.maven.artifact.Artifact toArtifact(Dependency dependenc
8185 return result ;
8286 }
8387
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 ) {
8590 if (artifact == null ) {
8691 return null ;
8792 }
@@ -112,10 +117,10 @@ public static org.apache.maven.artifact.Artifact toArtifact(Artifact artifact) {
112117 }
113118
114119 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 ) {
119124 for (DependencyNode node : nodes ) {
120125 org .apache .maven .artifact .Artifact artifact = toArtifact (node .getDependency ());
121126
@@ -132,7 +137,8 @@ public static void toArtifacts(
132137 }
133138 }
134139
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 ) {
136142 if (artifact == null ) {
137143 return null ;
138144 }
@@ -162,7 +168,8 @@ public static Artifact toArtifact(org.apache.maven.artifact.Artifact artifact) {
162168 }
163169
164170 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 ) {
166173 if (artifact == null ) {
167174 return null ;
168175 }
@@ -175,13 +182,15 @@ public static Dependency toDependency(
175182 return new Dependency (result , artifact .getScope (), artifact .isOptional (), excl );
176183 }
177184
178- public static List <RemoteRepository > toRepos (List <ArtifactRepository > repos ) {
185+ @ Nonnull
186+ public static List <RemoteRepository > toRepos (@ Nullable List <ArtifactRepository > repos ) {
179187 return Optional .ofNullable (repos ).orElse (Collections .emptyList ()).stream ()
180188 .map (RepositoryUtils ::toRepo )
181189 .collect (Collectors .toList ());
182190 }
183191
184- public static RemoteRepository toRepo (ArtifactRepository repo ) {
192+ @ Nullable
193+ public static RemoteRepository toRepo (@ Nullable ArtifactRepository repo ) {
185194 RemoteRepository result = null ;
186195 if (repo != null ) {
187196 RemoteRepository .Builder builder =
@@ -197,7 +206,8 @@ public static RemoteRepository toRepo(ArtifactRepository repo) {
197206 return result ;
198207 }
199208
200- public static String getLayout (ArtifactRepository repo ) {
209+ @ Nonnull
210+ public static String getLayout (@ Nonnull ArtifactRepository repo ) {
201211 try {
202212 return repo .getLayout ().getId ();
203213 } catch (LinkageError e ) {
@@ -216,15 +226,17 @@ public static String getLayout(ArtifactRepository repo) {
216226 }
217227 }
218228
219- private static RepositoryPolicy toPolicy (ArtifactRepositoryPolicy policy ) {
229+ @ Nullable
230+ private static RepositoryPolicy toPolicy (@ Nullable ArtifactRepositoryPolicy policy ) {
220231 RepositoryPolicy result = null ;
221232 if (policy != null ) {
222233 result = new RepositoryPolicy (policy .isEnabled (), policy .getUpdatePolicy (), policy .getChecksumPolicy ());
223234 }
224235 return result ;
225236 }
226237
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 ) {
228240 Authentication result = null ;
229241 if (auth != null ) {
230242 AuthenticationBuilder authBuilder = new AuthenticationBuilder ();
@@ -235,7 +247,8 @@ private static Authentication toAuthentication(org.apache.maven.artifact.reposit
235247 return result ;
236248 }
237249
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 ) {
239252 Proxy result = null ;
240253 if (proxy != null ) {
241254 AuthenticationBuilder authBuilder = new AuthenticationBuilder ();
@@ -245,7 +258,8 @@ private static Proxy toProxy(org.apache.maven.repository.Proxy proxy) {
245258 return result ;
246259 }
247260
248- public static ArtifactHandler newHandler (Artifact artifact ) {
261+ @ Nonnull
262+ public static ArtifactHandler newHandler (@ Nonnull Artifact artifact ) {
249263 String type = artifact .getProperty (ArtifactProperties .TYPE , artifact .getExtension ());
250264 return new DefaultArtifactHandler (
251265 type ,
@@ -258,7 +272,8 @@ public static ArtifactHandler newHandler(Artifact artifact) {
258272 Boolean .parseBoolean (artifact .getProperty (MavenArtifactProperties .CONSTITUTES_BUILD_PATH , "" )));
259273 }
260274
261- public static ArtifactType newArtifactType (String id , ArtifactHandler handler ) {
275+ @ Nonnull
276+ public static ArtifactType newArtifactType (@ Nonnull String id , @ Nonnull ArtifactHandler handler ) {
262277 return new DefaultArtifactType (
263278 id ,
264279 handler .getExtension (),
@@ -268,8 +283,9 @@ public static ArtifactType newArtifactType(String id, ArtifactHandler handler) {
268283 handler .isIncludesDependencies ());
269284 }
270285
286+ @ Nonnull
271287 public static Dependency toDependency (
272- org .apache .maven .model .Dependency dependency , ArtifactTypeRegistry stereotypes ) {
288+ @ Nonnull org .apache .maven .model .Dependency dependency , @ Nonnull ArtifactTypeRegistry stereotypes ) {
273289 ArtifactType stereotype = stereotypes .get (dependency .getType ());
274290 if (stereotype == null ) {
275291 stereotype = new DefaultArtifactType (dependency .getType ());
@@ -303,38 +319,46 @@ public static Dependency toDependency(
303319 exclusions );
304320 }
305321
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 ) {
307324 return new Exclusion (exclusion .getGroupId (), exclusion .getArtifactId (), "*" , "*" );
308325 }
309326
310- public static ArtifactTypeRegistry newArtifactTypeRegistry (ArtifactHandlerManager handlerManager ) {
327+ @ Nonnull
328+ public static ArtifactTypeRegistry newArtifactTypeRegistry (@ Nonnull ArtifactHandlerManager handlerManager ) {
311329 return new MavenArtifactTypeRegistry (handlerManager );
312330 }
313331
314332 static class MavenArtifactTypeRegistry implements ArtifactTypeRegistry {
315333
334+ @ Nonnull
316335 private final ArtifactHandlerManager handlerManager ;
317336
318- MavenArtifactTypeRegistry (ArtifactHandlerManager handlerManager ) {
337+ MavenArtifactTypeRegistry (@ Nonnull ArtifactHandlerManager handlerManager ) {
319338 this .handlerManager = handlerManager ;
320339 }
321340
322- public ArtifactType get (String stereotypeId ) {
341+ @ Nullable
342+ @ Override
343+ public ArtifactType get (@ Nonnull String stereotypeId ) {
323344 ArtifactHandler handler = handlerManager .getArtifactHandler (stereotypeId );
324345 return newArtifactType (stereotypeId , handler );
325346 }
326347 }
327348
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 ) {
329352 return artifactsToConvert .stream ().map (RepositoryUtils ::toArtifact ).collect (Collectors .toList ());
330353 }
331354
332- public static WorkspaceRepository getWorkspace (RepositorySystemSession session ) {
355+ @ Nullable
356+ public static WorkspaceRepository getWorkspace (@ Nonnull RepositorySystemSession session ) {
333357 WorkspaceReader reader = session .getWorkspaceReader ();
334358 return (reader != null ) ? reader .getRepository () : null ;
335359 }
336360
337- public static boolean repositoriesEquals (List <RemoteRepository > r1 , List <RemoteRepository > r2 ) {
361+ public static boolean repositoriesEquals (@ Nonnull List <RemoteRepository > r1 , @ Nonnull List <RemoteRepository > r2 ) {
338362 if (r1 .size () != r2 .size ()) {
339363 return false ;
340364 }
@@ -348,16 +372,19 @@ public static boolean repositoriesEquals(List<RemoteRepository> r1, List<RemoteR
348372 return true ;
349373 }
350374
351- public static int repositoriesHashCode (List <RemoteRepository > repositories ) {
375+ public static int repositoriesHashCode (@ Nonnull List <RemoteRepository > repositories ) {
352376 int result = 17 ;
353377 for (RemoteRepository repository : repositories ) {
354378 result = 31 * result + repositoryHashCode (repository );
355379 }
356380 return result ;
357381 }
358382
383+ @ Nullable
359384 public static RepositorySystemSession overlay (
360- ArtifactRepository repository , RepositorySystemSession session , RepositorySystem system ) {
385+ @ Nullable ArtifactRepository repository ,
386+ @ Nullable RepositorySystemSession session ,
387+ @ Nonnull RepositorySystem system ) {
361388 if (repository == null || repository .getBasedir () == null ) {
362389 return session ;
363390 }
@@ -379,22 +406,22 @@ public static RepositorySystemSession overlay(
379406 return newSession ;
380407 }
381408
382- private static int repositoryHashCode (RemoteRepository repository ) {
409+ private static int repositoryHashCode (@ Nonnull RemoteRepository repository ) {
383410 int result = 17 ;
384411 Object obj = repository .getUrl ();
385412 result = 31 * result + (obj != null ? obj .hashCode () : 0 );
386413 return result ;
387414 }
388415
389- private static boolean policyEquals (RepositoryPolicy p1 , RepositoryPolicy p2 ) {
416+ private static boolean policyEquals (@ Nonnull RepositoryPolicy p1 , @ Nonnull RepositoryPolicy p2 ) {
390417 if (p1 == p2 ) {
391418 return true ;
392419 }
393420 // update policy doesn't affect contents
394421 return p1 .isEnabled () == p2 .isEnabled () && Objects .equals (p1 .getChecksumPolicy (), p2 .getChecksumPolicy ());
395422 }
396423
397- private static boolean repositoryEquals (RemoteRepository r1 , RemoteRepository r2 ) {
424+ private static boolean repositoryEquals (@ Nonnull RemoteRepository r1 , @ Nonnull RemoteRepository r2 ) {
398425 if (r1 == r2 ) {
399426 return true ;
400427 }
0 commit comments