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 | 8 | { |
52 | 8 | this.resolver = theResolver; |
53 | 8 | this.local = theLocal; |
54 | 8 | this.remoteRepositories = theRemoteRepositories; |
55 | 8 | this.stopOnFailure = theStopOnFailure; |
56 | 8 | } |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
public Set<Artifact> resolve( Set<Artifact> artifacts, Log log ) |
65 | |
throws MojoExecutionException |
66 | |
{ |
67 | |
|
68 | 8 | Set<Artifact> resolvedArtifacts = new HashSet<Artifact>(); |
69 | 8 | for ( Artifact artifact : artifacts ) |
70 | |
{ |
71 | |
try |
72 | |
{ |
73 | 32 | resolver.resolve( artifact, remoteRepositories, local ); |
74 | 28 | resolvedArtifacts.add( artifact ); |
75 | |
} |
76 | 2 | catch ( ArtifactResolutionException ex ) |
77 | |
{ |
78 | |
|
79 | 2 | log.debug( "error resolving: " + artifact.getId() ); |
80 | 2 | log.debug( ex ); |
81 | 2 | if ( stopOnFailure ) |
82 | |
{ |
83 | 2 | throw new MojoExecutionException( "error resolving: " + artifact.getId(), ex ); |
84 | |
} |
85 | |
} |
86 | 2 | catch ( ArtifactNotFoundException ex ) |
87 | |
{ |
88 | |
|
89 | 2 | log.debug( "not found in any repository: " + artifact.getId() ); |
90 | 2 | if ( stopOnFailure ) |
91 | |
{ |
92 | 2 | throw new MojoExecutionException( "not found in any repository: " + artifact.getId(), ex ); |
93 | |
} |
94 | 56 | } |
95 | |
} |
96 | 4 | return resolvedArtifacts; |
97 | |
} |
98 | |
|
99 | |
} |