Coverage Report - org.apache.maven.plugin.dependency.utils.resolvers.DefaultArtifactsResolver
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultArtifactsResolver
100%
21/21
66%
4/6
4.5
 
 1  
 package org.apache.maven.plugin.dependency.utils.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 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  
  * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
 36  
  * @version $Id: DefaultArtifactsResolver.java 1085777 2011-03-26 18:13:19Z hboutemy $
 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  
      * (non-Javadoc)
 60  
      * 
 61  
      * @see org.apache.mojo.dependency.utils.resolvers.ArtifactsResolver#resolve(java.util.Set,
 62  
      *      org.apache.maven.plugin.logging.Log)
 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  
                 // an error occurred during resolution, log it an continue
 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  
                 // not found, log it and continue
 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  
 }