1 package org.apache.maven.plugin.dependency.utils.resolvers;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.HashSet;
23 import java.util.List;
24 import java.util.Set;
25
26 import org.apache.maven.artifact.Artifact;
27 import org.apache.maven.artifact.repository.ArtifactRepository;
28 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
29 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
30 import org.apache.maven.artifact.resolver.ArtifactResolver;
31 import org.apache.maven.plugin.MojoExecutionException;
32 import org.apache.maven.plugin.logging.Log;
33
34
35
36
37
38 public class DefaultArtifactsResolver
39 implements ArtifactsResolver
40 {
41 ArtifactResolver resolver;
42
43 ArtifactRepository local;
44
45 List<ArtifactRepository> remoteRepositories;
46
47 boolean stopOnFailure;
48
49 public DefaultArtifactsResolver( ArtifactResolver theResolver, ArtifactRepository theLocal,
50 List<ArtifactRepository> theRemoteRepositories, boolean theStopOnFailure )
51 {
52 this.resolver = theResolver;
53 this.local = theLocal;
54 this.remoteRepositories = theRemoteRepositories;
55 this.stopOnFailure = theStopOnFailure;
56 }
57
58
59
60
61
62
63
64 public Set<Artifact> resolve( Set<Artifact> artifacts, Log log )
65 throws MojoExecutionException
66 {
67
68 Set<Artifact> resolvedArtifacts = new HashSet<Artifact>();
69 for ( Artifact artifact : artifacts )
70 {
71 try
72 {
73 resolver.resolve( artifact, remoteRepositories, local );
74 resolvedArtifacts.add( artifact );
75 }
76 catch ( ArtifactResolutionException ex )
77 {
78
79 log.debug( "error resolving: " + artifact.getId() );
80 log.debug( ex );
81 if ( stopOnFailure )
82 {
83 throw new MojoExecutionException( "error resolving: " + artifact.getId(), ex );
84 }
85 }
86 catch ( ArtifactNotFoundException ex )
87 {
88
89 log.debug( "not found in any repository: " + artifact.getId() );
90 if ( stopOnFailure )
91 {
92 throw new MojoExecutionException( "not found in any repository: " + artifact.getId(), ex );
93 }
94 }
95 }
96 return resolvedArtifacts;
97 }
98
99 }