Coverage Report - org.apache.maven.plugin.dependency.resolvers.ListRepositoriesMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
ListRepositoriesMojo
0%
0/13
0%
0/4
5
 
 1  
 package org.apache.maven.plugin.dependency.resolvers;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  * http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import org.apache.maven.artifact.Artifact;
 23  
 import org.apache.maven.artifact.repository.ArtifactRepository;
 24  
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 25  
 import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
 26  
 import org.apache.maven.artifact.resolver.ResolutionListener;
 27  
 import org.apache.maven.artifact.resolver.ResolutionNode;
 28  
 import org.apache.maven.plugin.MojoExecutionException;
 29  
 import org.apache.maven.plugin.dependency.AbstractDependencyMojo;
 30  
 import org.apache.maven.plugins.annotations.Mojo;
 31  
 import org.apache.maven.plugins.annotations.ResolutionScope;
 32  
 import org.apache.maven.shared.artifact.filter.ScopeArtifactFilter;
 33  
 
 34  
 import java.util.ArrayList;
 35  
 import java.util.HashSet;
 36  
 import java.util.Set;
 37  
 
 38  
 /**
 39  
  * Goal that resolves all project dependencies and then lists the repositories
 40  
  * used by the build and by the transitive dependencies
 41  
  *
 42  
  * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
 43  
  * @version $Id: GoOfflineMojo.java 728546 2008-12-21 22:56:51Z bentmann $
 44  
  * @since 2.2
 45  
  */
 46  
 @Mojo( name = "list-repositories", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true )
 47  0
 public class ListRepositoriesMojo
 48  
     extends AbstractDependencyMojo
 49  
 {
 50  
     /**
 51  
      * Displays a list of the repositories used by this build.
 52  
      *
 53  
      * @throws MojoExecutionException with a message if an error occurs.
 54  
      */
 55  
     public void execute()
 56  
         throws MojoExecutionException
 57  
     {
 58  
         try
 59  
         {
 60  0
             ArtifactResolutionResult result =
 61  
                 this.artifactCollector.collect( project.getArtifacts(), project.getArtifact(), this.getLocal(),
 62  
                                                 this.remoteRepos, this.artifactMetadataSource,
 63  
                                                 new ScopeArtifactFilter( Artifact.SCOPE_TEST ),
 64  
                                                 new ArrayList<ResolutionListener>() );
 65  0
             Set<ArtifactRepository> repos = new HashSet<ArtifactRepository>();
 66  0
             Set<ResolutionNode> nodes = result.getArtifactResolutionNodes();
 67  0
             for ( ResolutionNode node : nodes )
 68  
             {
 69  0
                 repos.addAll( node.getRemoteRepositories() );
 70  
             }
 71  
 
 72  0
             this.getLog().info( "Repositories Used by this build:" );
 73  0
             for ( ArtifactRepository repo : repos )
 74  
             {
 75  0
                 this.getLog().info( repo.toString() );
 76  
             }
 77  
         }
 78  0
         catch ( ArtifactResolutionException e )
 79  
         {
 80  0
             throw new MojoExecutionException( "Unable to resolve artifacts", e );
 81  0
         }
 82  0
     }
 83  
 }