1 package org.apache.maven.plugin.dependency.resolvers;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.artifact.Artifact;
23 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
24 import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
25 import org.apache.maven.artifact.resolver.ResolutionNode;
26 import org.apache.maven.plugin.MojoExecutionException;
27 import org.apache.maven.plugin.dependency.AbstractDependencyMojo;
28 import org.apache.maven.plugins.annotations.Mojo;
29 import org.apache.maven.plugins.annotations.ResolutionScope;
30 import org.apache.maven.shared.artifact.filter.ScopeArtifactFilter;
31
32 import java.util.ArrayList;
33 import java.util.HashSet;
34 import java.util.Iterator;
35 import java.util.Set;
36
37
38
39
40
41
42
43
44
45 @Mojo( name = "list-repositories", requiresDependencyResolution = ResolutionScope.TEST )
46 public class ListRepositoriesMojo
47 extends AbstractDependencyMojo
48 {
49
50
51
52
53
54 public void execute()
55 throws MojoExecutionException
56 {
57 try
58 {
59 ArtifactResolutionResult result =
60 this.artifactCollector.collect( project.getArtifacts(), project.getArtifact(), this.getLocal(),
61 this.remoteRepos, this.artifactMetadataSource,
62 new ScopeArtifactFilter( Artifact.SCOPE_TEST ), new ArrayList() );
63 Set repos = new HashSet();
64 Set<ResolutionNode> nodes = result.getArtifactResolutionNodes();
65 for ( ResolutionNode node : nodes )
66 {
67 repos.addAll( node.getRemoteRepositories() );
68 }
69
70 this.getLog().info( "Repositories Used by this build:" );
71 for ( Iterator i = repos.iterator(); i.hasNext(); )
72 {
73 this.getLog().info( i.next().toString() );
74 }
75 }
76 catch ( ArtifactResolutionException e )
77 {
78 throw new MojoExecutionException( "Unable to resolve artifacts", e );
79 }
80 }
81 }