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