1 package org.apache.maven.artifact.resolver;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.List;
25
26 import org.codehaus.plexus.component.annotations.Component;
27
28
29
30
31 @Component( role = ResolutionErrorHandler.class )
32 public class DefaultResolutionErrorHandler
33 implements ResolutionErrorHandler
34 {
35
36 public void throwErrors( ArtifactResolutionRequest request, ArtifactResolutionResult result )
37 throws ArtifactResolutionException
38 {
39
40
41 if ( result.hasMetadataResolutionExceptions() )
42 {
43 throw result.getMetadataResolutionException( 0 );
44 }
45
46
47
48
49
50 if ( result.hasCircularDependencyExceptions() )
51 {
52 throw result.getCircularDependencyException( 0 );
53 }
54
55
56
57 if ( result.hasVersionRangeViolations() )
58 {
59 throw result.getVersionRangeViolation( 0 );
60 }
61
62
63
64 if ( result.hasErrorArtifactExceptions() )
65 {
66 throw result.getErrorArtifactExceptions().get( 0 );
67 }
68
69 if ( result.hasMissingArtifacts() )
70 {
71 throw new MultipleArtifactsNotFoundException( request.getArtifact(), toList( result.getArtifacts() ),
72 result.getMissingArtifacts(),
73 request.getRemoteRepositories() );
74 }
75
76
77 if ( result.hasExceptions() )
78 {
79 throw new ArtifactResolutionException( "Unknown error during artifact resolution, " + request + ", "
80 + result.getExceptions(), request.getArtifact(), request.getRemoteRepositories() );
81 }
82 }
83
84 private static <T> List<T> toList( Collection<T> items )
85 {
86 return ( items != null ) ? new ArrayList<T>( items ) : null;
87 }
88
89 }