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
23
24
25
26
27 import java.util.HashSet;
28 import java.util.Iterator;
29 import java.util.List;
30 import java.util.Set;
31
32 import org.apache.maven.artifact.Artifact;
33 import org.apache.maven.artifact.repository.ArtifactRepository;
34 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
35 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
36 import org.apache.maven.artifact.resolver.ArtifactResolver;
37 import org.apache.maven.plugin.MojoExecutionException;
38 import org.apache.maven.plugin.logging.Log;
39
40
41
42
43
44 public class DefaultArtifactsResolver
45 implements ArtifactsResolver
46 {
47 ArtifactResolver resolver;
48
49 ArtifactRepository local;
50
51 List remoteRepositories;
52
53 boolean stopOnFailure;
54
55 public DefaultArtifactsResolver( ArtifactResolver theResolver, ArtifactRepository theLocal,
56 List theRemoteRepositories, boolean theStopOnFailure )
57 {
58 this.resolver = theResolver;
59 this.local = theLocal;
60 this.remoteRepositories = theRemoteRepositories;
61 this.stopOnFailure = theStopOnFailure;
62 }
63
64
65
66
67
68
69
70 public Set resolve( Set artifacts, Log log )
71 throws MojoExecutionException
72 {
73
74 Set resolvedArtifacts = new HashSet();
75 Iterator iter = artifacts.iterator();
76 while ( iter.hasNext() )
77 {
78 Artifact artifact = (Artifact) iter.next();
79 try
80 {
81 resolver.resolve( artifact, remoteRepositories, local );
82 resolvedArtifacts.add( artifact );
83 }
84 catch ( ArtifactResolutionException ex )
85 {
86
87 log.debug( "error resolving: " + artifact.getId() );
88 log.debug( ex );
89 if ( stopOnFailure )
90 {
91 throw new MojoExecutionException( "error resolving: " + artifact.getId(), ex );
92 }
93 }
94 catch ( ArtifactNotFoundException ex )
95 {
96
97 log.debug( "not found in any repository: " + artifact.getId() );
98 if ( stopOnFailure )
99 {
100 throw new MojoExecutionException( "not found in any repository: " + artifact.getId(), ex );
101 }
102 }
103 }
104 return resolvedArtifacts;
105 }
106
107 }